Skip to content

Commit

Permalink
Proper cleanup of lookup table when removing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
kaczy93 committed Oct 9, 2024
1 parent cdf097f commit ebb4efa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CentrED/Tools/LandBrushTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public LandBrushTool()
internal override void Draw()
{
base.Draw();
if (!ProfileManager.ActiveProfile.LandBrush.ContainsKey(_activeLandBrushName))
{
_activeLandBrushName = ProfileManager.ActiveProfile.LandBrush.Keys.FirstOrDefault("");
}

_manager.LandBrushCombo(ref _activeLandBrushName);
ImGui.Checkbox("Fixed Z", ref _fixedZ);
Expand Down
26 changes: 23 additions & 3 deletions CentrED/UI/Windows/LandBrushManagerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,26 @@ private void DrawBrushPopups()
ImGui.Text($"LandBrush: '{Selected.Name}'");
if (ImGui.Button("Yes", new Vector2(100, 0)))
{
foreach (var landBrushesValue in _landBrushes.Values)
//Remove all entries that have removed brush as to-transition
foreach (var landBrush in _landBrushes.Values)
{
landBrushesValue.Transitions.Remove(Selected.Name);
if(landBrush.Transitions.Remove(Selected.Name, out var removed))
{
foreach (var transition in removed)
{
RemoveLandBrushEntry(transition.TileID, landBrush.Name, _selectedLandBrushName);
}
}
}
//Remove all entries that have removed brush as from-transition
foreach (var (name, transitions) in Selected.Transitions)
{
foreach (var transition in transitions)
{
RemoveLandBrushEntry(transition.TileID, _selectedLandBrushName, name);
}
}
Selected.Tiles.ForEach(t => RemoveLandBrushEntry(t, _selectedLandBrushName, _selectedLandBrushName));
_landBrushes.Remove(Selected.Name);
_selectedLandBrushName = _landBrushes.Keys.FirstOrDefault("");
_selectedTransitionBrushName = Selected?.Transitions.Keys.FirstOrDefault("") ?? "";
Expand Down Expand Up @@ -439,7 +455,11 @@ private void DrawTransitionPopups()
ImGui.Text($"Transition: '{_selectedTransitionBrushName}'");
if (ImGui.Button("Yes", new Vector2(100, 0)))
{
Selected!.Transitions.Remove(_selectedTransitionBrushName);
//Remove all entries that have removed brush as to-transition
if (Selected!.Transitions.Remove(_selectedTransitionBrushName, out var removed))
{
removed.ForEach(t => RemoveLandBrushEntry(t.TileID, Selected.Name, _selectedTransitionBrushName));
}
if(Selected.Transitions.Count > 0)
_selectedTransitionBrushName = Selected.Transitions.Keys.FirstOrDefault("");
else
Expand Down

0 comments on commit ebb4efa

Please sign in to comment.