Description:
Refactor some repeated code in BuildToolEngine.
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r632:c18475dcd7c8 -

@@ -16,7 +16,6
16 [Receives(typeof(SpawnSelection),
16 [Receives(typeof(SpawnSelection),
17 typeof(AdjustSelection))]
17 typeof(AdjustSelection))]
18 [Writes(typeof(AreaComponent),
18 [Writes(typeof(AreaComponent),
19 // typeof(SelectedComponent),
20 typeof(PointComponent),
19 typeof(PointComponent),
21 typeof(PreserveComponent))]
20 typeof(PreserveComponent))]
22 [Reads(typeof(SelectedComponent),
21 [Reads(typeof(SelectedComponent),
@@ -79,11 +78,27
79 Destroy(entity);
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 public override void Update(double dt) {
101 public override void Update(double dt) {
86 var occupied = new List<Vector2>();
87 Dictionary<Tool, bool> statuses = new Dictionary<Tool, bool>();
102 Dictionary<Tool, bool> statuses = new Dictionary<Tool, bool>();
88
103
89 foreach (var entity in ReadEntities<ToolComponent>()) {
104 foreach (var entity in ReadEntities<ToolComponent>()) {
@@ -94,18 +109,7
94 }
109 }
95
110
96 if (statuses.ContainsKey(Tool.Preserve) && statuses[Tool.Preserve]) {
111 if (statuses.ContainsKey(Tool.Preserve) && statuses[Tool.Preserve]) {
97 foreach (var (entity, status) in ReadEntities<AreaComponent>()
112 var occupied = GetOccupied();
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 }
109 foreach (var entity in ReadEntities<AreaComponent>()
113 foreach (var entity in ReadEntities<AreaComponent>()
110 .WhereF((e) => HasComponent<PreserveComponent>(e))) {
114 .WhereF((e) => HasComponent<PreserveComponent>(e))) {
111 var entitySquares = GetComponent<AreaComponent>(entity).squares;
115 var entitySquares = GetComponent<AreaComponent>(entity).squares;
@@ -154,8 +158,7
154 }
158 }
155 }
159 }
156 }
160 }
157
161 SetComponent(entity, new AreaComponent { squares = newSquares.ToArray(), Tool = area.Tool});
158 SetComponent(entity, new AreaComponent { squares = newSquares.ToArray() /*new[]{ area.squares[0], message.End}*/, Tool = area.Tool});
159 }
162 }
160 }
163 }
161 }
164 }
@@ -198,9 +201,7
198 foreach (var i in step_until(area.squares[0].X, end_x)) {
201 foreach (var i in step_until(area.squares[0].X, end_x)) {
199 foreach (var j in step_until(area.squares[0].Y, end_y)) {
202 foreach (var j in step_until(area.squares[0].Y, end_y)) {
200 var newSquare = new Vector2(i, j);
203 var newSquare = new Vector2(i, j);
201 if (!occupied.Contains(newSquare)) {
204 newSquares.Add(newSquare);
202 newSquares.Add(newSquare);
203 }
204 }
205 }
205 }
206 }
206 SetComponent(entity, new AreaComponent { squares = newSquares.ToArray(), Tool = area.Tool});
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 var occupied = GetOccupied();
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 }
237
227
238 foreach (var (entity, point) in ReadEntities<StructureComponent>()
228 foreach (var (entity, point) in ReadEntities<StructureComponent>()
239 .WhereF((e) => HasComponent<PointComponent>(e))
229 .WhereF((e) => HasComponent<PointComponent>(e))
@@ -277,13 +267,9
277 Tool = point.Tool});
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