From 130e9f1eb8a29f071e0ea8bcfe7a20fecfb9f63b Mon Sep 17 00:00:00 2001 From: haven1433 Date: Fri, 28 Oct 2022 17:29:34 -0500 Subject: [PATCH] add metadata during create operations for layout and blockmap --- src/HexManiac.Core/Models/Runs/Sprites/BlockmapRun.cs | 10 ++++++---- src/HexManiac.Core/ViewModels/Map/BlockMapViewModel.cs | 6 +----- src/HexManiac.Core/ViewModels/Map/MapRepointer.cs | 3 +++ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/HexManiac.Core/Models/Runs/Sprites/BlockmapRun.cs b/src/HexManiac.Core/Models/Runs/Sprites/BlockmapRun.cs index a7142107..b7c16c2e 100644 --- a/src/HexManiac.Core/Models/Runs/Sprites/BlockmapRun.cs +++ b/src/HexManiac.Core/Models/Runs/Sprites/BlockmapRun.cs @@ -40,10 +40,12 @@ namespace HexManiac.Core.Models.Runs.Sprites { public BlockmapRun(IDataModel model, int start, SortedSpan sources, int width = -1, int height = -1) : base(start, sources) { this.model = model; - var primarySource = sources[0]; - var layoutStart = primarySource - 12; - if (width == -1) width = model.ReadValue(layoutStart); - if (height == -1) height = model.ReadValue(layoutStart + 4); + if (sources != null && sources.Count > 0) { + var primarySource = sources[0]; + var layoutStart = primarySource - 12; + if (width == -1) width = model.ReadValue(layoutStart); + if (height == -1) height = model.ReadValue(layoutStart + 4); + } (BlockWidth, BlockHeight) = (width, height); var code = model.GetGameCode(); diff --git a/src/HexManiac.Core/ViewModels/Map/BlockMapViewModel.cs b/src/HexManiac.Core/ViewModels/Map/BlockMapViewModel.cs index c314edcc..71d3cbe5 100644 --- a/src/HexManiac.Core/ViewModels/Map/BlockMapViewModel.cs +++ b/src/HexManiac.Core/ViewModels/Map/BlockMapViewModel.cs @@ -1049,16 +1049,12 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Map { model.WriteValue(token, layoutStart + 0, width); model.WriteValue(token, layoutStart + 4, height); - // TODO update border block (layoutStart + 8) - // update blockmap (layoutStart + 12) WritePointerAndSource(token, layoutStart + 12, MapRepointer.CreateNewBlockMap(token, width, height)); - // TODO update primary blockset (layoutStart + 16) - // TODO update primary blockset (layoutStart + 20) - WritePointerAndSource(token, address + 0, layoutStart); model.UpdateArrayPointer(token, null, null, -1, mapTable.Start + mapTable.Length - 4, address); + var otherMap = new BlockMapViewModel(fileSystem, viewPort, format, bank, mapTable.ElementCount - 1) { allOverworldSprites = allOverworldSprites }; otherMap.UpdateLayoutID(); return otherMap; diff --git a/src/HexManiac.Core/ViewModels/Map/MapRepointer.cs b/src/HexManiac.Core/ViewModels/Map/MapRepointer.cs index 4b664d6e..a485b9a0 100644 --- a/src/HexManiac.Core/ViewModels/Map/MapRepointer.cs +++ b/src/HexManiac.Core/ViewModels/Map/MapRepointer.cs @@ -587,6 +587,7 @@ 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.None, out var run) == ErrorInfo.NoError) model.ObserveRunWritten(token, run); return layoutStart; } @@ -594,6 +595,8 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Map { var blockmapLength = width * height * 2; var blockmapStart = model.FindFreeSpace(model.FreeSpaceStart, blockmapLength); token.ChangeData(model, blockmapStart, new byte[blockmapLength]); + var run = new BlockmapRun(model, blockmapStart, SortedSpan.None, width, height); + model.ObserveRunWritten(token, run); return blockmapStart; }