Description:
Further refactoring.
I don't love this, but I think it lays the groundwork for future refactorings.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -165,6 +165,10 | |||
|
165 | 165 | - Additional in-game menu |
|
166 | 166 | - Save |
|
167 | 167 | - Save & Quit |
|
168 | - Fix selection | |
|
169 | 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 | |
|
170 | - Turn tools into classes? | |
|
171 | Creating a shallow hierarchy seems a little nicer than the current setup. | |
|
168 | 172 | |
|
169 | 173 | Music and Audio: |
|
170 | 174 | Sound Effects: |
@@ -33,6 +33,11 | |||
|
33 | 33 | |
|
34 | 34 | private CellMap Map; |
|
35 | 35 | |
|
36 | private static Dictionary<Tool, bool> ToolArea = new Dictionary<Tool, bool> {{Tool.Preserve, true}, | |
|
37 | {Tool.Dezone, true}, | |
|
38 | {Tool.Tower, false}, | |
|
39 | {Tool.Bulldozer, true}}; | |
|
40 | ||
|
36 | 41 | public BuildToolEngine(CellMap map) { |
|
37 | 42 | this.Map = map; |
|
38 | 43 | } |
@@ -98,33 +103,25 | |||
|
98 | 103 | } |
|
99 | 104 | } |
|
100 | 105 | |
|
101 |
private void Spawn |
|
|
106 | private void SpawnSelection(Tool tool) { | |
|
102 | 107 | foreach (ref readonly var message in ReadMessages<SpawnSelection>()) |
|
103 | 108 | { |
|
104 | 109 | if (message.Start.X >= 0 && message.Start.X < this.Map.MapWidth |
|
105 | 110 | && message.Start.Y >= 0 && message.Start.Y < this.Map.MapHeight) { |
|
106 | 111 | var entity = CreateEntity(); |
|
107 | ||
|
108 |
AddComponent(entity, new |
|
|
109 | Tool=tool}); | |
|
110 | AddComponent(entity, new SelectedComponent { selected = true, Type= SelectionType.Area}); | |
|
112 | if (BuildToolEngine.ToolArea[tool]) { | |
|
113 | AddComponent(entity, new AreaComponent {squares = new[] {message.Start}, | |
|
114 | Tool = tool}); | |
|
115 | } | |
|
116 | else { | |
|
117 | AddComponent(entity, new PointComponent {Square = message.Start, | |
|
118 | Tool=tool}); | |
|
119 | } | |
|
120 | AddComponent(entity, new SelectedComponent {selected = true, Type= SelectionType.Area}); | |
|
111 | 121 | } |
|
112 | 122 | } |
|
113 | 123 | } |
|
114 | 124 | |
|
115 | private void SpawnAreaSelection(Tool tool) { | |
|
116 | foreach (ref readonly var message in ReadMessages<SpawnSelection>()) | |
|
117 | { | |
|
118 | if (message.Start.X >= 0 && message.Start.X < this.Map.MapWidth | |
|
119 | && message.Start.Y >= 0 && message.Start.Y < this.Map.MapHeight) { | |
|
120 | var entity = CreateEntity(); | |
|
121 | ||
|
122 | AddComponent(entity, new AreaComponent { squares = new[] {message.Start}, | |
|
123 | Tool = tool}); | |
|
124 | AddComponent(entity, new SelectedComponent { selected = true, Type= SelectionType.Area}); | |
|
125 | } | |
|
126 | } | |
|
127 | } | |
|
128 | 125 | |
|
129 | 126 | public List<Vector2> GetOccupied() { |
|
130 | 127 | List<Vector2> occupied = new List<Vector2>(); |
@@ -162,7 +159,7 | |||
|
162 | 159 | occupied.AddRange(entitySquares); |
|
163 | 160 | } |
|
164 | 161 | |
|
165 |
Spawn |
|
|
162 | SpawnSelection(Tool.Preserve); | |
|
166 | 163 | |
|
167 | 164 | foreach (ref readonly var message in ReadMessages<AdjustSelection>()) { |
|
168 | 165 | foreach (ref readonly var entity in ReadEntities<SelectedComponent>()) { |
@@ -201,7 +198,7 | |||
|
201 | 198 | } |
|
202 | 199 | } |
|
203 | 200 | else if (statuses.ContainsKey(Tool.Dezone) && statuses[Tool.Dezone]) { |
|
204 |
Spawn |
|
|
201 | SpawnSelection(Tool.Dezone); | |
|
205 | 202 | |
|
206 | 203 | foreach (ref readonly var message in ReadMessages<AdjustSelection>()) { |
|
207 | 204 | foreach (ref readonly var entity in ReadEntities<SelectedComponent>()) { |
@@ -236,7 +233,7 | |||
|
236 | 233 | } |
|
237 | 234 | } |
|
238 | 235 | else if (statuses.ContainsKey(Tool.Tower) && statuses[Tool.Tower]) { |
|
239 |
Spawn |
|
|
236 | SpawnSelection(Tool.Tower); | |
|
240 | 237 | |
|
241 | 238 | var occupied = GetOccupied(); |
|
242 | 239 | |
@@ -287,7 +284,7 | |||
|
287 | 284 | } |
|
288 | 285 | |
|
289 | 286 | else if ((statuses.ContainsKey(Tool.Bulldozer) && statuses[Tool.Bulldozer])) { |
|
290 |
Spawn |
|
|
287 | SpawnSelection(Tool.Bulldozer); | |
|
291 | 288 | |
|
292 | 289 | foreach (ref readonly var message in ReadMessages<AdjustSelection>()) { |
|
293 | 290 | foreach (ref readonly var entity in ReadEntities<SelectedComponent>()) { |
You need to be logged in to leave comments.
Login now