Fix map editor not removing an actor properly.

If you edit an actor name, then delete the actor - it fails to be removed from the map in the editor. This is because the actor previews are keyed by ID. Editing their name edits their ID and breaks the stability of their hash code. This unstable hash code means the preview will now fail to be removed from collections, even though it's the "same" object.

Fix this by making the ID immutable to ensure hash stability - this means that a preview can be added and removed from collections successfully. Now when we edit the ID in the UI, we can't update the ID in place on the preview. Instead we must generate a new preview with the correct ID and swap it with the preview currently in use.
This commit is contained in:
RoosterDragon
2024-03-14 18:58:21 +00:00
committed by Gustas
parent 25a6b4b6b9
commit 799c4c9e3c
3 changed files with 63 additions and 29 deletions

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Traits
public string Type => reference.Type;
public string ID { get; set; }
public string ID { get; }
public PlayerReference Owner { get; set; }
public WPos CenterPosition { get; set; }
public IReadOnlyDictionary<CPos, SubCell> Footprint { get; private set; }
@@ -83,6 +83,11 @@ namespace OpenRA.Mods.Common.Traits
onCellEntryChanged = _ => UpdateFromCellChange();
}
public EditorActorPreview WithId(string id)
{
return new EditorActorPreview(worldRenderer, id, reference.Clone(), Owner);
}
void UpdateFromCellChange()
{
CenterPosition = PreviewPosition(worldRenderer.World, reference);