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 @@ -16,7 +16,6 @@ [Receives(typeof(SpawnSelection), typeof(AdjustSelection))] [Writes(typeof(AreaComponent), - // typeof(SelectedComponent), typeof(PointComponent), typeof(PreserveComponent))] [Reads(typeof(SelectedComponent), @@ -79,11 +78,27 @@ Destroy(entity); } } + } + public List GetOccupied() { + List occupied = new List(); + + foreach (var (entity, status) in ReadEntities() + .WhereF((e) => HasComponent(e)) + .SelectWhereF((e) => (e, GetComponent(e)), + (e) => ((e.Item2.status != ContractStatus.Broken) + && (e.Item2.status != ContractStatus.Rejected) + && (e.Item2.status != ContractStatus.Expired) + && (e.Item2.status != ContractStatus.Completed) + && (e.Item2.status != ContractStatus.Proposed)) + )) { + var entitySquares = GetComponent(entity).squares; + occupied.AddRange(entitySquares); + } + return occupied; } public override void Update(double dt) { - var occupied = new List(); Dictionary statuses = new Dictionary(); foreach (var entity in ReadEntities()) { @@ -94,18 +109,7 @@ } if (statuses.ContainsKey(Tool.Preserve) && statuses[Tool.Preserve]) { - foreach (var (entity, status) in ReadEntities() - .WhereF((e) => HasComponent(e)) - .SelectWhereF((e) => (e, GetComponent(e)), - (e) => ((e.Item2.status != ContractStatus.Broken) - && (e.Item2.status != ContractStatus.Rejected) - && (e.Item2.status != ContractStatus.Expired) - && (e.Item2.status != ContractStatus.Completed) - && (e.Item2.status != ContractStatus.Proposed)) - )) { - var entitySquares = GetComponent(entity).squares; - occupied.AddRange(entitySquares); - } + var occupied = GetOccupied(); foreach (var entity in ReadEntities() .WhereF((e) => HasComponent(e))) { var entitySquares = GetComponent(entity).squares; @@ -154,8 +158,7 @@ } } } - - SetComponent(entity, new AreaComponent { squares = newSquares.ToArray() /*new[]{ area.squares[0], message.End}*/, Tool = area.Tool}); + SetComponent(entity, new AreaComponent { squares = newSquares.ToArray(), Tool = area.Tool}); } } } @@ -198,9 +201,7 @@ foreach (var i in step_until(area.squares[0].X, end_x)) { foreach (var j in step_until(area.squares[0].Y, end_y)) { var newSquare = new Vector2(i, j); - if (!occupied.Contains(newSquare)) { - newSquares.Add(newSquare); - } + newSquares.Add(newSquare); } } SetComponent(entity, new AreaComponent { squares = newSquares.ToArray(), Tool = area.Tool}); @@ -222,18 +223,7 @@ } } - foreach (var (entity, status) in ReadEntities() - .WhereF((e) => HasComponent(e)) - .SelectWhereF((e) => (e, GetComponent(e)), - (e) => ((e.Item2.status != ContractStatus.Broken) - && (e.Item2.status != ContractStatus.Rejected) - && (e.Item2.status != ContractStatus.Expired) - && (e.Item2.status != ContractStatus.Completed) - && (e.Item2.status != ContractStatus.Proposed)) - )) { - var entitySquares = GetComponent(entity).squares; - occupied.AddRange(entitySquares); - } + var occupied = GetOccupied(); foreach (var (entity, point) in ReadEntities() .WhereF((e) => HasComponent(e)) @@ -277,13 +267,9 @@ Tool = point.Tool}); } } - } - } - } } } } -