diff --git a/src/HexManiac.Core/ViewModels/Map/BlockMapViewModel.cs b/src/HexManiac.Core/ViewModels/Map/BlockMapViewModel.cs index d71658f7..73527067 100644 --- a/src/HexManiac.Core/ViewModels/Map/BlockMapViewModel.cs +++ b/src/HexManiac.Core/ViewModels/Map/BlockMapViewModel.cs @@ -1262,7 +1262,9 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Map { // if there were no empty entries in the table, add a new one if (emptySpawn == -1) { - var newSpawns = spawns.Run.Append(tokenFactory(), 1); + var newSpawns = model.RelocateForExpansion(tokenFactory(), spawns.Run, spawns.Run.Length + spawns.Run.ElementLength); + newSpawns = newSpawns.Append(tokenFactory(), 1); + model.ObserveRunWritten(tokenFactory(), newSpawns); if (newSpawns.Start != spawns.Run.Start) InformRepoint(new("Fly Spawns", newSpawns.Start)); spawns = new ModelTable(model, newSpawns, tokenFactory); emptySpawn = spawns.Count - 1; diff --git a/src/HexManiac.Core/ViewModels/Map/MapEditorViewModel.cs b/src/HexManiac.Core/ViewModels/Map/MapEditorViewModel.cs index c3d11c02..deb33d2d 100644 --- a/src/HexManiac.Core/ViewModels/Map/MapEditorViewModel.cs +++ b/src/HexManiac.Core/ViewModels/Map/MapEditorViewModel.cs @@ -188,7 +188,7 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Map { public ICommand Diff => null; public ICommand DiffLeft => null; public ICommand DiffRight => null; - public bool CanDuplicate => false; + public bool CanDuplicate => true; public event EventHandler OnError; public event EventHandler OnMessage; @@ -202,7 +202,13 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Map { public event EventHandler RequestCanCreatePatch; public event EventHandler RequestCreatePatch; - public void Duplicate() { } + public void Duplicate() => Duplicate(PrimaryMap.MapID / 1000, PrimaryMap.MapID % 1000); + private void Duplicate(int bank, int map) { + var newEditor = new MapEditorViewModel(FileSystem, viewPort, singletons, Tutorials); + newEditor.UpdatePrimaryMap(new BlockMapViewModel(FileSystem, Tutorials, viewPort, Format, bank, map)); + RequestTabChange?.Invoke(this, new(newEditor)); + } + public void Refresh() { VisibleMaps.Clear(); primaryMap.ClearCaches(); @@ -767,6 +773,7 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Map { ContextItems.Add(new MenuCommand("Delete Object", DeleteCurrentEvent)); } else if (ev is WarpEventViewModel warp) { ContextItems.Add(new MenuCommand("Create New Map", CreateMapForWarp)); + ContextItems.Add(new MenuCommand("Open in New Tab", () => Duplicate(warp.Bank, warp.Map))); ContextItems.Add(new MenuCommand("Delete Warp", DeleteCurrentEvent)); } else if (ev is ScriptEventViewModel script) { ContextItems.Add(new MenuCommand("Delete Script", DeleteCurrentEvent));