Content changes for SetTiles change (#37229)
* Content changes for SetTiles change * Retest with new engine changes * Derp * Update for new engine PR changes
This commit is contained in:
@@ -233,65 +233,66 @@ public sealed partial class ExplosionSystem
|
||||
/// </summary>
|
||||
private void OnTileChanged(ref TileChangedEvent ev)
|
||||
{
|
||||
// only need to update the grid-edge map if a tile was added or removed from the grid.
|
||||
if (!ev.NewTile.Tile.IsEmpty && !ev.OldTile.IsEmpty)
|
||||
return;
|
||||
|
||||
if (!TryComp(ev.Entity, out MapGridComponent? grid))
|
||||
return;
|
||||
|
||||
var tileRef = ev.NewTile;
|
||||
|
||||
if (!_gridEdges.TryGetValue(tileRef.GridUid, out var edges))
|
||||
foreach (var change in ev.Changes)
|
||||
{
|
||||
edges = new();
|
||||
_gridEdges[tileRef.GridUid] = edges;
|
||||
}
|
||||
// only need to update the grid-edge map if a tile was added or removed from the grid.
|
||||
if (!change.NewTile.IsEmpty && !change.OldTile.IsEmpty)
|
||||
return;
|
||||
|
||||
if (tileRef.Tile.IsEmpty)
|
||||
{
|
||||
// if the tile is empty, it cannot itself be an edge tile.
|
||||
edges.Remove(tileRef.GridIndices);
|
||||
if (!TryComp(ev.Entity, out MapGridComponent? grid))
|
||||
return;
|
||||
|
||||
// add any valid neighbours to the list of edge-tiles
|
||||
if (!_gridEdges.TryGetValue(ev.Entity, out var edges))
|
||||
{
|
||||
edges = new();
|
||||
_gridEdges[ev.Entity] = edges;
|
||||
}
|
||||
|
||||
if (change.NewTile.IsEmpty)
|
||||
{
|
||||
// if the tile is empty, it cannot itself be an edge tile.
|
||||
edges.Remove(change.GridIndices);
|
||||
|
||||
// add any valid neighbours to the list of edge-tiles
|
||||
for (var i = 0; i < NeighbourVectors.Length; i++)
|
||||
{
|
||||
var neighbourIndex = change.GridIndices + NeighbourVectors[i];
|
||||
|
||||
if (_mapSystem.TryGetTileRef(ev.Entity, grid, neighbourIndex, out var neighbourTile) && !neighbourTile.Tile.IsEmpty)
|
||||
{
|
||||
var oppositeDirection = (NeighborFlag)(1 << ((i + 4) % 8));
|
||||
edges[neighbourIndex] = edges.GetValueOrDefault(neighbourIndex) | oppositeDirection;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// the tile is not empty space, but was previously. So update directly adjacent neighbours, which may no longer
|
||||
// be edge tiles.
|
||||
for (var i = 0; i < NeighbourVectors.Length; i++)
|
||||
{
|
||||
var neighbourIndex = tileRef.GridIndices + NeighbourVectors[i];
|
||||
var neighbourIndex = change.GridIndices + NeighbourVectors[i];
|
||||
|
||||
if (_mapSystem.TryGetTileRef(ev.Entity, grid, neighbourIndex, out var neighbourTile) && !neighbourTile.Tile.IsEmpty)
|
||||
if (edges.TryGetValue(neighbourIndex, out var neighborSpaceDir))
|
||||
{
|
||||
var oppositeDirection = (NeighborFlag) (1 << ((i + 4) % 8));
|
||||
edges[neighbourIndex] = edges.GetValueOrDefault(neighbourIndex) | oppositeDirection;
|
||||
var oppositeDirection = (NeighborFlag)(1 << ((i + 4) % 8));
|
||||
neighborSpaceDir &= ~oppositeDirection;
|
||||
if (neighborSpaceDir == NeighborFlag.Invalid)
|
||||
{
|
||||
// no longer an edge tile
|
||||
edges.Remove(neighbourIndex);
|
||||
continue;
|
||||
}
|
||||
|
||||
edges[neighbourIndex] = neighborSpaceDir;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
// finally check if the new tile is itself an edge tile
|
||||
if (IsEdge(grid, change.GridIndices, out var spaceDir))
|
||||
edges.Add(change.GridIndices, spaceDir);
|
||||
}
|
||||
|
||||
// the tile is not empty space, but was previously. So update directly adjacent neighbours, which may no longer
|
||||
// be edge tiles.
|
||||
for (var i = 0; i < NeighbourVectors.Length; i++)
|
||||
{
|
||||
var neighbourIndex = tileRef.GridIndices + NeighbourVectors[i];
|
||||
|
||||
if (edges.TryGetValue(neighbourIndex, out var neighborSpaceDir))
|
||||
{
|
||||
var oppositeDirection = (NeighborFlag) (1 << ((i + 4) % 8));
|
||||
neighborSpaceDir &= ~oppositeDirection;
|
||||
if (neighborSpaceDir == NeighborFlag.Invalid)
|
||||
{
|
||||
// no longer an edge tile
|
||||
edges.Remove(neighbourIndex);
|
||||
continue;
|
||||
}
|
||||
|
||||
edges[neighbourIndex] = neighborSpaceDir;
|
||||
}
|
||||
}
|
||||
|
||||
// finally check if the new tile is itself an edge tile
|
||||
if (IsEdge(grid, tileRef.GridIndices, out var spaceDir))
|
||||
edges.Add(tileRef.GridIndices, spaceDir);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user