Add editor image badges and drag moves

This commit is contained in:
2026-05-11 23:03:29 +02:00
parent 884cc4503f
commit dfe0cb3b6a
7 changed files with 538 additions and 46 deletions

View File

@@ -13,6 +13,35 @@ public sealed class LevelEditorTests
Assert.Equal(EDoorState.Closed, next.GetProp(new(2, 2)).DoorState);
}
[Fact]
public void DoorToolTogglesExistingDoorState()
{
var level = LevelState.Create("Door editor", 6, 6);
level = LevelEditor.Apply(level, new(2, 2), new() { Tool = EEditorTool.Door });
var opened = LevelEditor.Apply(level, new(2, 2), new() { Tool = EEditorTool.Door });
var closed = LevelEditor.Apply(opened, new(2, 2), new() { Tool = EEditorTool.Door });
Assert.Equal(EDoorState.Open, opened.GetProp(new(2, 2)).DoorState);
Assert.Equal(EDoorState.Closed, closed.GetProp(new(2, 2)).DoorState);
}
[Fact]
public void WallToolPreservesUndergroundNetworks()
{
var level = LevelState.Create("Wall editor", 6, 6);
var position = new GridPosition(2, 2);
level = LevelEditor.Apply(level, position, new() { Tool = EEditorTool.Underground, Carrier = ECarrierType.Fuel });
level = LevelEditor.Apply(level, position, new() { Tool = EEditorTool.Underground, Carrier = ECarrierType.Coolant });
level = LevelEditor.Apply(level, position, new() { Tool = EEditorTool.Underground, Carrier = ECarrierType.Electricity });
var next = LevelEditor.Apply(level, position, new() { Tool = EEditorTool.Wall });
Assert.Equal(EUndergroundState.Intact, next.GetUnderground(position, ECarrierType.Fuel).State);
Assert.Equal(EUndergroundState.Intact, next.GetUnderground(position, ECarrierType.Coolant).State);
Assert.Equal(EUndergroundState.Intact, next.GetUnderground(position, ECarrierType.Electricity).State);
}
[Fact]
public void ConsumerToolPlacesCarrierAgnosticConsumer()
{
@@ -92,4 +121,66 @@ public sealed class LevelEditorTests
Assert.Equal(EPropType.ReactorControl, next.GetProp(new(3, 3)).Type);
Assert.Equal(new(3, 3), next.Reactors[0].ControlPosition);
}
[Fact]
public void MoveOccupantMovesSourcesAsProps()
{
var level = LevelState.Create("Move editor", 6, 6);
level = LevelEditor.Apply(level, new(1, 1), new() { Tool = EEditorTool.Flow, Carrier = ECarrierType.Fuel });
var result = LevelEditor.TryMoveOccupant(level, new(1, 1), new(3, 3));
Assert.True(result.Success, result.Reason);
Assert.Equal(EPropType.None, result.Level.GetProp(new(1, 1)).Type);
Assert.Equal(EPropType.Flow, result.Level.GetProp(new(3, 3)).Type);
Assert.Equal(ECarrierType.Fuel, result.Level.GetProp(new(3, 3)).Carrier);
}
[Fact]
public void MoveOccupantMovesFuelLeakToFloorDestination()
{
var level = LevelState.Create("Move editor", 6, 6);
level = LevelEditor.SetLeak(level, new(1, 1), new(1, 1), ECarrierType.Fuel);
var result = LevelEditor.TryMoveOccupant(level, new(1, 1), new(3, 3));
Assert.True(result.Success, result.Reason);
Assert.Single(result.Level.Leaks);
Assert.Equal(new(3, 3), result.Level.Leaks[0].UndergroundPosition);
Assert.Equal(new(3, 3), result.Level.Leaks[0].AccessPosition);
Assert.Equal(EUndergroundState.Leaking, result.Level.GetUnderground(new(3, 3), ECarrierType.Fuel).State);
Assert.Equal(EUndergroundState.Absent, result.Level.GetUnderground(new(1, 1), ECarrierType.Fuel).State);
}
[Fact]
public void MoveOccupantMovesElectricityLeakAccessFace()
{
var level = LevelState.Create("Move editor", 6, 6);
level = level.SetTerrain(new(2, 2), ECellTerrain.Wall);
level = LevelEditor.SetLeak(level, new(2, 2), new(2, 3), ECarrierType.Electricity);
var result = LevelEditor.TryMoveOccupant(level, new(2, 3), new(3, 2));
Assert.True(result.Success, result.Reason);
Assert.Single(result.Level.Leaks);
Assert.Equal(new(2, 2), result.Level.Leaks[0].UndergroundPosition);
Assert.Equal(new(3, 2), result.Level.Leaks[0].AccessPosition);
}
[Fact]
public void MoveOccupantReportsInvalidStartAndDestinationReasons()
{
var level = LevelState.Create("Move editor", 6, 6);
level = level.SetTerrain(new(3, 3), ECellTerrain.Wall);
level = level.SetProp(new(1, 1), new() { Type = EPropType.Consumer });
level = level.SetProp(new(2, 2), new() { Type = EPropType.Consumer });
var invalidStart = LevelEditor.TryMoveOccupant(level, new(4, 4), new(5, 5));
var invalidDestination = LevelEditor.TryMoveOccupant(level, new(1, 1), new(2, 2));
Assert.False(invalidStart.Success);
Assert.Contains("No movable", invalidStart.Reason);
Assert.False(invalidDestination.Success);
Assert.Contains("occupied", invalidDestination.Reason);
}
}