Description:
Only build preserve when selected.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -21,7 +21,9 | |||||
|
21 | [Reads(typeof(SelectedComponent), |
|
21 | [Reads(typeof(SelectedComponent), |
|
22 | typeof(ContractStatusComponent), |
|
22 | typeof(ContractStatusComponent), |
|
23 | typeof(AreaComponent), |
|
23 | typeof(AreaComponent), |
|
24 |
typeof(PreserveComponent) |
|
24 | typeof(PreserveComponent), |
|
|
25 | typeof(SelectedComponent), | ||
|
|
26 | typeof(ToolComponent))] | ||
|
25 | public class BuildToolEngine : Engine { |
|
27 | public class BuildToolEngine : Engine { |
|
26 |
|
28 | ||
|
27 | private CellMap Map; |
|
29 | private CellMap Map; |
@@ -47,72 +49,84 | |||||
|
47 |
|
49 | ||
|
48 | public override void Update(double dt) { |
|
50 | public override void Update(double dt) { |
|
49 | var occupied = new List<Vector2>(); |
|
51 | var occupied = new List<Vector2>(); |
|
50 | foreach (var (entity, status) in ReadEntities<AreaComponent>() |
|
52 | |
|
51 | .WhereF((e) => HasComponent<ContractStatusComponent>(e)) |
|
53 | Dictionary<Tool, bool> statuses = new Dictionary<Tool, bool>(); |
|
52 | .SelectWhereF((e) => (e, GetComponent<ContractStatusComponent>(e)), |
|
54 | |
|
53 | (e) => ((e.Item2.status != ContractStatus.Broken) |
|
55 | foreach (var entity in ReadEntities<ToolComponent>()) { |
|
54 | && (e.Item2.status != ContractStatus.Rejected) |
|
56 | var tool = GetComponent<ToolComponent>(entity); |
|
55 | && (e.Item2.status != ContractStatus.Expired) |
|
57 | var selected = GetComponent<SelectedComponent>(entity); |
|
56 | && (e.Item2.status != ContractStatus.Completed) |
|
58 | |
|
57 | && (e.Item2.status != ContractStatus.Proposed)) |
|
59 | statuses.Add(tool.Tool, selected.selected); |
|
58 | )) { |
|
||
|
59 | var entitySquares = GetComponent<AreaComponent>(entity).squares; |
|
||
|
60 | occupied.AddRange(entitySquares); |
|
||
|
61 | } |
|
60 | } |
|
62 | foreach (var entity in ReadEntities<AreaComponent>() |
|
61 | |
|
63 | .WhereF((e) => HasComponent<PreserveComponent>(e))) { |
|
62 | if (statuses.ContainsKey(Tool.Preserve) && statuses[Tool.Preserve]) { |
|
64 | var entitySquares = GetComponent<AreaComponent>(entity).squares; |
|
63 | foreach (var (entity, status) in ReadEntities<AreaComponent>() |
|
65 | occupied.AddRange(entitySquares); |
|
64 | .WhereF((e) => HasComponent<ContractStatusComponent>(e)) |
|
66 | } |
|
65 | .SelectWhereF((e) => (e, GetComponent<ContractStatusComponent>(e)), |
|
|
66 | (e) => ((e.Item2.status != ContractStatus.Broken) | ||
|
|
67 | && (e.Item2.status != ContractStatus.Rejected) | ||
|
|
68 | && (e.Item2.status != ContractStatus.Expired) | ||
|
|
69 | && (e.Item2.status != ContractStatus.Completed) | ||
|
|
70 | && (e.Item2.status != ContractStatus.Proposed)) | ||
|
|
71 | )) { | ||
|
|
72 | var entitySquares = GetComponent<AreaComponent>(entity).squares; | ||
|
|
73 | occupied.AddRange(entitySquares); | ||
|
|
74 | } | ||
|
|
75 | foreach (var entity in ReadEntities<AreaComponent>() | ||
|
|
76 | .WhereF((e) => HasComponent<PreserveComponent>(e))) { | ||
|
|
77 | var entitySquares = GetComponent<AreaComponent>(entity).squares; | ||
|
|
78 | occupied.AddRange(entitySquares); | ||
|
|
79 | } | ||
|
67 |
|
80 | ||
|
68 |
|
81 | ||
|
69 |
|
82 | ||
|
70 | foreach (ref readonly var message in ReadMessages<SpawnSelection>()) |
|
83 | foreach (ref readonly var message in ReadMessages<SpawnSelection>()) |
|
71 | { |
|
84 | { |
|
72 | if (message.Start.X >= 0 && message.Start.X < this.Map.MapWidth |
|
85 | if (message.Start.X >= 0 && message.Start.X < this.Map.MapWidth |
|
73 | && message.Start.Y >= 0 && message.Start.Y < this.Map.MapHeight) { |
|
86 | && message.Start.Y >= 0 && message.Start.Y < this.Map.MapHeight) { |
|
74 | var entity = CreateEntity(); |
|
87 | var entity = CreateEntity(); |
|
75 |
|
|||
|
76 | AddComponent(entity, new AreaComponent { squares = new[] {message.Start} }); |
|
||
|
77 | AddComponent(entity, new SelectedComponent { selected = true, Type= SelectionType.Area}); |
|
||
|
78 | } |
|
||
|
79 | } |
|
||
|
80 |
|
88 | ||
|
81 | foreach (ref readonly var message in ReadMessages<AdjustSelection>()) { |
|
89 | AddComponent(entity, new AreaComponent { squares = new[] {message.Start} }); |
|
82 | foreach (ref readonly var entity in ReadEntities<SelectedComponent>()) { |
|
90 | AddComponent(entity, new SelectedComponent { selected = true, Type= SelectionType.Area}); |
|
83 | var selection = GetComponent<SelectedComponent>(entity); |
|
||
|
84 | if(selection.Type == SelectionType.Area |
|
||
|
85 | && selection.selected) { |
|
||
|
86 | if(message.Type == AdjustmentType.Clear) { |
|
||
|
87 | Destroy(entity); |
|
||
|
88 | } |
|
||
|
89 | else if(message.Type == AdjustmentType.Complete) { |
|
||
|
90 | SetComponent(entity, new PreserveComponent {}); |
|
||
|
91 | // SetComponent(entity, new SelectedComponent {selected = false }); |
|
||
|
92 | } |
|
||
|
93 | else { |
|
||
|
94 | var area = GetComponent<AreaComponent>(entity); |
|
||
|
95 |
|
|||
|
96 | var newSquares = new List<Vector2>(); |
|
||
|
97 |
|
|||
|
98 | var end_x = MathUtils.Clamp(message.End.X, 0.0f, this.Map.MapWidth); |
|
||
|
99 | var end_y = MathUtils.Clamp(message.End.Y, 0.0f, this.Map.MapHeight); |
|
||
|
100 |
|
|||
|
101 | foreach (var i in step_until(area.squares[0].X, end_x)) { |
|
||
|
102 | foreach (var j in step_until(area.squares[0].Y, end_y)) { |
|
||
|
103 | var newSquare = new Vector2(i, j); |
|
||
|
104 | if (!occupied.Contains(newSquare)) { |
|
||
|
105 | newSquares.Add(newSquare); |
|
||
|
106 | } |
|
||
|
107 | } |
|
||
|
108 | } |
|
||
|
109 |
|
|||
|
110 | SetComponent(entity, new AreaComponent { squares = newSquares.ToArray() /*( new[]{ area.squares[0], message.End}*/}); |
|
||
|
111 | } |
|
||
|
112 | } |
|
91 | } |
|
113 | } |
|
92 | } |
|
114 |
|
93 | ||
|
115 | } |
|
94 | foreach (ref readonly var message in ReadMessages<AdjustSelection>()) { |
|
|
95 | foreach (ref readonly var entity in ReadEntities<SelectedComponent>()) { | ||
|
|
96 | var selection = GetComponent<SelectedComponent>(entity); | ||
|
|
97 | if(selection.Type == SelectionType.Area | ||
|
|
98 | && selection.selected) { | ||
|
|
99 | if(message.Type == AdjustmentType.Clear) { | ||
|
|
100 | Destroy(entity); | ||
|
|
101 | } | ||
|
|
102 | else if(message.Type == AdjustmentType.Complete) { | ||
|
|
103 | SetComponent(entity, new PreserveComponent {}); | ||
|
|
104 | // SetComponent(entity, new SelectedComponent {selected = false }); | ||
|
|
105 | } | ||
|
|
106 | else { | ||
|
|
107 | var area = GetComponent<AreaComponent>(entity); | ||
|
|
108 | |||
|
|
109 | var newSquares = new List<Vector2>(); | ||
|
|
110 | |||
|
|
111 | var end_x = MathUtils.Clamp(message.End.X, 0.0f, this.Map.MapWidth); | ||
|
|
112 | var end_y = MathUtils.Clamp(message.End.Y, 0.0f, this.Map.MapHeight); | ||
|
|
113 | |||
|
|
114 | foreach (var i in step_until(area.squares[0].X, end_x)) { | ||
|
|
115 | foreach (var j in step_until(area.squares[0].Y, end_y)) { | ||
|
|
116 | var newSquare = new Vector2(i, j); | ||
|
|
117 | if (!occupied.Contains(newSquare)) { | ||
|
|
118 | newSquares.Add(newSquare); | ||
|
|
119 | } | ||
|
|
120 | } | ||
|
|
121 | } | ||
|
|
122 | |||
|
|
123 | SetComponent(entity, new AreaComponent { squares = newSquares.ToArray() /*( new[]{ area.squares[0], message.End}*/}); | ||
|
|
124 | } | ||
|
|
125 | } | ||
|
|
126 | } | ||
|
|
127 | |||
|
|
128 | } | ||
|
|
129 | } | ||
|
116 | } |
|
130 | } |
|
117 | } |
|
131 | } |
|
118 | } |
|
132 | } |
@@ -241,7 +241,7 | |||||
|
241 | } |
|
241 | } |
|
242 |
|
242 | ||
|
243 | if (mouseCur.LeftButton == ButtonState.Pressed && mousePrev.LeftButton == ButtonState.Released |
|
243 | if (mouseCur.LeftButton == ButtonState.Pressed && mousePrev.LeftButton == ButtonState.Released |
|
244 | && keyboardCur.IsKeyDown(Keys.LeftShift) |
|
244 | // && keyboardCur.IsKeyDown(Keys.LeftShift) |
|
245 | ) |
|
245 | ) |
|
246 | { |
|
246 | { |
|
247 | SendMessage(new SpawnSelection {Start = CellMap.calculateMousegrid(original_point)}); |
|
247 | SendMessage(new SpawnSelection {Start = CellMap.calculateMousegrid(original_point)}); |
@@ -36,8 +36,8 | |||||
|
36 |
|
36 | ||
|
37 | if (!HasComponent<ContractStatusComponent>(entity) ) |
|
37 | if (!HasComponent<ContractStatusComponent>(entity) ) |
|
38 | { |
|
38 | { |
|
39 |
Quad.FillSquares(batch, areaComponent.squares, Color. |
|
39 | Quad.FillSquares(batch, areaComponent.squares, Color.Blue, 0.5f, 0.79f); |
|
40 |
Tile.DrawOutlinedSquares(batch, areaComponent.squares, Color. |
|
40 | Tile.DrawOutlinedSquares(batch, areaComponent.squares, Color.Blue); |
|
41 | } |
|
41 | } |
|
42 | else if ((!HasComponent<ContractStatusComponent>(entity) |
|
42 | else if ((!HasComponent<ContractStatusComponent>(entity) |
|
43 | || GetComponent<ContractStatusComponent>(entity).status == ContractStatus.Accepted) |
|
43 | || GetComponent<ContractStatusComponent>(entity).status == ContractStatus.Accepted) |
You need to be logged in to leave comments.
Login now