cleanup code

This commit is contained in:
2026-05-08 20:47:09 +02:00
parent 07d35a49a3
commit 2e813962c9
9 changed files with 387 additions and 355 deletions

View File

@@ -25,41 +25,98 @@ public static class LevelEditor
public static LevelState Apply(LevelState level, GridPosition position, EditorTool tool)
{
if (!level.InBounds(position))
{
return level;
}
if (tool == EditorTool.Robot)
{
return level.GetCell(position).IsWalkable ? level with { Robot = position } : level;
}
var cell = level.GetCell(position);
cell = tool switch
{
EditorTool.Floor => cell with { Kind = CellKind.Floor },
EditorTool.Wall => cell with { Kind = CellKind.Wall, Pipe = PipeMedium.None, Powered = false },
EditorTool.Wall => cell with
{
Kind = CellKind.Wall,
Pipe = PipeMedium.None,
Powered = false
},
EditorTool.Reactor => cell with { Kind = CellKind.Reactor },
EditorTool.CoolingPump => cell with { Kind = CellKind.CoolingPump, Powered = true },
EditorTool.Generator => cell with { Kind = CellKind.Generator, Powered = true },
EditorTool.CoolingPump => cell with
{
Kind = CellKind.CoolingPump,
Powered = true
},
EditorTool.Generator => cell with
{
Kind = CellKind.Generator,
Powered = true
},
EditorTool.PressureRegulator => cell with { Kind = CellKind.PressureRegulator },
EditorTool.DiagnosticTerminal => cell with { Kind = CellKind.DiagnosticTerminal, Powered = true },
EditorTool.ControlTerminal => cell with { Kind = CellKind.ControlTerminal, Powered = true },
EditorTool.CoolantPipe => cell with { Pipe = PipeMedium.Coolant, Flow = 4, Pressure = 4, Integrity = Math.Max(cell.Integrity, 8), PipeOpen = true },
EditorTool.FuelPipe => cell with { Pipe = PipeMedium.Fuel, Flow = 4, Pressure = 4, Integrity = Math.Max(cell.Integrity, 8), PipeOpen = true },
EditorTool.PressurePipe => cell with { Pipe = PipeMedium.Pressure, Flow = 5, Pressure = 6, Integrity = Math.Max(cell.Integrity, 8), PipeOpen = true },
EditorTool.Leak => cell with { LeakRate = Math.Max(1, cell.LeakRate), Integrity = Math.Min(cell.Integrity, 4) },
EditorTool.Repair => cell with { LeakRate = 0, Integrity = 10, Hazards = cell.Hazards with { Fire = false, ElectricalCharge = 0 } },
EditorTool.DiagnosticTerminal => cell with
{
Kind = CellKind.DiagnosticTerminal,
Powered = true
},
EditorTool.ControlTerminal => cell with
{
Kind = CellKind.ControlTerminal,
Powered = true
},
EditorTool.CoolantPipe => cell with
{
Pipe = PipeMedium.Coolant,
Flow = 4,
Pressure = 4,
Integrity = Math.Max(cell.Integrity, 8),
PipeOpen = true
},
EditorTool.FuelPipe => cell with
{
Pipe = PipeMedium.Fuel,
Flow = 4,
Pressure = 4,
Integrity = Math.Max(cell.Integrity, 8),
PipeOpen = true
},
EditorTool.PressurePipe => cell with
{
Pipe = PipeMedium.Pressure,
Flow = 5,
Pressure = 6,
Integrity = Math.Max(cell.Integrity, 8),
PipeOpen = true
},
EditorTool.Leak => cell with
{
LeakRate = Math.Max(1, cell.LeakRate),
Integrity = Math.Min(cell.Integrity, 4)
},
EditorTool.Repair => cell with
{
LeakRate = 0,
Integrity = 10,
Hazards = cell.Hazards with
{
Fire = false,
ElectricalCharge = 0
}
},
EditorTool.Heat => cell with { Hazards = cell.Hazards with { Heat = Rules.Clamp(cell.Hazards.Heat + 2) } },
EditorTool.Fire => cell with { Hazards = cell.Hazards with { Fire = !cell.Hazards.Fire, Heat = Math.Max(cell.Hazards.Heat, 7), Smoke = Math.Max(cell.Hazards.Smoke, 3) } },
EditorTool.Fire => cell with
{
Hazards = cell.Hazards with
{
Fire = !cell.Hazards.Fire,
Heat = Math.Max(cell.Hazards.Heat, 7),
Smoke = Math.Max(cell.Hazards.Smoke, 3)
}
},
_ => cell
};
if (cell.Kind == CellKind.Wall)
{
cell = cell with { Hazards = new HazardState() };
}
cell = cell with { Hazards = new() };
return level.SetCell(position, cell);
}
}
}