Skip to content

Commit

Permalink
Sort tiles when added/removed
Browse files Browse the repository at this point in the history
  • Loading branch information
kaczy93 committed Oct 2, 2024
1 parent 1ab2ea2 commit b6f6bea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CentrED/Map/MapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ public MapManager(GraphicsDevice gd)
Client.StaticTileElevated += (tile, newZ) =>
{
GetTile(tile)?.UpdatePos(tile.X, tile.Y, newZ);
StaticTiles?[tile.X, tile.Y]?.Sort();
};
Client.AfterStaticChanged += tile =>
{
Expand Down Expand Up @@ -446,6 +447,7 @@ public void MoveTile(StaticTile staticTile, ushort newX, ushort newY)
StaticTiles[newX, newY] = newList;
}
newList.Add(found);
newList.Sort();
}
}

Expand All @@ -469,6 +471,7 @@ public void AddTile(StaticTile staticTile)
StaticTiles[x, y] = list;
}
list.Add(so);
list.Sort();
AllTiles.Add(so.ObjectId, so);
StaticTilesCount++;
if (so.IsAnimated)
Expand All @@ -492,6 +495,7 @@ public void RemoveTile(StaticTile staticTile)
if (found != null)
{
list.Remove(found);
list.Sort();
AllTiles.Remove(found.ObjectId);
if (found.IsAnimated)
{
Expand Down
15 changes: 14 additions & 1 deletion CentrED/Map/StaticObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace CentrED.Map;

public class StaticObject : TileObject
public class StaticObject : TileObject, IComparable<StaticObject>
{
public StaticTile StaticTile;
public bool IsAnimated;
Expand Down Expand Up @@ -135,4 +135,17 @@ public float Alpha
}
}
}

public int CompareTo(StaticObject? other)
{
if (ReferenceEquals(this, other))
{
return 0;
}
if (other is null)
{
return 1;
}
return StaticTile.PriorityZ.CompareTo(other.StaticTile.PriorityZ);
}
}

0 comments on commit b6f6bea

Please sign in to comment.