Remove obsolete functions from tile commands. (#31112)
* first part * second part - file scope namespaces * missing peice
This commit is contained in:
@@ -6,103 +6,102 @@ using Content.Shared.Tag;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Map.Components;
|
||||
|
||||
namespace Content.Server.Construction.Commands
|
||||
namespace Content.Server.Construction.Commands;
|
||||
|
||||
[AdminCommand(AdminFlags.Mapping)]
|
||||
public sealed class FixRotationsCommand : IConsoleCommand
|
||||
{
|
||||
[AdminCommand(AdminFlags.Mapping)]
|
||||
public sealed class FixRotationsCommand : IConsoleCommand
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
|
||||
// ReSharper disable once StringLiteralTypo
|
||||
public string Command => "fixrotations";
|
||||
public string Description => "Sets the rotation of all occluders, low walls and windows to south.";
|
||||
public string Help => $"Usage: {Command} <gridId> | {Command}";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argsOther, string[] args)
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
var player = shell.Player;
|
||||
EntityUid? gridId;
|
||||
var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
|
||||
|
||||
// ReSharper disable once StringLiteralTypo
|
||||
public string Command => "fixrotations";
|
||||
public string Description => "Sets the rotation of all occluders, low walls and windows to south.";
|
||||
public string Help => $"Usage: {Command} <gridId> | {Command}";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argsOther, string[] args)
|
||||
switch (args.Length)
|
||||
{
|
||||
var player = shell.Player;
|
||||
EntityUid? gridId;
|
||||
var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
|
||||
|
||||
switch (args.Length)
|
||||
{
|
||||
case 0:
|
||||
if (player?.AttachedEntity is not {Valid: true} playerEntity)
|
||||
{
|
||||
shell.WriteError("Only a player can run this command.");
|
||||
return;
|
||||
}
|
||||
|
||||
gridId = xformQuery.GetComponent(playerEntity).GridUid;
|
||||
break;
|
||||
case 1:
|
||||
if (!NetEntity.TryParse(args[0], out var idNet) || !_entManager.TryGetEntity(idNet, out var id))
|
||||
{
|
||||
shell.WriteError($"{args[0]} is not a valid entity.");
|
||||
return;
|
||||
}
|
||||
|
||||
gridId = id;
|
||||
break;
|
||||
default:
|
||||
shell.WriteLine(Help);
|
||||
case 0:
|
||||
if (player?.AttachedEntity is not { Valid: true } playerEntity)
|
||||
{
|
||||
shell.WriteError("Only a player can run this command.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_entManager.TryGetComponent(gridId, out MapGridComponent? grid))
|
||||
{
|
||||
shell.WriteError($"No grid exists with id {gridId}");
|
||||
gridId = xformQuery.GetComponent(playerEntity).GridUid;
|
||||
break;
|
||||
case 1:
|
||||
if (!NetEntity.TryParse(args[0], out var idNet) || !_entManager.TryGetEntity(idNet, out var id))
|
||||
{
|
||||
shell.WriteError($"{args[0]} is not a valid entity.");
|
||||
return;
|
||||
}
|
||||
|
||||
gridId = id;
|
||||
break;
|
||||
default:
|
||||
shell.WriteLine(Help);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_entManager.EntityExists(gridId))
|
||||
{
|
||||
shell.WriteError($"Grid {gridId} doesn't have an associated grid entity.");
|
||||
return;
|
||||
}
|
||||
|
||||
var changed = 0;
|
||||
var tagSystem = _entManager.EntitySysManager.GetEntitySystem<TagSystem>();
|
||||
|
||||
|
||||
var enumerator = xformQuery.GetComponent(gridId.Value).ChildEnumerator;
|
||||
while (enumerator.MoveNext(out var child))
|
||||
{
|
||||
if (!_entManager.EntityExists(child))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var valid = false;
|
||||
|
||||
// Occluders should only count if the state of it right now is enabled.
|
||||
// This prevents issues with edge firelocks.
|
||||
if (_entManager.TryGetComponent<OccluderComponent>(child, out var occluder))
|
||||
{
|
||||
valid |= occluder.Enabled;
|
||||
}
|
||||
// low walls & grilles
|
||||
valid |= _entManager.HasComponent<SharedCanBuildWindowOnTopComponent>(child);
|
||||
// cables
|
||||
valid |= _entManager.HasComponent<CableComponent>(child);
|
||||
// anything else that might need this forced
|
||||
valid |= tagSystem.HasTag(child, "ForceFixRotations");
|
||||
// override
|
||||
valid &= !tagSystem.HasTag(child, "ForceNoFixRotations");
|
||||
|
||||
if (!valid)
|
||||
continue;
|
||||
|
||||
var childXform = xformQuery.GetComponent(child);
|
||||
|
||||
if (childXform.LocalRotation != Angle.Zero)
|
||||
{
|
||||
childXform.LocalRotation = Angle.Zero;
|
||||
changed++;
|
||||
}
|
||||
}
|
||||
|
||||
shell.WriteLine($"Changed {changed} entities. If things seem wrong, reconnect.");
|
||||
}
|
||||
|
||||
if (!_entManager.TryGetComponent(gridId, out MapGridComponent? grid))
|
||||
{
|
||||
shell.WriteError($"No grid exists with id {gridId}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_entManager.EntityExists(gridId))
|
||||
{
|
||||
shell.WriteError($"Grid {gridId} doesn't have an associated grid entity.");
|
||||
return;
|
||||
}
|
||||
|
||||
var changed = 0;
|
||||
var tagSystem = _entManager.EntitySysManager.GetEntitySystem<TagSystem>();
|
||||
|
||||
|
||||
var enumerator = xformQuery.GetComponent(gridId.Value).ChildEnumerator;
|
||||
while (enumerator.MoveNext(out var child))
|
||||
{
|
||||
if (!_entManager.EntityExists(child))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var valid = false;
|
||||
|
||||
// Occluders should only count if the state of it right now is enabled.
|
||||
// This prevents issues with edge firelocks.
|
||||
if (_entManager.TryGetComponent<OccluderComponent>(child, out var occluder))
|
||||
{
|
||||
valid |= occluder.Enabled;
|
||||
}
|
||||
// low walls & grilles
|
||||
valid |= _entManager.HasComponent<SharedCanBuildWindowOnTopComponent>(child);
|
||||
// cables
|
||||
valid |= _entManager.HasComponent<CableComponent>(child);
|
||||
// anything else that might need this forced
|
||||
valid |= tagSystem.HasTag(child, "ForceFixRotations");
|
||||
// override
|
||||
valid &= !tagSystem.HasTag(child, "ForceNoFixRotations");
|
||||
|
||||
if (!valid)
|
||||
continue;
|
||||
|
||||
var childXform = xformQuery.GetComponent(child);
|
||||
|
||||
if (childXform.LocalRotation != Angle.Zero)
|
||||
{
|
||||
childXform.LocalRotation = Angle.Zero;
|
||||
changed++;
|
||||
}
|
||||
}
|
||||
|
||||
shell.WriteLine($"Changed {changed} entities. If things seem wrong, reconnect.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ using Robust.Shared.Map.Components;
|
||||
namespace Content.Server.Construction.Commands;
|
||||
|
||||
[AdminCommand(AdminFlags.Mapping)]
|
||||
sealed class TileReplaceCommand : IConsoleCommand
|
||||
public sealed class TileReplaceCommand : IConsoleCommand
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDef = default!;
|
||||
@@ -27,9 +27,9 @@ sealed class TileReplaceCommand : IConsoleCommand
|
||||
switch (args.Length)
|
||||
{
|
||||
case 2:
|
||||
if (player?.AttachedEntity is not {Valid: true} playerEntity)
|
||||
if (player?.AttachedEntity is not { Valid: true } playerEntity)
|
||||
{
|
||||
shell.WriteLine("Only a player can run this command without a grid ID.");
|
||||
shell.WriteError("Only a player can run this command without a grid ID.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ sealed class TileReplaceCommand : IConsoleCommand
|
||||
if (!NetEntity.TryParse(args[0], out var idNet) ||
|
||||
!_entManager.TryGetEntity(idNet, out var id))
|
||||
{
|
||||
shell.WriteLine($"{args[0]} is not a valid entity.");
|
||||
shell.WriteError($"{args[0]} is not a valid entity.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -59,23 +59,25 @@ sealed class TileReplaceCommand : IConsoleCommand
|
||||
|
||||
if (!_entManager.TryGetComponent(gridId, out MapGridComponent? grid))
|
||||
{
|
||||
shell.WriteLine($"No grid exists with id {gridId}");
|
||||
shell.WriteError($"No grid exists with id {gridId}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_entManager.EntityExists(gridId))
|
||||
{
|
||||
shell.WriteLine($"Grid {gridId} doesn't have an associated grid entity.");
|
||||
shell.WriteError($"Grid {gridId} doesn't have an associated grid entity.");
|
||||
return;
|
||||
}
|
||||
|
||||
var mapSystem = _entManager.System<SharedMapSystem>();
|
||||
|
||||
var changed = 0;
|
||||
foreach (var tile in grid.GetAllTiles())
|
||||
foreach (var tile in mapSystem.GetAllTiles(gridId.Value, grid))
|
||||
{
|
||||
var tileContent = tile.Tile;
|
||||
if (tileContent.TypeId == tileA.TileId)
|
||||
{
|
||||
grid.SetTile(tile.GridIndices, new Tile(tileB.TileId));
|
||||
mapSystem.SetTile(gridId.Value, grid, tile.GridIndices, new Tile(tileB.TileId));
|
||||
changed++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,105 +7,104 @@ using Robust.Shared.Map;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Map.Components;
|
||||
|
||||
namespace Content.Server.Construction.Commands
|
||||
namespace Content.Server.Construction.Commands;
|
||||
|
||||
[AdminCommand(AdminFlags.Mapping)]
|
||||
public sealed class TileWallsCommand : IConsoleCommand
|
||||
{
|
||||
[AdminCommand(AdminFlags.Mapping)]
|
||||
sealed class TileWallsCommand : IConsoleCommand
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDefManager = default!;
|
||||
|
||||
// ReSharper disable once StringLiteralTypo
|
||||
public string Command => "tilewalls";
|
||||
public string Description => "Puts an underplating tile below every wall on a grid.";
|
||||
public string Help => $"Usage: {Command} <gridId> | {Command}";
|
||||
|
||||
[ValidatePrototypeId<ContentTileDefinition>]
|
||||
public const string TilePrototypeId = "Plating";
|
||||
|
||||
[ValidatePrototypeId<TagPrototype>]
|
||||
public const string WallTag = "Wall";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDefManager = default!;
|
||||
var player = shell.Player;
|
||||
EntityUid? gridId;
|
||||
|
||||
// ReSharper disable once StringLiteralTypo
|
||||
public string Command => "tilewalls";
|
||||
public string Description => "Puts an underplating tile below every wall on a grid.";
|
||||
public string Help => $"Usage: {Command} <gridId> | {Command}";
|
||||
|
||||
[ValidatePrototypeId<ContentTileDefinition>]
|
||||
public const string TilePrototypeId = "Plating";
|
||||
|
||||
[ValidatePrototypeId<TagPrototype>]
|
||||
public const string WallTag = "Wall";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
switch (args.Length)
|
||||
{
|
||||
var player = shell.Player;
|
||||
EntityUid? gridId;
|
||||
|
||||
switch (args.Length)
|
||||
{
|
||||
case 0:
|
||||
if (player?.AttachedEntity is not {Valid: true} playerEntity)
|
||||
{
|
||||
shell.WriteLine("Only a player can run this command.");
|
||||
return;
|
||||
}
|
||||
|
||||
gridId = _entManager.GetComponent<TransformComponent>(playerEntity).GridUid;
|
||||
break;
|
||||
case 1:
|
||||
if (!NetEntity.TryParse(args[0], out var idNet) || !_entManager.TryGetEntity(idNet, out var id))
|
||||
{
|
||||
shell.WriteLine($"{args[0]} is not a valid entity.");
|
||||
return;
|
||||
}
|
||||
|
||||
gridId = id;
|
||||
break;
|
||||
default:
|
||||
shell.WriteLine(Help);
|
||||
case 0:
|
||||
if (player?.AttachedEntity is not { Valid: true } playerEntity)
|
||||
{
|
||||
shell.WriteError("Only a player can run this command.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_entManager.TryGetComponent(gridId, out MapGridComponent? grid))
|
||||
{
|
||||
shell.WriteLine($"No grid exists with id {gridId}");
|
||||
gridId = _entManager.GetComponent<TransformComponent>(playerEntity).GridUid;
|
||||
break;
|
||||
case 1:
|
||||
if (!NetEntity.TryParse(args[0], out var idNet) || !_entManager.TryGetEntity(idNet, out var id))
|
||||
{
|
||||
shell.WriteError($"{args[0]} is not a valid entity.");
|
||||
return;
|
||||
}
|
||||
|
||||
gridId = id;
|
||||
break;
|
||||
default:
|
||||
shell.WriteLine(Help);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_entManager.EntityExists(gridId))
|
||||
{
|
||||
shell.WriteLine($"Grid {gridId} doesn't have an associated grid entity.");
|
||||
return;
|
||||
}
|
||||
|
||||
var tagSystem = _entManager.EntitySysManager.GetEntitySystem<TagSystem>();
|
||||
var underplating = _tileDefManager[TilePrototypeId];
|
||||
var underplatingTile = new Tile(underplating.TileId);
|
||||
var changed = 0;
|
||||
var enumerator = _entManager.GetComponent<TransformComponent>(gridId.Value).ChildEnumerator;
|
||||
while (enumerator.MoveNext(out var child))
|
||||
{
|
||||
if (!_entManager.EntityExists(child))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!tagSystem.HasTag(child, WallTag))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var childTransform = _entManager.GetComponent<TransformComponent>(child);
|
||||
|
||||
if (!childTransform.Anchored)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var mapSystem = _entManager.System<MapSystem>();
|
||||
var tile = mapSystem.GetTileRef(gridId.Value, grid, childTransform.Coordinates);
|
||||
var tileDef = (ContentTileDefinition) _tileDefManager[tile.Tile.TypeId];
|
||||
|
||||
if (tileDef.ID == TilePrototypeId)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
grid.SetTile(childTransform.Coordinates, underplatingTile);
|
||||
changed++;
|
||||
}
|
||||
|
||||
shell.WriteLine($"Changed {changed} tiles.");
|
||||
}
|
||||
|
||||
if (!_entManager.TryGetComponent(gridId, out MapGridComponent? grid))
|
||||
{
|
||||
shell.WriteError($"No grid exists with id {gridId}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_entManager.EntityExists(gridId))
|
||||
{
|
||||
shell.WriteError($"Grid {gridId} doesn't have an associated grid entity.");
|
||||
return;
|
||||
}
|
||||
|
||||
var tagSystem = _entManager.EntitySysManager.GetEntitySystem<TagSystem>();
|
||||
var underplating = _tileDefManager[TilePrototypeId];
|
||||
var underplatingTile = new Tile(underplating.TileId);
|
||||
var changed = 0;
|
||||
var enumerator = _entManager.GetComponent<TransformComponent>(gridId.Value).ChildEnumerator;
|
||||
while (enumerator.MoveNext(out var child))
|
||||
{
|
||||
if (!_entManager.EntityExists(child))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!tagSystem.HasTag(child, WallTag))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var childTransform = _entManager.GetComponent<TransformComponent>(child);
|
||||
|
||||
if (!childTransform.Anchored)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var mapSystem = _entManager.System<MapSystem>();
|
||||
var tile = mapSystem.GetTileRef(gridId.Value, grid, childTransform.Coordinates);
|
||||
var tileDef = (ContentTileDefinition)_tileDefManager[tile.Tile.TypeId];
|
||||
|
||||
if (tileDef.ID == TilePrototypeId)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
mapSystem.SetTile(gridId.Value, grid, childTransform.Coordinates, underplatingTile);
|
||||
changed++;
|
||||
}
|
||||
|
||||
shell.WriteLine($"Changed {changed} tiles.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,66 +6,66 @@ using Robust.Shared.Console;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
|
||||
namespace Content.Server.Interaction
|
||||
namespace Content.Server.Interaction;
|
||||
|
||||
[AdminCommand(AdminFlags.Debug)]
|
||||
public sealed class TilePryCommand : IConsoleCommand
|
||||
{
|
||||
[AdminCommand(AdminFlags.Debug)]
|
||||
sealed class TilePryCommand : IConsoleCommand
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
|
||||
public string Command => "tilepry";
|
||||
public string Description => "Pries up all tiles in a radius around the user.";
|
||||
public string Help => $"Usage: {Command} <radius>";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
|
||||
public string Command => "tilepry";
|
||||
public string Description => "Pries up all tiles in a radius around the user.";
|
||||
public string Help => $"Usage: {Command} <radius>";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
var player = shell.Player;
|
||||
if (player?.AttachedEntity is not { } attached)
|
||||
{
|
||||
var player = shell.Player;
|
||||
if (player?.AttachedEntity is not {} attached)
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Length != 1)
|
||||
{
|
||||
shell.WriteLine(Help);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!int.TryParse(args[0], out var radius))
|
||||
{
|
||||
shell.WriteError($"{args[0]} isn't a valid integer.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (radius < 0)
|
||||
{
|
||||
shell.WriteError("Radius must be positive.");
|
||||
return;
|
||||
}
|
||||
|
||||
var mapSystem = _entities.System<SharedMapSystem>();
|
||||
var xform = _entities.GetComponent<TransformComponent>(attached);
|
||||
|
||||
var playerGrid = xform.GridUid;
|
||||
|
||||
if (!_entities.TryGetComponent<MapGridComponent>(playerGrid, out var mapGrid))
|
||||
return;
|
||||
|
||||
var playerPosition = xform.Coordinates;
|
||||
var tileDefinitionManager = IoCManager.Resolve<ITileDefinitionManager>();
|
||||
|
||||
for (var i = -radius; i <= radius; i++)
|
||||
{
|
||||
for (var j = -radius; j <= radius; j++)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var tile = mapSystem.GetTileRef(playerGrid.Value, mapGrid, playerPosition.Offset(new Vector2(i, j)));
|
||||
var coordinates = mapSystem.GridTileToLocal(playerGrid.Value, mapGrid, tile.GridIndices);
|
||||
var tileDef = (ContentTileDefinition)tileDefinitionManager[tile.Tile.TypeId];
|
||||
|
||||
if (args.Length != 1)
|
||||
{
|
||||
shell.WriteLine(Help);
|
||||
return;
|
||||
}
|
||||
if (!tileDef.CanCrowbar) continue;
|
||||
|
||||
if (!int.TryParse(args[0], out var radius))
|
||||
{
|
||||
shell.WriteLine($"{args[0]} isn't a valid integer.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (radius < 0)
|
||||
{
|
||||
shell.WriteLine("Radius must be positive.");
|
||||
return;
|
||||
}
|
||||
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
var xform = _entities.GetComponent<TransformComponent>(attached);
|
||||
var playerGrid = xform.GridUid;
|
||||
|
||||
if (!_entities.TryGetComponent<MapGridComponent>(playerGrid, out var mapGrid))
|
||||
return;
|
||||
|
||||
var playerPosition = xform.Coordinates;
|
||||
var tileDefinitionManager = IoCManager.Resolve<ITileDefinitionManager>();
|
||||
|
||||
for (var i = -radius; i <= radius; i++)
|
||||
{
|
||||
for (var j = -radius; j <= radius; j++)
|
||||
{
|
||||
var tile = mapGrid.GetTileRef(playerPosition.Offset(new Vector2(i, j)));
|
||||
var coordinates = mapGrid.GridTileToLocal(tile.GridIndices);
|
||||
var tileDef = (ContentTileDefinition) tileDefinitionManager[tile.Tile.TypeId];
|
||||
|
||||
if (!tileDef.CanCrowbar) continue;
|
||||
|
||||
var plating = tileDefinitionManager["Plating"];
|
||||
mapGrid.SetTile(coordinates, new Tile(plating.TileId));
|
||||
}
|
||||
var plating = tileDefinitionManager["Plating"];
|
||||
mapSystem.SetTile(playerGrid.Value, mapGrid, coordinates, new Tile(plating.TileId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user