Description:
Refactor some repeated code in BuildToolEngine.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -16,7 +16,6 | |||
|
16 | 16 | [Receives(typeof(SpawnSelection), |
|
17 | 17 | typeof(AdjustSelection))] |
|
18 | 18 | [Writes(typeof(AreaComponent), |
|
19 | // typeof(SelectedComponent), | |
|
20 | 19 | typeof(PointComponent), |
|
21 | 20 | typeof(PreserveComponent))] |
|
22 | 21 | [Reads(typeof(SelectedComponent), |
@@ -79,11 +78,27 | |||
|
79 | 78 | Destroy(entity); |
|
80 | 79 | } |
|
81 | 80 | } |
|
81 | } | |
|
82 | 82 | |
|
83 | public List<Vector2> GetOccupied() { | |
|
84 | List<Vector2> occupied = new List<Vector2>(); | |
|
85 | ||
|
86 | foreach (var (entity, status) in ReadEntities<AreaComponent>() | |
|
87 | .WhereF((e) => HasComponent<ContractStatusComponent>(e)) | |
|
88 | .SelectWhereF((e) => (e, GetComponent<ContractStatusComponent>(e)), | |
|
89 | (e) => ((e.Item2.status != ContractStatus.Broken) | |
|
90 | && (e.Item2.status != ContractStatus.Rejected) | |
|
91 | && (e.Item2.status != ContractStatus.Expired) | |
|
92 | && (e.Item2.status != ContractStatus.Completed) | |
|
93 | && (e.Item2.status != ContractStatus.Proposed)) | |
|
94 | )) { | |
|
95 | var entitySquares = GetComponent<AreaComponent>(entity).squares; | |
|
96 | occupied.AddRange(entitySquares); | |
|
97 | } | |
|
98 | return occupied; | |
|
83 | 99 | } |
|
84 | 100 | |
|
85 | 101 | public override void Update(double dt) { |
|
86 | var occupied = new List<Vector2>(); | |
|
87 | 102 | Dictionary<Tool, bool> statuses = new Dictionary<Tool, bool>(); |
|
88 | 103 | |
|
89 | 104 | foreach (var entity in ReadEntities<ToolComponent>()) { |
@@ -94,18 +109,7 | |||
|
94 | 109 | } |
|
95 | 110 | |
|
96 | 111 | if (statuses.ContainsKey(Tool.Preserve) && statuses[Tool.Preserve]) { |
|
97 | foreach (var (entity, status) in ReadEntities<AreaComponent>() | |
|
98 | .WhereF((e) => HasComponent<ContractStatusComponent>(e)) | |
|
99 | .SelectWhereF((e) => (e, GetComponent<ContractStatusComponent>(e)), | |
|
100 | (e) => ((e.Item2.status != ContractStatus.Broken) | |
|
101 | && (e.Item2.status != ContractStatus.Rejected) | |
|
102 | && (e.Item2.status != ContractStatus.Expired) | |
|
103 | && (e.Item2.status != ContractStatus.Completed) | |
|
104 | && (e.Item2.status != ContractStatus.Proposed)) | |
|
105 | )) { | |
|
106 | var entitySquares = GetComponent<AreaComponent>(entity).squares; | |
|
107 | occupied.AddRange(entitySquares); | |
|
108 | } | |
|
112 | var occupied = GetOccupied(); | |
|
109 | 113 | foreach (var entity in ReadEntities<AreaComponent>() |
|
110 | 114 | .WhereF((e) => HasComponent<PreserveComponent>(e))) { |
|
111 | 115 | var entitySquares = GetComponent<AreaComponent>(entity).squares; |
@@ -154,8 +158,7 | |||
|
154 | 158 | } |
|
155 | 159 | } |
|
156 | 160 | } |
|
157 | ||
|
158 | SetComponent(entity, new AreaComponent { squares = newSquares.ToArray() /*new[]{ area.squares[0], message.End}*/, Tool = area.Tool}); | |
|
161 | SetComponent(entity, new AreaComponent { squares = newSquares.ToArray(), Tool = area.Tool}); | |
|
159 | 162 | } |
|
160 | 163 | } |
|
161 | 164 | } |
@@ -198,9 +201,7 | |||
|
198 | 201 | foreach (var i in step_until(area.squares[0].X, end_x)) { |
|
199 | 202 | foreach (var j in step_until(area.squares[0].Y, end_y)) { |
|
200 | 203 | var newSquare = new Vector2(i, j); |
|
201 |
|
|
|
202 | newSquares.Add(newSquare); | |
|
203 | } | |
|
204 | newSquares.Add(newSquare); | |
|
204 | 205 | } |
|
205 | 206 | } |
|
206 | 207 | SetComponent(entity, new AreaComponent { squares = newSquares.ToArray(), Tool = area.Tool}); |
@@ -222,18 +223,7 | |||
|
222 | 223 | } |
|
223 | 224 | } |
|
224 | 225 | |
|
225 | foreach (var (entity, status) in ReadEntities<AreaComponent>() | |
|
226 | .WhereF((e) => HasComponent<ContractStatusComponent>(e)) | |
|
227 | .SelectWhereF((e) => (e, GetComponent<ContractStatusComponent>(e)), | |
|
228 | (e) => ((e.Item2.status != ContractStatus.Broken) | |
|
229 | && (e.Item2.status != ContractStatus.Rejected) | |
|
230 | && (e.Item2.status != ContractStatus.Expired) | |
|
231 | && (e.Item2.status != ContractStatus.Completed) | |
|
232 | && (e.Item2.status != ContractStatus.Proposed)) | |
|
233 | )) { | |
|
234 | var entitySquares = GetComponent<AreaComponent>(entity).squares; | |
|
235 | occupied.AddRange(entitySquares); | |
|
236 | } | |
|
226 | var occupied = GetOccupied(); | |
|
237 | 227 | |
|
238 | 228 | foreach (var (entity, point) in ReadEntities<StructureComponent>() |
|
239 | 229 | .WhereF((e) => HasComponent<PointComponent>(e)) |
@@ -277,13 +267,9 | |||
|
277 | 267 | Tool = point.Tool}); |
|
278 | 268 | } |
|
279 | 269 | } |
|
280 | ||
|
281 | 270 | } |
|
282 | ||
|
283 | 271 | } |
|
284 | ||
|
285 | 272 | } |
|
286 | 273 | } |
|
287 | 274 | } |
|
288 | 275 | } |
|
289 |
You need to be logged in to leave comments.
Login now