From 094cbcd6703f882b93a735ec8b2a417e4436147c Mon Sep 17 00:00:00 2001 From: MilenVolf <63782763+milenvolf@users.noreply.github.com> Date: Sun, 29 Sep 2024 02:27:47 +0300 Subject: [PATCH] Replace obsolete Tile Access methods (#32508) * Replace obsolete SetTile * Remove obsolete GetTileRef & GetAllTiles * Forgor * Apply suggested `GetMapOrInvalid` (cherry picked from commit 1b9d77a76078668ceb15acebf777fae05167ea83) --- .../EntitySystems/ExplosionSystem.Processing.cs | 7 +++++-- .../Explosion/EntitySystems/ExplosionSystem.cs | 3 ++- Content.Server/ImmovableRod/ImmovableRodSystem.cs | 3 ++- Content.Server/Parallax/BiomeSystem.cs | 2 +- .../Pointing/EntitySystems/PointingSystem.cs | 14 ++++++++++---- .../Power/EntitySystems/CableSystem.Placer.cs | 7 +++++-- .../Procedural/DungeonSystem.Commands.cs | 12 +++++------- .../Systems/Debris/BlobFloorPlanBuilderSystem.cs | 7 ++++--- .../Debris/SimpleFloorPlanPopulatorSystem.cs | 3 ++- Content.Shared/Friction/TileFrictionController.cs | 3 ++- Content.Shared/Sound/SharedEmitSoundSystem.cs | 3 ++- Content.Shared/Tiles/FloorTileSystem.cs | 5 +++-- 12 files changed, 43 insertions(+), 26 deletions(-) diff --git a/Content.Server/Explosion/EntitySystems/ExplosionSystem.Processing.cs b/Content.Server/Explosion/EntitySystems/ExplosionSystem.Processing.cs index 369111b31b..e0d82e8f04 100644 --- a/Content.Server/Explosion/EntitySystems/ExplosionSystem.Processing.cs +++ b/Content.Server/Explosion/EntitySystems/ExplosionSystem.Processing.cs @@ -666,6 +666,7 @@ sealed class Explosion private readonly IEntityManager _entMan; private readonly ExplosionSystem _system; + private readonly SharedMapSystem _mapSystem; public readonly EntityUid VisualEnt; @@ -688,11 +689,13 @@ sealed class Explosion IEntityManager entMan, IMapManager mapMan, EntityUid visualEnt, - EntityUid? cause) + EntityUid? cause, + SharedMapSystem mapSystem) { VisualEnt = visualEnt; Cause = cause; _system = system; + _mapSystem = mapSystem; ExplosionType = explosionType; _tileSetIntensity = tileSetIntensity; Epicenter = epicenter; @@ -899,7 +902,7 @@ sealed class Explosion { if (list.Count > 0 && _entMan.EntityExists(grid.Owner)) { - grid.SetTiles(list); + _mapSystem.SetTiles(grid.Owner, grid, list); } } _tileUpdateDict.Clear(); diff --git a/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs b/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs index 0cc7be39a3..16a34c9d3e 100644 --- a/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs +++ b/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs @@ -400,7 +400,8 @@ public sealed partial class ExplosionSystem : SharedExplosionSystem EntityManager, _mapManager, visualEnt, - queued.Cause); + queued.Cause, + _map); } private void CameraShake(float range, MapCoordinates epicenter, float totalIntensity) diff --git a/Content.Server/ImmovableRod/ImmovableRodSystem.cs b/Content.Server/ImmovableRod/ImmovableRodSystem.cs index f9873b0d6a..0d3d69c1bc 100644 --- a/Content.Server/ImmovableRod/ImmovableRodSystem.cs +++ b/Content.Server/ImmovableRod/ImmovableRodSystem.cs @@ -25,6 +25,7 @@ public sealed class ImmovableRodSystem : EntitySystem [Dependency] private readonly SharedAudioSystem _audio = default!; [Dependency] private readonly DamageableSystem _damageable = default!; [Dependency] private readonly SharedTransformSystem _transform = default!; + [Dependency] private readonly SharedMapSystem _map = default!; public override void Update(float frameTime) { @@ -39,7 +40,7 @@ public sealed class ImmovableRodSystem : EntitySystem if (!TryComp(trans.GridUid, out var grid)) continue; - grid.SetTile(trans.Coordinates, Tile.Empty); + _map.SetTile(trans.GridUid.Value, grid, trans.Coordinates, Tile.Empty); } } diff --git a/Content.Server/Parallax/BiomeSystem.cs b/Content.Server/Parallax/BiomeSystem.cs index 88635ccae0..8c4022a065 100644 --- a/Content.Server/Parallax/BiomeSystem.cs +++ b/Content.Server/Parallax/BiomeSystem.cs @@ -974,7 +974,7 @@ public sealed partial class BiomeSystem : SharedBiomeSystem } } - grid.SetTiles(tiles); + _mapSystem.SetTiles(gridUid, grid, tiles); tiles.Clear(); component.LoadedChunks.Remove(chunk); diff --git a/Content.Server/Pointing/EntitySystems/PointingSystem.cs b/Content.Server/Pointing/EntitySystems/PointingSystem.cs index d5ad1fb123..23c70d78f4 100644 --- a/Content.Server/Pointing/EntitySystems/PointingSystem.cs +++ b/Content.Server/Pointing/EntitySystems/PointingSystem.cs @@ -40,6 +40,7 @@ namespace Content.Server.Pointing.EntitySystems [Dependency] private readonly VisibilitySystem _visibilitySystem = default!; [Dependency] private readonly SharedMindSystem _minds = default!; [Dependency] private readonly SharedTransformSystem _transform = default!; + [Dependency] private readonly SharedMapSystem _map = default!; [Dependency] private readonly IAdminLogManager _adminLogger = default!; [Dependency] private readonly ExamineSystemShared _examine = default!; @@ -73,8 +74,13 @@ namespace Content.Server.Pointing.EntitySystems } // TODO: FOV - private void SendMessage(EntityUid source, IEnumerable viewers, EntityUid pointed, string selfMessage, - string viewerMessage, string? viewerPointedAtMessage = null) + private void SendMessage( + EntityUid source, + IEnumerable viewers, + EntityUid pointed, + string selfMessage, + string viewerMessage, + string? viewerPointedAtMessage = null) { var netSource = GetNetEntity(source); @@ -226,8 +232,8 @@ namespace Content.Server.Pointing.EntitySystems if (_mapManager.TryFindGridAt(mapCoordsPointed, out var gridUid, out var grid)) { - position = $"EntId={gridUid} {grid.WorldToTile(mapCoordsPointed.Position)}"; - tileRef = grid.GetTileRef(grid.WorldToTile(mapCoordsPointed.Position)); + position = $"EntId={gridUid} {_map.WorldToTile(gridUid, grid, mapCoordsPointed.Position)}"; + tileRef = _map.GetTileRef(gridUid, grid, _map.WorldToTile(gridUid, grid, mapCoordsPointed.Position)); } var tileDef = _tileDefinitionManager[tileRef?.Tile.TypeId ?? 0]; diff --git a/Content.Server/Power/EntitySystems/CableSystem.Placer.cs b/Content.Server/Power/EntitySystems/CableSystem.Placer.cs index 263d626ef5..a5cf54fae0 100644 --- a/Content.Server/Power/EntitySystems/CableSystem.Placer.cs +++ b/Content.Server/Power/EntitySystems/CableSystem.Placer.cs @@ -11,6 +11,8 @@ namespace Content.Server.Power.EntitySystems; public sealed partial class CableSystem { [Dependency] private readonly IAdminLogManager _adminLogger = default!; + [Dependency] private readonly SharedTransformSystem _transform = default!; + [Dependency] private readonly SharedMapSystem _map = default!; private void InitializeCablePlacer() { @@ -26,11 +28,12 @@ public sealed partial class CableSystem if (component.CablePrototypeId == null) return; - if(!TryComp(args.ClickLocation.GetGridUid(EntityManager), out var grid)) + if(!TryComp(_transform.GetGrid(args.ClickLocation), out var grid)) return; + var gridUid = _transform.GetGrid(args.ClickLocation)!.Value; var snapPos = grid.TileIndicesFor(args.ClickLocation); - var tileDef = (ContentTileDefinition) _tileManager[grid.GetTileRef(snapPos).Tile.TypeId]; + var tileDef = (ContentTileDefinition) _tileManager[_map.GetTileRef(gridUid, grid,snapPos).Tile.TypeId]; if (!tileDef.IsSubFloor || !tileDef.Sturdy) return; diff --git a/Content.Server/Procedural/DungeonSystem.Commands.cs b/Content.Server/Procedural/DungeonSystem.Commands.cs index 51a6a57bbe..09e881686e 100644 --- a/Content.Server/Procedural/DungeonSystem.Commands.cs +++ b/Content.Server/Procedural/DungeonSystem.Commands.cs @@ -1,8 +1,6 @@ -using System.Threading.Tasks; using Content.Server.Administration; using Content.Shared.Administration; using Content.Shared.Procedural; -using Content.Shared.Procedural.DungeonGenerators; using Robust.Shared.Console; using Robust.Shared.Map; using Robust.Shared.Map.Components; @@ -44,7 +42,7 @@ public sealed partial class DungeonSystem } var position = new Vector2i(posX, posY); - var dungeonUid = _mapManager.GetMapEntityId(mapId); + var dungeonUid = _maps.GetMapOrInvalid(mapId); if (!TryComp(dungeonUid, out var dungeonGrid)) { @@ -118,7 +116,7 @@ public sealed partial class DungeonSystem } var mapId = new MapId(mapInt); - var mapUid = _mapManager.GetMapEntityId(mapId); + var mapUid = _maps.GetMapOrInvalid(mapId); if (!_prototype.TryIndex(args[1], out var pack)) { @@ -156,7 +154,7 @@ public sealed partial class DungeonSystem } } - grid.SetTiles(tiles); + _maps.SetTiles(mapUid, grid, tiles); shell.WriteLine(Loc.GetString("cmd-dungen_pack_vis")); } @@ -174,7 +172,7 @@ public sealed partial class DungeonSystem } var mapId = new MapId(mapInt); - var mapUid = _mapManager.GetMapEntityId(mapId); + var mapUid =_maps.GetMapOrInvalid(mapId); if (!_prototype.TryIndex(args[1], out var preset)) { @@ -197,7 +195,7 @@ public sealed partial class DungeonSystem } } - grid.SetTiles(tiles); + _maps.SetTiles(mapUid, grid, tiles); shell.WriteLine(Loc.GetString("cmd-dungen_pack_vis")); } diff --git a/Content.Server/Worldgen/Systems/Debris/BlobFloorPlanBuilderSystem.cs b/Content.Server/Worldgen/Systems/Debris/BlobFloorPlanBuilderSystem.cs index a09416e593..ba0a3a7132 100644 --- a/Content.Server/Worldgen/Systems/Debris/BlobFloorPlanBuilderSystem.cs +++ b/Content.Server/Worldgen/Systems/Debris/BlobFloorPlanBuilderSystem.cs @@ -15,6 +15,7 @@ public sealed class BlobFloorPlanBuilderSystem : BaseWorldSystem [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly ITileDefinitionManager _tileDefinition = default!; [Dependency] private readonly TileSystem _tiles = default!; + [Dependency] private readonly SharedMapSystem _map = default!; /// public override void Initialize() @@ -25,10 +26,10 @@ public sealed class BlobFloorPlanBuilderSystem : BaseWorldSystem private void OnBlobFloorPlanBuilderStartup(EntityUid uid, BlobFloorPlanBuilderComponent component, ComponentStartup args) { - PlaceFloorplanTiles(component, Comp(uid)); + PlaceFloorplanTiles(uid, component, Comp(uid)); } - private void PlaceFloorplanTiles(BlobFloorPlanBuilderComponent comp, MapGridComponent grid) + private void PlaceFloorplanTiles(EntityUid gridUid, BlobFloorPlanBuilderComponent comp, MapGridComponent grid) { // NO MORE THAN TWO ALLOCATIONS THANK YOU VERY MUCH. // TODO: Just put these on a field instead then? @@ -82,7 +83,7 @@ public sealed class BlobFloorPlanBuilderSystem : BaseWorldSystem } } - grid.SetTiles(taken.Select(x => (x.Key, x.Value)).ToList()); + _map.SetTiles(gridUid, grid, taken.Select(x => (x.Key, x.Value)).ToList()); } } diff --git a/Content.Server/Worldgen/Systems/Debris/SimpleFloorPlanPopulatorSystem.cs b/Content.Server/Worldgen/Systems/Debris/SimpleFloorPlanPopulatorSystem.cs index ae1c6b5c00..a575e055ef 100644 --- a/Content.Server/Worldgen/Systems/Debris/SimpleFloorPlanPopulatorSystem.cs +++ b/Content.Server/Worldgen/Systems/Debris/SimpleFloorPlanPopulatorSystem.cs @@ -13,6 +13,7 @@ public sealed class SimpleFloorPlanPopulatorSystem : BaseWorldSystem { [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly ITileDefinitionManager _tileDefinition = default!; + [Dependency] private readonly SharedMapSystem _map = default!; /// public override void Initialize() @@ -25,7 +26,7 @@ public sealed class SimpleFloorPlanPopulatorSystem : BaseWorldSystem { var placeables = new List(4); var grid = Comp(uid); - var enumerator = grid.GetAllTilesEnumerator(); + var enumerator = _map.GetAllTilesEnumerator(uid, grid); while (enumerator.MoveNext(out var tile)) { var coords = grid.GridTileToLocal(tile.Value.GridIndices); diff --git a/Content.Shared/Friction/TileFrictionController.cs b/Content.Shared/Friction/TileFrictionController.cs index 930de07dab..eb109caa42 100644 --- a/Content.Shared/Friction/TileFrictionController.cs +++ b/Content.Shared/Friction/TileFrictionController.cs @@ -22,6 +22,7 @@ namespace Content.Shared.Friction [Dependency] private readonly SharedGravitySystem _gravity = default!; [Dependency] private readonly SharedMoverController _mover = default!; [Dependency] private readonly SharedPhysicsSystem _physics = default!; + [Dependency] private readonly SharedMapSystem _map = default!; private EntityQuery _frictionQuery; private EntityQuery _xformQuery; @@ -185,7 +186,7 @@ namespace Content.Shared.Friction : DefaultFriction; } - var tile = grid.GetTileRef(xform.Coordinates); + var tile = _map.GetTileRef(xform.GridUid.Value, grid, xform.Coordinates); // If it's a map but on an empty tile then just assume it has gravity. if (tile.Tile.IsEmpty && diff --git a/Content.Shared/Sound/SharedEmitSoundSystem.cs b/Content.Shared/Sound/SharedEmitSoundSystem.cs index 0260095e21..3e051fff31 100644 --- a/Content.Shared/Sound/SharedEmitSoundSystem.cs +++ b/Content.Shared/Sound/SharedEmitSoundSystem.cs @@ -35,6 +35,7 @@ public abstract class SharedEmitSoundSystem : EntitySystem [Dependency] private readonly SharedAmbientSoundSystem _ambient = default!; [Dependency] private readonly SharedAudioSystem _audioSystem = default!; [Dependency] protected readonly SharedPopupSystem Popup = default!; + [Dependency] private readonly SharedMapSystem _map = default!; [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!; public override void Initialize() @@ -89,7 +90,7 @@ public abstract class SharedEmitSoundSystem : EntitySystem return; } - var tile = grid.GetTileRef(xform.Coordinates); + var tile = _map.GetTileRef(xform.GridUid.Value, grid, xform.Coordinates); // Handle maps being grids (we'll still emit the sound). if (xform.GridUid != xform.MapUid && tile.IsSpace(_tileDefMan)) diff --git a/Content.Shared/Tiles/FloorTileSystem.cs b/Content.Shared/Tiles/FloorTileSystem.cs index f031292f23..3acd5051c9 100644 --- a/Content.Shared/Tiles/FloorTileSystem.cs +++ b/Content.Shared/Tiles/FloorTileSystem.cs @@ -36,6 +36,7 @@ public sealed class FloorTileSystem : EntitySystem [Dependency] private readonly SharedTransformSystem _transform = default!; [Dependency] private readonly TileSystem _tile = default!; [Dependency] private readonly SharedPhysicsSystem _physics = default!; + [Dependency] private readonly SharedMapSystem _map = default!; private static readonly Vector2 CheckRange = new(1f, 1f); @@ -132,7 +133,7 @@ public sealed class FloorTileSystem : EntitySystem return; } - var tile = mapGrid.GetTileRef(location); + var tile = _map.GetTileRef(gridUid, mapGrid, location); var baseTurf = (ContentTileDefinition) _tileDefinitionManager[tile.Tile.TypeId]; if (HasBaseTurf(currentTileDefinition, baseTurf.ID)) @@ -176,7 +177,7 @@ public sealed class FloorTileSystem : EntitySystem var random = new System.Random((int) _timing.CurTick.Value); var variant = _tile.PickVariant((ContentTileDefinition) _tileDefinitionManager[tileId], random); - mapGrid.SetTile(location.Offset(new Vector2(offset, offset)), new Tile(tileId, 0, variant)); + _map.SetTile(gridUid, mapGrid,location.Offset(new Vector2(offset, offset)), new Tile(tileId, 0, variant)); _audio.PlayPredicted(placeSound, location, user); }