Skip to content

Commit

Permalink
fixed bug that ChangeState would assume standard value for unchanged …
Browse files Browse the repository at this point in the history
…fields instead of falling back on parent
  • Loading branch information
sirati committed Oct 13, 2019
1 parent ebb5102 commit eac2473
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 11 additions & 2 deletions ProgressionCore/World/ChangeState/RectChangeState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ public RectChangeState(ITileWorld parent, Rect affectedRect, IFeatureResolver ap
AffectedRect = affectedRect;
ApplicableFeatures = applicableFeatures;
_data = new int[affectedRect.Height,affectedRect.Width];
_changed = new bool[affectedRect.Height,affectedRect.Width];

}

public Rect AffectedRect { get; }
public IFeatureResolver ApplicableFeatures { get; }
private int[,] _data;
private bool[,] _changed;


protected override Coordinate transform(Coordinate coord)
Expand All @@ -28,14 +31,20 @@ protected override bool IsContained(Coordinate coord, DataIdentifier identifier)
return identifier.Resolver == ApplicableFeatures && AffectedRect.IsInside(coord.X, coord.Y);
}

protected override bool IsChanged(Coordinate t, DataIdentifier identifier)
{
return identifier.Resolver == ApplicableFeatures && _changed[t.X, t.Y];
}

protected override int getChange(Coordinate transCoord)
{
return _data[transCoord.X, transCoord.Y];
}

protected override void setChange(Coordinate transCoord, int v)
protected override void setChange(Coordinate t, int v)
{
_data[transCoord.X, transCoord.Y] = v;
_data[t.X, t.Y] = v;
_changed[t.X, t.Y] = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ protected TransformableChangeStateBase(ITileWorld parent) : base(parent) { }

protected abstract Coordinate transform(Coordinate coord);
protected abstract bool IsContained(Coordinate coord, DataIdentifier identifier);
protected abstract bool IsChanged(Coordinate transCoord, DataIdentifier identifier);
protected abstract int getChange(Coordinate transCoord);
protected abstract void setChange(Coordinate transCoord, int v);
protected abstract void setChange(Coordinate t, int v);



public override int this[Coordinate c, DataIdentifier i] {
get => IsContained(c, i) ? getChange(transform(c)) : Parent[c, i];
get {
Coordinate t;
return IsContained(c, i) && IsChanged(t= transform(c), i) ? getChange(t) : Parent[c, i]; }

set {
if (IsContained(c, i)) {
setChange(transform(c), value);
Expand Down

0 comments on commit eac2473

Please sign in to comment.