# HG changeset patch # User Alys Brooks # Date 2022-02-13 12:29:50 # Node ID 99b285f3e6d3ab03deceb7a25488a1ce3543e2e0 # Parent 5c22e0ed170b844bad1098931e9a166176e68405 Allow finalizing preserve areas. diff --git a/isometric-park-fna/Components/PreserveComponent.cs b/isometric-park-fna/Components/PreserveComponent.cs new file mode 100644 --- /dev/null +++ b/isometric-park-fna/Components/PreserveComponent.cs @@ -0,0 +1,10 @@ + +using Encompass; +using System; + +namespace isometricparkfna.Components { + + public struct PreserveComponent : IComponent { + public DateTime date; + } +} diff --git a/isometric-park-fna/Engines/BuildToolEngine.cs b/isometric-park-fna/Engines/BuildToolEngine.cs --- a/isometric-park-fna/Engines/BuildToolEngine.cs +++ b/isometric-park-fna/Engines/BuildToolEngine.cs @@ -14,7 +14,9 @@ [Receives(typeof(SpawnSelection), typeof(AdjustSelection))] - [Writes(typeof(AreaComponent))] + [Writes(typeof(AreaComponent), + // typeof(SelectedComponent), + typeof(PreserveComponent))] [Reads(typeof(SelectedComponent), typeof(AreaComponent))] public class BuildToolEngine : Engine { @@ -44,28 +46,32 @@ foreach (ref readonly var message in ReadMessages()) { + if (message.Start.X >= 0 && message.Start.X < this.Map.MapWidth + && message.Start.Y >= 0 && message.Start.Y < this.Map.MapHeight) { var entity = CreateEntity(); AddComponent(entity, new AreaComponent { squares = new[] {message.Start} }); AddComponent(entity, new SelectedComponent { selected = true, Type= SelectionType.ActiveTool}); + } } - foreach (ref readonly var message in ReadMessages()) - { - foreach (ref readonly var entity in ReadEntities()) - { + foreach (ref readonly var message in ReadMessages()) { + foreach (ref readonly var entity in ReadEntities()) { var selection = GetComponent(entity); - if(selection.Type == SelectionType.ActiveTool) { - if(message.Clear) { + if(selection.Type == SelectionType.ActiveTool + && selection.selected) { + if(message.Type == AdjustmentType.Clear) { Destroy(entity); } + else if(message.Type == AdjustmentType.Complete) { + SetComponent(entity, new PreserveComponent {}); + // SetComponent(entity, new SelectedComponent {selected = false }); + } else { var area = GetComponent(entity); var newSquares = new List(); - newSquares.Add(area.squares[0]); - var end_x = MathUtils.Clamp(message.End.X, 0.0f, this.Map.MapWidth); var end_y = MathUtils.Clamp(message.End.Y, 0.0f, this.Map.MapHeight); @@ -75,8 +81,6 @@ } } - newSquares.Add(message.End); - SetComponent(entity, new AreaComponent { squares = newSquares.ToArray() /*( new[]{ area.squares[0], message.End}*/}); } } diff --git a/isometric-park-fna/Engines/InputEngine.cs b/isometric-park-fna/Engines/InputEngine.cs --- a/isometric-park-fna/Engines/InputEngine.cs +++ b/isometric-park-fna/Engines/InputEngine.cs @@ -188,6 +188,7 @@ { SendMessage(new ToggleWindowTypeMessage {Window = Window.InGameMenu}); SendMessage(new GameRateMessage { paused = true, rate = null }); + SendMessage(new AdjustSelection {Type = AdjustmentType.Complete }); } } @@ -248,7 +249,7 @@ if ( mouseCur.LeftButton == ButtonState.Released && mousePrev.LeftButton == ButtonState.Pressed ) { - SendMessage(new AdjustSelection {Clear = true }); + SendMessage(new AdjustSelection {Type = AdjustmentType.Complete }); } if (mouseCur.LeftButton == ButtonState.Pressed && mousePrev.LeftButton == ButtonState.Pressed) diff --git a/isometric-park-fna/Engines/UIEngine.cs b/isometric-park-fna/Engines/UIEngine.cs --- a/isometric-park-fna/Engines/UIEngine.cs +++ b/isometric-park-fna/Engines/UIEngine.cs @@ -20,7 +20,8 @@ typeof(SetWindowVisibilityMessage), typeof(SelectMessage), typeof(SetDialogMessage), - typeof(DialogChoiceMessage))] + typeof(DialogChoiceMessage), + typeof(AdjustSelection))] [Reads(typeof(DialogComponent), typeof(WindowTypeComponent), typeof(VisibilityComponent), @@ -101,7 +102,20 @@ new SelectedComponent { selected = true }); } + foreach (ref readonly var message in ReadMessages()) { + if(message.Type == AdjustmentType.Complete) { + foreach (ref readonly var entity in ReadEntities()) { + var selection = GetComponent(entity); + if(selection.Type == SelectionType.ActiveTool + && selection.selected) { + SetComponent(entity, new SelectedComponent {Type = SelectionType.ActiveTool, + selected = false }); + } + } + } + } - } - } + + } + } } diff --git a/isometric-park-fna/Messages/AdjustSelection.cs b/isometric-park-fna/Messages/AdjustSelection.cs --- a/isometric-park-fna/Messages/AdjustSelection.cs +++ b/isometric-park-fna/Messages/AdjustSelection.cs @@ -3,8 +3,15 @@ using Encompass; namespace isometricparkfna.Messages { + + public enum AdjustmentType { + None, + Clear, + Complete + } + public struct AdjustSelection : IMessage { public Vector2 End; - public bool Clear; + public AdjustmentType Type; } }