diff --git a/TODO.taskpaper b/TODO.taskpaper --- a/TODO.taskpaper +++ b/TODO.taskpaper @@ -165,6 +165,10 @@ - Additional in-game menu - Save - Save & Quit + - Fix selection + Selections require two components to really work, which is messy and doesn't really fit. A Selection without some sort of associated selection that describes what's selected doesn't really work + - Turn tools into classes? + Creating a shallow hierarchy seems a little nicer than the current setup. Music and Audio: Sound Effects: diff --git a/isometric-park-fna/Engines/BuildToolEngine.cs b/isometric-park-fna/Engines/BuildToolEngine.cs --- a/isometric-park-fna/Engines/BuildToolEngine.cs +++ b/isometric-park-fna/Engines/BuildToolEngine.cs @@ -33,6 +33,11 @@ private CellMap Map; + private static Dictionary ToolArea = new Dictionary {{Tool.Preserve, true}, + {Tool.Dezone, true}, + {Tool.Tower, false}, + {Tool.Bulldozer, true}}; + public BuildToolEngine(CellMap map) { this.Map = map; } @@ -98,33 +103,25 @@ } } - private void SpawnPointSelection(Tool tool) { + private void SpawnSelection(Tool tool) { foreach (ref readonly var message in ReadMessages()) { if (message.Start.X >= 0 && message.Start.X < this.Map.MapWidth && message.Start.Y >= 0 && message.Start.Y < this.Map.MapHeight) { var entity = CreateEntity(); - - AddComponent(entity, new PointComponent {Square = message.Start, - Tool=tool}); - AddComponent(entity, new SelectedComponent { selected = true, Type= SelectionType.Area}); + if (BuildToolEngine.ToolArea[tool]) { + AddComponent(entity, new AreaComponent {squares = new[] {message.Start}, + Tool = tool}); + } + else { + AddComponent(entity, new PointComponent {Square = message.Start, + Tool=tool}); + } + AddComponent(entity, new SelectedComponent {selected = true, Type= SelectionType.Area}); } } } - private void SpawnAreaSelection(Tool tool) { - foreach (ref readonly var message in ReadMessages()) - { - if (message.Start.X >= 0 && message.Start.X < this.Map.MapWidth - && message.Start.Y >= 0 && message.Start.Y < this.Map.MapHeight) { - var entity = CreateEntity(); - - AddComponent(entity, new AreaComponent { squares = new[] {message.Start}, - Tool = tool}); - AddComponent(entity, new SelectedComponent { selected = true, Type= SelectionType.Area}); - } - } - } public List GetOccupied() { List occupied = new List(); @@ -162,7 +159,7 @@ occupied.AddRange(entitySquares); } - SpawnAreaSelection(Tool.Preserve); + SpawnSelection(Tool.Preserve); foreach (ref readonly var message in ReadMessages()) { foreach (ref readonly var entity in ReadEntities()) { @@ -201,7 +198,7 @@ } } else if (statuses.ContainsKey(Tool.Dezone) && statuses[Tool.Dezone]) { - SpawnAreaSelection(Tool.Dezone); + SpawnSelection(Tool.Dezone); foreach (ref readonly var message in ReadMessages()) { foreach (ref readonly var entity in ReadEntities()) { @@ -236,7 +233,7 @@ } } else if (statuses.ContainsKey(Tool.Tower) && statuses[Tool.Tower]) { - SpawnPointSelection(Tool.Tower); + SpawnSelection(Tool.Tower); var occupied = GetOccupied(); @@ -287,7 +284,7 @@ } else if ((statuses.ContainsKey(Tool.Bulldozer) && statuses[Tool.Bulldozer])) { - SpawnAreaSelection(Tool.Bulldozer); + SpawnSelection(Tool.Bulldozer); foreach (ref readonly var message in ReadMessages()) { foreach (ref readonly var entity in ReadEntities()) {