Description:
Refactor out selection spawning code.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -98,6 +98,34 | |||||
|
98 | } |
|
98 | } |
|
99 | } |
|
99 | } |
|
100 |
|
100 | ||
|
|
101 | private void SpawnPointSelection(Tool tool) { | ||
|
|
102 | foreach (ref readonly var message in ReadMessages<SpawnSelection>()) | ||
|
|
103 | { | ||
|
|
104 | if (message.Start.X >= 0 && message.Start.X < this.Map.MapWidth | ||
|
|
105 | && message.Start.Y >= 0 && message.Start.Y < this.Map.MapHeight) { | ||
|
|
106 | var entity = CreateEntity(); | ||
|
|
107 | |||
|
|
108 | AddComponent(entity, new PointComponent {Square = message.Start, | ||
|
|
109 | Tool=tool}); | ||
|
|
110 | AddComponent(entity, new SelectedComponent { selected = true, Type= SelectionType.Area}); | ||
|
|
111 | } | ||
|
|
112 | } | ||
|
|
113 | } | ||
|
|
114 | |||
|
|
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 | |||
|
101 | public List<Vector2> GetOccupied() { |
|
129 | public List<Vector2> GetOccupied() { |
|
102 | List<Vector2> occupied = new List<Vector2>(); |
|
130 | List<Vector2> occupied = new List<Vector2>(); |
|
103 |
|
131 | ||
@@ -134,17 +162,7 | |||||
|
134 | occupied.AddRange(entitySquares); |
|
162 | occupied.AddRange(entitySquares); |
|
135 | } |
|
163 | } |
|
136 |
|
164 | ||
|
137 | foreach (ref readonly var message in ReadMessages<SpawnSelection>()) |
|
165 | SpawnAreaSelection(Tool.Preserve); |
|
138 | { |
|
||
|
139 | if (message.Start.X >= 0 && message.Start.X < this.Map.MapWidth |
|
||
|
140 | && message.Start.Y >= 0 && message.Start.Y < this.Map.MapHeight) { |
|
||
|
141 | var entity = CreateEntity(); |
|
||
|
142 |
|
|||
|
143 | AddComponent(entity, new AreaComponent { squares = new[] {message.Start} , |
|
||
|
144 | Tool=Tool.Preserve}); |
|
||
|
145 | AddComponent(entity, new SelectedComponent { selected = true, Type= SelectionType.Area}); |
|
||
|
146 | } |
|
||
|
147 | } |
|
||
|
148 |
|
166 | ||
|
149 | foreach (ref readonly var message in ReadMessages<AdjustSelection>()) { |
|
167 | foreach (ref readonly var message in ReadMessages<AdjustSelection>()) { |
|
150 | foreach (ref readonly var entity in ReadEntities<SelectedComponent>()) { |
|
168 | foreach (ref readonly var entity in ReadEntities<SelectedComponent>()) { |
@@ -183,17 +201,7 | |||||
|
183 | } |
|
201 | } |
|
184 | } |
|
202 | } |
|
185 | else if (statuses.ContainsKey(Tool.Dezone) && statuses[Tool.Dezone]) { |
|
203 | else if (statuses.ContainsKey(Tool.Dezone) && statuses[Tool.Dezone]) { |
|
186 | foreach (ref readonly var message in ReadMessages<SpawnSelection>()) |
|
204 | SpawnAreaSelection(Tool.Dezone); |
|
187 | { |
|
||
|
188 | if (message.Start.X >= 0 && message.Start.X < this.Map.MapWidth |
|
||
|
189 | && message.Start.Y >= 0 && message.Start.Y < this.Map.MapHeight) { |
|
||
|
190 | var entity = CreateEntity(); |
|
||
|
191 |
|
|||
|
192 | AddComponent(entity, new AreaComponent { squares = new[] {message.Start}, |
|
||
|
193 | Tool = Tool.Dezone }); |
|
||
|
194 | AddComponent(entity, new SelectedComponent { selected = true, Type= SelectionType.Area}); |
|
||
|
195 | } |
|
||
|
196 | } |
|
||
|
197 |
|
205 | ||
|
198 | foreach (ref readonly var message in ReadMessages<AdjustSelection>()) { |
|
206 | foreach (ref readonly var message in ReadMessages<AdjustSelection>()) { |
|
199 | foreach (ref readonly var entity in ReadEntities<SelectedComponent>()) { |
|
207 | foreach (ref readonly var entity in ReadEntities<SelectedComponent>()) { |
@@ -228,17 +236,7 | |||||
|
228 | } |
|
236 | } |
|
229 | } |
|
237 | } |
|
230 | else if (statuses.ContainsKey(Tool.Tower) && statuses[Tool.Tower]) { |
|
238 | else if (statuses.ContainsKey(Tool.Tower) && statuses[Tool.Tower]) { |
|
231 | foreach (ref readonly var message in ReadMessages<SpawnSelection>()) |
|
239 | SpawnPointSelection(Tool.Tower); |
|
232 | { |
|
||
|
233 | if (message.Start.X >= 0 && message.Start.X < this.Map.MapWidth |
|
||
|
234 | && message.Start.Y >= 0 && message.Start.Y < this.Map.MapHeight) { |
|
||
|
235 | var entity = CreateEntity(); |
|
||
|
236 |
|
|||
|
237 | AddComponent(entity, new PointComponent {Square = message.Start, |
|
||
|
238 | Tool=Tool.Tower}); |
|
||
|
239 | AddComponent(entity, new SelectedComponent { selected = true, Type= SelectionType.Area}); |
|
||
|
240 | } |
|
||
|
241 | } |
|
||
|
242 |
|
240 | ||
|
243 | var occupied = GetOccupied(); |
|
241 | var occupied = GetOccupied(); |
|
244 |
|
242 | ||
@@ -289,17 +287,7 | |||||
|
289 | } |
|
287 | } |
|
290 |
|
288 | ||
|
291 | else if ((statuses.ContainsKey(Tool.Bulldozer) && statuses[Tool.Bulldozer])) { |
|
289 | else if ((statuses.ContainsKey(Tool.Bulldozer) && statuses[Tool.Bulldozer])) { |
|
292 | foreach (ref readonly var message in ReadMessages<SpawnSelection>()) |
|
290 | SpawnAreaSelection(Tool.Bulldozer); |
|
293 | { |
|
||
|
294 | if (message.Start.X >= 0 && message.Start.X < this.Map.MapWidth |
|
||
|
295 | && message.Start.Y >= 0 && message.Start.Y < this.Map.MapHeight) { |
|
||
|
296 | var entity = CreateEntity(); |
|
||
|
297 |
|
|||
|
298 | AddComponent(entity, new AreaComponent { squares = new[] {message.Start}, |
|
||
|
299 | Tool = Tool.Bulldozer }); |
|
||
|
300 | AddComponent(entity, new SelectedComponent { selected = true, Type= SelectionType.Area}); |
|
||
|
301 | } |
|
||
|
302 | } |
|
||
|
303 |
|
291 | ||
|
304 | foreach (ref readonly var message in ReadMessages<AdjustSelection>()) { |
|
292 | foreach (ref readonly var message in ReadMessages<AdjustSelection>()) { |
|
305 | foreach (ref readonly var entity in ReadEntities<SelectedComponent>()) { |
|
293 | foreach (ref readonly var entity in ReadEntities<SelectedComponent>()) { |
You need to be logged in to leave comments.
Login now