Show More
Commit Description:
Add tool selection button.
Commit Description:
Add tool selection button.
Show/Diff file:
Action:
isometric-park-fna/Engines/BuildToolEngine.cs
119 lines | 4.9 KiB | text/x-csharp | CSharpLexer
Draw areas when clicked.
r536 using System;
Extend ranges properly.
r537 using System.Linq;
using System.Collections.Generic;
Draw areas when clicked.
r536 using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Encompass;
Prevent overlapping preserves with contracts and other preserves.
r540 using JM.LinqFaster;
Draw areas when clicked.
r536
using isometricparkfna.Messages;
using isometricparkfna.Components;
namespace isometricparkfna.Engines {
[Receives(typeof(SpawnSelection),
Limit to boundaries.
r538 typeof(AdjustSelection))]
Allow finalizing preserve areas.
r539 [Writes(typeof(AreaComponent),
// typeof(SelectedComponent),
typeof(PreserveComponent))]
Extend ranges properly.
r537 [Reads(typeof(SelectedComponent),
Fix style and ensure preserve renders in red.
r542 typeof(ContractStatusComponent),
Prevent overlapping preserves with contracts and other preserves.
r540 typeof(AreaComponent),
typeof(PreserveComponent))]
Draw areas when clicked.
r536 public class BuildToolEngine : Engine {
Extend ranges properly.
r537
Limit to boundaries.
r538 private CellMap Map;
public BuildToolEngine(CellMap map) {
this.Map = map;
}
Extend ranges properly.
r537 private System.Collections.Generic.IEnumerable<float> step_until(float start, float stop) {
if (stop >= start) {
for(float i = start; i <= stop; i++)
{
yield return i;
}
}
else {
for(float i = start; i >= stop; i--)
{
yield return i;
}
}
}
Draw areas when clicked.
r536 public override void Update(double dt) {
Prevent overlapping preserves with contracts and other preserves.
r540 var occupied = new List<Vector2>();
foreach (var (entity, status) in ReadEntities<AreaComponent>()
Fix style and ensure preserve renders in red.
r542 .WhereF((e) => HasComponent<ContractStatusComponent>(e))
.SelectWhereF((e) => (e, GetComponent<ContractStatusComponent>(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))
)) {
Prevent overlapping preserves with contracts and other preserves.
r540 var entitySquares = GetComponent<AreaComponent>(entity).squares;
occupied.AddRange(entitySquares);
}
foreach (var entity in ReadEntities<AreaComponent>()
Fix style and ensure preserve renders in red.
r542 .WhereF((e) => HasComponent<PreserveComponent>(e))) {
Prevent overlapping preserves with contracts and other preserves.
r540 var entitySquares = GetComponent<AreaComponent>(entity).squares;
occupied.AddRange(entitySquares);
}
Draw areas when clicked.
r536
foreach (ref readonly var message in ReadMessages<SpawnSelection>())
{
Allow finalizing preserve areas.
r539 if (message.Start.X >= 0 && message.Start.X < this.Map.MapWidth
&& message.Start.Y >= 0 && message.Start.Y < this.Map.MapHeight) {
Fix style and ensure preserve renders in red.
r542 var entity = CreateEntity();
Draw areas when clicked.
r536
Fix style and ensure preserve renders in red.
r542 AddComponent(entity, new AreaComponent { squares = new[] {message.Start} });
Add tool selection button.
r543 AddComponent(entity, new SelectedComponent { selected = true, Type= SelectionType.Area});
Allow finalizing preserve areas.
r539 }
Draw areas when clicked.
r536 }
Extend ranges properly.
r537
Allow finalizing preserve areas.
r539 foreach (ref readonly var message in ReadMessages<AdjustSelection>()) {
foreach (ref readonly var entity in ReadEntities<SelectedComponent>()) {
Extend ranges properly.
r537 var selection = GetComponent<SelectedComponent>(entity);
Add tool selection button.
r543 if(selection.Type == SelectionType.Area
Allow finalizing preserve areas.
r539 && selection.selected) {
if(message.Type == AdjustmentType.Clear) {
Extend ranges properly.
r537 Destroy(entity);
}
Allow finalizing preserve areas.
r539 else if(message.Type == AdjustmentType.Complete) {
SetComponent(entity, new PreserveComponent {});
// SetComponent(entity, new SelectedComponent {selected = false });
}
Extend ranges properly.
r537 else {
var area = GetComponent<AreaComponent>(entity);
var newSquares = new List<Vector2>();
Limit to boundaries.
r538 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);
Draw areas when clicked.
r536
Limit to boundaries.
r538 foreach (var i in step_until(area.squares[0].X, end_x)) {
foreach (var j in step_until(area.squares[0].Y, end_y)) {
Prevent overlapping preserves with contracts and other preserves.
r540 var newSquare = new Vector2(i, j);
if (!occupied.Contains(newSquare)) {
newSquares.Add(newSquare);
}
Extend ranges properly.
r537 }
}
SetComponent(entity, new AreaComponent { squares = newSquares.ToArray() /*( new[]{ area.squares[0], message.End}*/});
Limit to boundaries.
r538 }
}
}
Extend ranges properly.
r537
Limit to boundaries.
r538 }
}
}
}
Extend ranges properly.
r537