Update SharedBiomeSystem methods to use Entity<T> (#37698)
* Fix warning in TryGetBiomeTile * Overload TryGetBiomeTile * Overload more methods, fix internal warnings * Update TryGetEntity uses * Update TryGetTile uses * Cleanup TryGetDecals use * Formatting * Two more warnings while we're here
This commit is contained in:
@@ -58,13 +58,13 @@ public sealed class BiomeDebugOverlay : Overlay
|
||||
var sb = new StringBuilder();
|
||||
var nodePos = _maps.WorldToTile(mapUid, grid, mousePos.Position);
|
||||
|
||||
if (_biomes.TryGetEntity(nodePos, biomeComp, grid, out var ent))
|
||||
if (_biomes.TryGetEntity(nodePos, biomeComp, (mapUid, grid), out var ent))
|
||||
{
|
||||
var text = $"Entity: {ent}";
|
||||
sb.AppendLine(text);
|
||||
}
|
||||
|
||||
if (_biomes.TryGetDecals(nodePos, biomeComp.Layers, biomeComp.Seed, grid, out var decals))
|
||||
if (_biomes.TryGetDecals(nodePos, biomeComp.Layers, biomeComp.Seed, (mapUid, grid), out var decals))
|
||||
{
|
||||
var text = $"Decals: {decals.Count}";
|
||||
sb.AppendLine(text);
|
||||
@@ -76,7 +76,7 @@ public sealed class BiomeDebugOverlay : Overlay
|
||||
}
|
||||
}
|
||||
|
||||
if (_biomes.TryGetBiomeTile(nodePos, biomeComp.Layers, biomeComp.Seed, grid, out var tile))
|
||||
if (_biomes.TryGetBiomeTile(nodePos, biomeComp.Layers, biomeComp.Seed, (mapUid, grid), out var tile))
|
||||
{
|
||||
var tileText = $"Tile: {_tileDefManager[tile.Value.TypeId].ID}";
|
||||
sb.AppendLine(tileText);
|
||||
|
||||
@@ -257,7 +257,7 @@ public sealed partial class BiomeSystem : SharedBiomeSystem
|
||||
private void OnFTLStarted(ref FTLStartedEvent ev)
|
||||
{
|
||||
var targetMap = _transform.ToMapCoordinates(ev.TargetCoordinates);
|
||||
var targetMapUid = _mapManager.GetMapEntityId(targetMap.MapId);
|
||||
var targetMapUid = _mapSystem.GetMapOrInvalid(targetMap.MapId);
|
||||
|
||||
if (!TryComp<BiomeComponent>(targetMapUid, out var biome))
|
||||
return;
|
||||
@@ -288,7 +288,7 @@ public sealed partial class BiomeSystem : SharedBiomeSystem
|
||||
|
||||
var mod = biome.ModifiedTiles.GetOrNew(chunk * ChunkSize);
|
||||
|
||||
if (!mod.Add(index) || !TryGetBiomeTile(index, biome.Layers, biome.Seed, grid, out var tile))
|
||||
if (!mod.Add(index) || !TryGetBiomeTile(index, biome.Layers, biome.Seed, (ev.MapUid, grid), out var tile))
|
||||
continue;
|
||||
|
||||
// If we flag it as modified then the tile is never set so need to do it ourselves.
|
||||
@@ -607,7 +607,7 @@ public sealed partial class BiomeSystem : SharedBiomeSystem
|
||||
continue;
|
||||
|
||||
// Check if mask matches // anything blocking.
|
||||
TryGetEntity(node, biome, grid, out var proto);
|
||||
TryGetEntity(node, biome, (gridUid, grid), out var proto);
|
||||
|
||||
// If there's an existing entity and it doesn't match the mask then skip.
|
||||
if (layerProto.EntityMask.Count > 0 &&
|
||||
@@ -727,14 +727,14 @@ public sealed partial class BiomeSystem : SharedBiomeSystem
|
||||
continue;
|
||||
|
||||
// Need to ensure the tile under it has loaded for anchoring.
|
||||
if (TryGetBiomeTile(node, component.Layers, seed, grid, out var tile))
|
||||
if (TryGetBiomeTile(node, component.Layers, seed, (gridUid, grid), out var tile))
|
||||
{
|
||||
_mapSystem.SetTile(gridUid, grid, node, tile.Value);
|
||||
}
|
||||
|
||||
string? prototype;
|
||||
|
||||
if (TryGetEntity(node, component, grid, out var proto) &&
|
||||
if (TryGetEntity(node, component, (gridUid, grid), out var proto) &&
|
||||
layerProto.EntityMask.TryGetValue(proto, out var maskedProto))
|
||||
{
|
||||
prototype = maskedProto;
|
||||
@@ -793,7 +793,7 @@ public sealed partial class BiomeSystem : SharedBiomeSystem
|
||||
if (_mapSystem.TryGetTileRef(gridUid, grid, indices, out var tileRef) && !tileRef.Tile.IsEmpty)
|
||||
continue;
|
||||
|
||||
if (!TryGetBiomeTile(indices, component.Layers, seed, grid, out var biomeTile))
|
||||
if (!TryGetBiomeTile(indices, component.Layers, seed, (gridUid, grid), out var biomeTile))
|
||||
continue;
|
||||
|
||||
_tiles.Add((indices, biomeTile.Value));
|
||||
@@ -819,7 +819,7 @@ public sealed partial class BiomeSystem : SharedBiomeSystem
|
||||
// Don't mess with anything that's potentially anchored.
|
||||
var anchored = _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, indices);
|
||||
|
||||
if (anchored.MoveNext(out _) || !TryGetEntity(indices, component, grid, out var entPrototype))
|
||||
if (anchored.MoveNext(out _) || !TryGetEntity(indices, component, (gridUid, grid), out var entPrototype))
|
||||
continue;
|
||||
|
||||
// TODO: Fix non-anchored ents spawning.
|
||||
@@ -852,7 +852,7 @@ public sealed partial class BiomeSystem : SharedBiomeSystem
|
||||
// Don't mess with anything that's potentially anchored.
|
||||
var anchored = _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, indices);
|
||||
|
||||
if (anchored.MoveNext(out _) || !TryGetDecals(indices, component.Layers, seed, grid, out var decals))
|
||||
if (anchored.MoveNext(out _) || !TryGetDecals(indices, component.Layers, seed, (gridUid, grid), out var decals))
|
||||
continue;
|
||||
|
||||
foreach (var decal in decals)
|
||||
@@ -966,7 +966,7 @@ public sealed partial class BiomeSystem : SharedBiomeSystem
|
||||
continue;
|
||||
|
||||
// Don't mess with anything that's potentially anchored.
|
||||
var anchored = grid.GetAnchoredEntitiesEnumerator(indices);
|
||||
var anchored = _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, indices);
|
||||
|
||||
if (anchored.MoveNext(out _))
|
||||
{
|
||||
@@ -1070,7 +1070,7 @@ public sealed partial class BiomeSystem : SharedBiomeSystem
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!TryGetBiomeTile(tileSet.GridIndices, biome.Layers, biome.Seed, mapGrid, out var tile))
|
||||
if (!TryGetBiomeTile(tileSet.GridIndices, biome.Layers, biome.Seed, (mapUid, mapGrid), out var tile))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -39,12 +39,12 @@ public sealed partial class DungeonJob
|
||||
}
|
||||
|
||||
// Need to set per-tile to override data.
|
||||
if (biomeSystem.TryGetTile(node, indexedBiome.Layers, seed, _grid, out var tile))
|
||||
if (biomeSystem.TryGetTile(node, indexedBiome.Layers, seed, (_gridUid, _grid), out var tile))
|
||||
{
|
||||
_maps.SetTile(_gridUid, _grid, node, tile.Value);
|
||||
}
|
||||
|
||||
if (biomeSystem.TryGetDecals(node, indexedBiome.Layers, seed, _grid, out var decals))
|
||||
if (biomeSystem.TryGetDecals(node, indexedBiome.Layers, seed, (_gridUid, _grid), out var decals))
|
||||
{
|
||||
foreach (var decal in decals)
|
||||
{
|
||||
@@ -52,7 +52,7 @@ public sealed partial class DungeonJob
|
||||
}
|
||||
}
|
||||
|
||||
if (biomeSystem.TryGetEntity(node, indexedBiome.Layers, tile ?? tileRef.Value.Tile, seed, _grid, out var entityProto))
|
||||
if (biomeSystem.TryGetEntity(node, indexedBiome.Layers, tile ?? tileRef.Value.Tile, seed, (_gridUid, _grid), out var entityProto))
|
||||
{
|
||||
var ent = _entManager.SpawnEntity(entityProto, new EntityCoordinates(_gridUid, node + _grid.TileSizeHalfVector));
|
||||
var xform = xformQuery.Get(ent);
|
||||
|
||||
@@ -17,6 +17,7 @@ public abstract class SharedBiomeSystem : EntitySystem
|
||||
[Dependency] private readonly ISerializationManager _serManager = default!;
|
||||
[Dependency] protected readonly ITileDefinitionManager TileDefManager = default!;
|
||||
[Dependency] private readonly TileSystem _tile = default!;
|
||||
[Dependency] private readonly SharedMapSystem _map = default!;
|
||||
|
||||
protected const byte ChunkSize = 8;
|
||||
|
||||
@@ -69,7 +70,7 @@ public abstract class SharedBiomeSystem : EntitySystem
|
||||
|
||||
public bool TryGetBiomeTile(EntityUid uid, MapGridComponent grid, Vector2i indices, [NotNullWhen(true)] out Tile? tile)
|
||||
{
|
||||
if (grid.TryGetTileRef(indices, out var tileRef) && !tileRef.Tile.IsEmpty)
|
||||
if (_map.TryGetTileRef(uid, grid, indices, out var tileRef) && !tileRef.Tile.IsEmpty)
|
||||
{
|
||||
tile = tileRef.Tile;
|
||||
return true;
|
||||
@@ -81,15 +82,15 @@ public abstract class SharedBiomeSystem : EntitySystem
|
||||
return false;
|
||||
}
|
||||
|
||||
return TryGetBiomeTile(indices, biome.Layers, biome.Seed, grid, out tile);
|
||||
return TryGetBiomeTile(indices, biome.Layers, biome.Seed, (uid, grid), out tile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the tile, real or otherwise, for the specified indices.
|
||||
/// </summary>
|
||||
public bool TryGetBiomeTile(Vector2i indices, List<IBiomeLayer> layers, int seed, MapGridComponent? grid, [NotNullWhen(true)] out Tile? tile)
|
||||
public bool TryGetBiomeTile(Vector2i indices, List<IBiomeLayer> layers, int seed, Entity<MapGridComponent>? grid, [NotNullWhen(true)] out Tile? tile)
|
||||
{
|
||||
if (grid?.TryGetTileRef(indices, out var tileRef) == true && !tileRef.Tile.IsEmpty)
|
||||
if (grid is { } gridEnt && _map.TryGetTileRef(gridEnt, gridEnt.Comp, indices, out var tileRef) && !tileRef.Tile.IsEmpty)
|
||||
{
|
||||
tile = tileRef.Tile;
|
||||
return true;
|
||||
@@ -98,10 +99,19 @@ public abstract class SharedBiomeSystem : EntitySystem
|
||||
return TryGetTile(indices, layers, seed, grid, out tile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the tile, real or otherwise, for the specified indices.
|
||||
/// </summary>
|
||||
[Obsolete("Use the Entity<MapGridComponent>? overload")]
|
||||
public bool TryGetBiomeTile(Vector2i indices, List<IBiomeLayer> layers, int seed, MapGridComponent? grid, [NotNullWhen(true)] out Tile? tile)
|
||||
{
|
||||
return TryGetBiomeTile(indices, layers, seed, grid == null ? null : (grid.Owner, grid), out tile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the underlying biome tile, ignoring any existing tile that may be there.
|
||||
/// </summary>
|
||||
public bool TryGetTile(Vector2i indices, List<IBiomeLayer> layers, int seed, MapGridComponent? grid, [NotNullWhen(true)] out Tile? tile)
|
||||
public bool TryGetTile(Vector2i indices, List<IBiomeLayer> layers, int seed, Entity<MapGridComponent>? grid, [NotNullWhen(true)] out Tile? tile)
|
||||
{
|
||||
for (var i = layers.Count - 1; i >= 0; i--)
|
||||
{
|
||||
@@ -139,6 +149,15 @@ public abstract class SharedBiomeSystem : EntitySystem
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the underlying biome tile, ignoring any existing tile that may be there.
|
||||
/// </summary>
|
||||
[Obsolete("Use the Entity<MapGridComponent>? overload")]
|
||||
public bool TryGetTile(Vector2i indices, List<IBiomeLayer> layers, int seed, MapGridComponent? grid, [NotNullWhen(true)] out Tile? tile)
|
||||
{
|
||||
return TryGetTile(indices, layers, seed, grid == null ? null : (grid.Owner, grid), out tile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the underlying biome tile, ignoring any existing tile that may be there.
|
||||
/// </summary>
|
||||
@@ -170,7 +189,7 @@ public abstract class SharedBiomeSystem : EntitySystem
|
||||
/// <summary>
|
||||
/// Tries to get the relevant entity for this tile.
|
||||
/// </summary>
|
||||
public bool TryGetEntity(Vector2i indices, BiomeComponent component, MapGridComponent grid,
|
||||
public bool TryGetEntity(Vector2i indices, BiomeComponent component, Entity<MapGridComponent>? grid,
|
||||
[NotNullWhen(true)] out string? entity)
|
||||
{
|
||||
if (!TryGetBiomeTile(indices, component.Layers, component.Seed, grid, out var tile))
|
||||
@@ -182,8 +201,17 @@ public abstract class SharedBiomeSystem : EntitySystem
|
||||
return TryGetEntity(indices, component.Layers, tile.Value, component.Seed, grid, out entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the relevant entity for this tile.
|
||||
/// </summary>
|
||||
[Obsolete("Use the Entity<MapGridComponent>? overload")]
|
||||
public bool TryGetEntity(Vector2i indices, BiomeComponent component, MapGridComponent grid,
|
||||
[NotNullWhen(true)] out string? entity)
|
||||
{
|
||||
return TryGetEntity(indices, component, grid == null ? null : (grid.Owner, grid), out entity);
|
||||
}
|
||||
|
||||
public bool TryGetEntity(Vector2i indices, List<IBiomeLayer> layers, Tile tileRef, int seed, MapGridComponent grid,
|
||||
public bool TryGetEntity(Vector2i indices, List<IBiomeLayer> layers, Tile tileRef, int seed, Entity<MapGridComponent>? grid,
|
||||
[NotNullWhen(true)] out string? entity)
|
||||
{
|
||||
var tileId = TileDefManager[tileRef.TypeId].ID;
|
||||
@@ -242,10 +270,17 @@ public abstract class SharedBiomeSystem : EntitySystem
|
||||
return false;
|
||||
}
|
||||
|
||||
[Obsolete("Use the Entity<MapGridComponent>? overload")]
|
||||
public bool TryGetEntity(Vector2i indices, List<IBiomeLayer> layers, Tile tileRef, int seed, MapGridComponent grid,
|
||||
[NotNullWhen(true)] out string? entity)
|
||||
{
|
||||
return TryGetEntity(indices, layers, tileRef, seed, grid == null ? null : (grid.Owner, grid), out entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the relevant decals for this tile.
|
||||
/// </summary>
|
||||
public bool TryGetDecals(Vector2i indices, List<IBiomeLayer> layers, int seed, MapGridComponent grid,
|
||||
public bool TryGetDecals(Vector2i indices, List<IBiomeLayer> layers, int seed, Entity<MapGridComponent>? grid,
|
||||
[NotNullWhen(true)] out List<(string ID, Vector2 Position)>? decals)
|
||||
{
|
||||
if (!TryGetBiomeTile(indices, layers, seed, grid, out var tileRef))
|
||||
@@ -329,6 +364,16 @@ public abstract class SharedBiomeSystem : EntitySystem
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the relevant decals for this tile.
|
||||
/// </summary>
|
||||
[Obsolete("Use the Entity<MapGridComponent>? overload")]
|
||||
public bool TryGetDecals(Vector2i indices, List<IBiomeLayer> layers, int seed, MapGridComponent grid,
|
||||
[NotNullWhen(true)] out List<(string ID, Vector2 Position)>? decals)
|
||||
{
|
||||
return TryGetDecals(indices, layers, seed, grid == null ? null : (grid.Owner, grid), out decals);
|
||||
}
|
||||
|
||||
private FastNoiseLite GetNoise(FastNoiseLite seedNoise, int seed)
|
||||
{
|
||||
var noiseCopy = new FastNoiseLite();
|
||||
|
||||
Reference in New Issue
Block a user