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 | 21 | [Reads(typeof(SelectedComponent), |
|
22 | 22 | typeof(ContractStatusComponent), |
|
23 | 23 | typeof(AreaComponent), |
|
24 |
typeof(PreserveComponent) |
|
|
24 | typeof(PreserveComponent), | |
|
25 | typeof(SelectedComponent), | |
|
26 | typeof(ToolComponent))] | |
|
25 | 27 | public class BuildToolEngine : Engine { |
|
26 | 28 | |
|
27 | 29 | private CellMap Map; |
@@ -47,72 +49,84 | |||
|
47 | 49 | |
|
48 | 50 | public override void Update(double dt) { |
|
49 | 51 | var occupied = new List<Vector2>(); |
|
50 | foreach (var (entity, status) in ReadEntities<AreaComponent>() | |
|
51 | .WhereF((e) => HasComponent<ContractStatusComponent>(e)) | |
|
52 | .SelectWhereF((e) => (e, GetComponent<ContractStatusComponent>(e)), | |
|
53 | (e) => ((e.Item2.status != ContractStatus.Broken) | |
|
54 | && (e.Item2.status != ContractStatus.Rejected) | |
|
55 | && (e.Item2.status != ContractStatus.Expired) | |
|
56 | && (e.Item2.status != ContractStatus.Completed) | |
|
57 | && (e.Item2.status != ContractStatus.Proposed)) | |
|
58 | )) { | |
|
59 | var entitySquares = GetComponent<AreaComponent>(entity).squares; | |
|
60 | occupied.AddRange(entitySquares); | |
|
52 | ||
|
53 | Dictionary<Tool, bool> statuses = new Dictionary<Tool, bool>(); | |
|
54 | ||
|
55 | foreach (var entity in ReadEntities<ToolComponent>()) { | |
|
56 | var tool = GetComponent<ToolComponent>(entity); | |
|
57 | var selected = GetComponent<SelectedComponent>(entity); | |
|
58 | ||
|
59 | statuses.Add(tool.Tool, selected.selected); | |
|
61 | 60 | } |
|
62 | foreach (var entity in ReadEntities<AreaComponent>() | |
|
63 | .WhereF((e) => HasComponent<PreserveComponent>(e))) { | |
|
64 | var entitySquares = GetComponent<AreaComponent>(entity).squares; | |
|
65 | occupied.AddRange(entitySquares); | |
|
66 | } | |
|
61 | ||
|
62 | if (statuses.ContainsKey(Tool.Preserve) && statuses[Tool.Preserve]) { | |
|
63 | foreach (var (entity, status) in ReadEntities<AreaComponent>() | |
|
64 | .WhereF((e) => HasComponent<ContractStatusComponent>(e)) | |
|
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>()) | |
|
71 | { | |
|
72 | if (message.Start.X >= 0 && message.Start.X < this.Map.MapWidth | |
|
73 | && message.Start.Y >= 0 && message.Start.Y < this.Map.MapHeight) { | |
|
74 | 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 | } | |
|
83 | foreach (ref readonly var message in ReadMessages<SpawnSelection>()) | |
|
84 | { | |
|
85 | if (message.Start.X >= 0 && message.Start.X < this.Map.MapWidth | |
|
86 | && message.Start.Y >= 0 && message.Start.Y < this.Map.MapHeight) { | |
|
87 | var entity = CreateEntity(); | |
|
80 | 88 | |
|
81 | foreach (ref readonly var message in ReadMessages<AdjustSelection>()) { | |
|
82 | foreach (ref readonly var entity in ReadEntities<SelectedComponent>()) { | |
|
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 | } | |
|
89 | AddComponent(entity, new AreaComponent { squares = new[] {message.Start} }); | |
|
90 | AddComponent(entity, new SelectedComponent { selected = true, Type= SelectionType.Area}); | |
|
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 | 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 | 247 | SendMessage(new SpawnSelection {Start = CellMap.calculateMousegrid(original_point)}); |
@@ -36,8 +36,8 | |||
|
36 | 36 | |
|
37 | 37 | if (!HasComponent<ContractStatusComponent>(entity) ) |
|
38 | 38 | { |
|
39 |
Quad.FillSquares(batch, areaComponent.squares, Color. |
|
|
40 |
Tile.DrawOutlinedSquares(batch, areaComponent.squares, Color. |
|
|
39 | Quad.FillSquares(batch, areaComponent.squares, Color.Blue, 0.5f, 0.79f); | |
|
40 | Tile.DrawOutlinedSquares(batch, areaComponent.squares, Color.Blue); | |
|
41 | 41 | } |
|
42 | 42 | else if ((!HasComponent<ContractStatusComponent>(entity) |
|
43 | 43 | || GetComponent<ContractStatusComponent>(entity).status == ContractStatus.Accepted) |
You need to be logged in to leave comments.
Login now