fix metadata issues

This commit is contained in:
haven1433
2022-10-28 21:52:43 -05:00
parent 130e9f1eb8
commit 196d46ea5c
2 changed files with 15 additions and 15 deletions

View File

@@ -1042,18 +1042,17 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Map {
private BlockMapViewModel CreateNewMap(ModelDelta token, int bank, int width, int height) {
var mapTable = MapRepointer.AddNewMapToBank(bank);
var address = MapRepointer.CreateNewMap(token);
var layoutStart = MapRepointer.CreateNewLayout(token);
var newMap = MapRepointer.CreateNewMap(token);
var layout = MapRepointer.CreateNewLayout(token);
// update width / height
model.WriteValue(token, layoutStart + 0, width);
model.WriteValue(token, layoutStart + 4, height);
model.WriteValue(token, layout.Element.Start + 0, width);
model.WriteValue(token, layout.Element.Start + 4, height);
// update blockmap (layoutStart + 12)
WritePointerAndSource(token, layoutStart + 12, MapRepointer.CreateNewBlockMap(token, width, height));
layout.Element.SetAddress(Format.BlockMap, MapRepointer.CreateNewBlockMap(token, width, height));
WritePointerAndSource(token, address + 0, layoutStart);
model.UpdateArrayPointer(token, null, null, -1, mapTable.Start + mapTable.Length - 4, address);
newMap.Element.SetAddress(Format.Layout, layout.Element.Start);
model.UpdateArrayPointer(token, null, null, -1, mapTable.Start + mapTable.Length - 4, newMap.Element.Start);
var otherMap = new BlockMapViewModel(fileSystem, viewPort, format, bank, mapTable.ElementCount - 1) { allOverworldSprites = allOverworldSprites };
otherMap.UpdateLayoutID();

View File

@@ -201,8 +201,8 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Map {
var option = GetMapBankForNewMap("Duplicate map into which bank?");
if (option == -1) return;
var table = AddNewMapToBank(option);
var newMapStart = CreateNewMap(history.CurrentChange);
model.UpdateArrayPointer(history.CurrentChange, null, null, -1, table.Start + table.Length - 4, newMapStart);
var newMap = CreateNewMap(history.CurrentChange);
model.UpdateArrayPointer(history.CurrentChange, null, null, -1, table.Start + table.Length - 4, newMap.Element.Start);
ChangeMap.Raise(this, new(option, table.ElementCount - 1));
repointLayout.RaiseCanExecuteChanged();
}
@@ -551,7 +551,7 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Map {
/// Creates event data with 0 events, map scripts data with 0 scripts, and connection data with 0 connections.
/// Copies all the flags/header from the current map.
/// </summary>
public int CreateNewMap(ModelDelta token) {
public MapModel CreateNewMap(ModelDelta token) {
var currentMap = GetMapModel();
var mapStart = model.FindFreeSpace(model.FreeSpaceStart, 28);
// music: layoutID: regionSectionID. cave. weather. mapType. allowBiking. flags. floorNum. battleType.
@@ -565,14 +565,14 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Map {
var table = new TableStreamRun(model, mapStart, SortedSpan<int>.None, format.MapFormat, null, new FixedLengthStreamStrategy(1));
model.ObserveRunWritten(token, table);
return mapStart;
return new MapModel(new ModelArrayElement(model, mapStart, 0, () => token, table));
}
/// <summary>
/// Creates a new layout using the existing layout's borderblock, blockmap, primary blockset, and secondary blockset.
/// Once this new layout is assigned to a map, you'll want to update that map's layout ID by calling BlockMapViewModel.UpdateLayoutID()
/// </summary>
public int CreateNewLayout(ModelDelta token) {
public LayoutModel CreateNewLayout(ModelDelta token) {
var layoutStart = model.FindFreeSpace(model.FreeSpaceStart, 28);
var myLayout = GetLayout();
@@ -587,8 +587,9 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Map {
model.WriteValue(token, layoutStart + 25, myLayout.GetValue(Format.BorderHeight));
model.WriteMultiByteValue(layoutStart + 26, 2, token, 0);
}
if (ArrayRun.TryParse(model, format.LayoutFormat, layoutStart, SortedSpan<int>.None, out var run) == ErrorInfo.NoError) model.ObserveRunWritten(token, run);
return layoutStart;
if (ArrayRun.TryParse(model, format.LayoutFormat, layoutStart, SortedSpan<int>.None, out var table) != ErrorInfo.NoError) throw new NotImplementedException();
model.ObserveRunWritten(token, table);
return new(new(model, table.Start, 0, () => token, table));
}
public int CreateNewBlockMap(ModelDelta token, int width, int height) {