Rework Win2D editor layers

This commit is contained in:
2026-05-11 22:34:19 +02:00
parent 69ed79ce86
commit 0651603fd2
5 changed files with 345 additions and 217 deletions

View File

@@ -2,6 +2,52 @@
public static class LevelEditor
{
public static LevelState MoveOccupant(LevelState level, GridPosition source, GridPosition destination)
{
if (!level.InBounds(source) || !level.IsFloor(destination) || source == destination)
return level;
var prop = level.GetProp(source);
if (prop.Type == EPropType.None)
return level.Robot.Position == source ? level with { Robot = level.Robot with { Position = destination } } : level;
if (level.GetProp(destination).Type != EPropType.None)
return level;
var next = level.SetProp(source, new()).SetProp(destination, prop);
if (prop.Type != EPropType.ReactorControl)
return next;
return next with {
Reactors = next.Reactors
.Select(reactor => reactor.ControlPosition == source ? reactor with { ControlPosition = destination } : reactor)
.ToArray()
};
}
public static LevelState CycleElectricityLeakAccess(LevelState level, GridPosition undergroundPosition)
{
if (!level.InBounds(undergroundPosition))
return level;
if (!level.GetUnderground(undergroundPosition, ECarrierType.Electricity).IsPresent)
return level;
var accessPositions = undergroundPosition.Neighbors().Where(level.IsFloor).ToArray();
if (accessPositions.Length == 0)
return level;
var existingLeak = level.Leaks.FirstOrDefault(leak => leak.Carrier == ECarrierType.Electricity && leak.UndergroundPosition == undergroundPosition);
var nextAccessPosition = accessPositions[0];
if (existingLeak is not null)
{
var index = Array.IndexOf(accessPositions, existingLeak.AccessPosition);
nextAccessPosition = accessPositions[(index + 1) % accessPositions.Length];
}
return SetLeak(level, undergroundPosition, nextAccessPosition, ECarrierType.Electricity);
}
public static LevelState Apply(LevelState level, GridPosition position, EditorToolCommand command)
{
if (!level.InBounds(position))