CatStation/Content.Client/Sandbox/SandboxSystem.cs
TemporalOroboros 84b2f07157
The IMapManager is dead (#44002)
* Axes the easy IMapManager references

* Axes the references to unported (obsolete) IMapManager methods

* Converts salvageruler command to a LocalizedEntityCommand so it can use SharedMapSystem

* Removes IMapManager from GameTicker
This required axing the map nuke during restart, but that should be fine?
Maps are entities so EntityManager.FlushEntities should delete them all and that's the preceding line

* submodule update(?)

---------

Co-authored-by: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
2026-07-01 20:44:54 -07:00

165 lines
4.7 KiB
C#

using Content.Client.Administration.Managers;
using Content.Client.Movement.Systems;
using Content.Shared.Sandbox;
using Robust.Client.Console;
using Robust.Client.Placement;
using Robust.Client.Placement.Modes;
using Robust.Shared.Map;
using Robust.Shared.Player;
namespace Content.Client.Sandbox
{
public sealed partial class SandboxSystem : SharedSandboxSystem
{
[Dependency] private IClientAdminManager _adminManager = default!;
[Dependency] private IClientConsoleHost _consoleHost = default!;
[Dependency] private IPlacementManager _placement = default!;
[Dependency] private ContentEyeSystem _contentEye = default!;
[Dependency] private SharedTransformSystem _transform = default!;
[Dependency] private SharedMapSystem _mapSystem = default!;
private bool _sandboxEnabled;
public bool SandboxAllowed { get; private set; }
public event Action? SandboxEnabled;
public event Action? SandboxDisabled;
public override void Initialize()
{
_adminManager.AdminStatusUpdated += CheckStatus;
SubscribeNetworkEvent<MsgSandboxStatus>(OnSandboxStatus);
}
private void CheckStatus()
{
var currentStatus = _sandboxEnabled || _adminManager.IsActive();
if (currentStatus == SandboxAllowed)
return;
SandboxAllowed = currentStatus;
if (SandboxAllowed)
{
SandboxEnabled?.Invoke();
}
else
{
SandboxDisabled?.Invoke();
}
}
public override void Shutdown()
{
_adminManager.AdminStatusUpdated -= CheckStatus;
base.Shutdown();
}
private void OnSandboxStatus(MsgSandboxStatus ev)
{
SetAllowed(ev.SandboxAllowed);
}
private void SetAllowed(bool sandboxEnabled)
{
_sandboxEnabled = sandboxEnabled;
CheckStatus();
}
public void Respawn()
{
RaiseNetworkEvent(new MsgSandboxRespawn());
}
public void GiveAdminAccess()
{
RaiseNetworkEvent(new MsgSandboxGiveAccess());
}
public void GiveAGhost()
{
RaiseNetworkEvent(new MsgSandboxGiveAghost());
}
public void Suicide()
{
RaiseNetworkEvent(new MsgSandboxSuicide());
}
public void ToggleThermalVision()
{
RaiseNetworkEvent(new MsgSandboxThermalVision());
}
public bool Copy(ICommonSession? session, EntityCoordinates coords, EntityUid uid)
{
if (!SandboxAllowed)
return false;
// Try copy entity.
if (uid.IsValid()
&& TryComp(uid, out MetaDataComponent? comp)
&& !comp.EntityDeleted)
{
if (comp.EntityPrototype == null || comp.EntityPrototype.HideSpawnMenu || comp.EntityPrototype.Abstract)
return false;
if (_placement.Eraser)
_placement.ToggleEraser();
_placement.BeginPlacing(new()
{
EntityType = comp.EntityPrototype.ID,
IsTile = false,
TileType = 0,
PlacementOption = comp.EntityPrototype.PlacementMode
});
return true;
}
// Try copy tile.
if (!_mapSystem.TryFindGridAt(_transform.ToMapCoordinates(coords), out var gridUid, out var grid) || !_mapSystem.TryGetTileRef(gridUid, grid, coords, out var tileRef))
return false;
if (_placement.Eraser)
_placement.ToggleEraser();
_placement.BeginPlacing(new()
{
EntityType = null,
IsTile = true,
TileType = tileRef.Tile.TypeId,
PlacementOption = nameof(AlignTileAny)
});
return true;
}
// TODO: need to cleanup these
public void ToggleLight()
{
_consoleHost.ExecuteCommand("togglelight");
}
public void ToggleFov()
{
_contentEye.RequestToggleFov();
}
public void ToggleShadows()
{
_consoleHost.ExecuteCommand("toggleshadows");
}
public void ToggleSubFloor()
{
_consoleHost.ExecuteCommand("showsubfloor");
}
public void ShowMarkers()
{
_consoleHost.ExecuteCommand("showmarkers");
}
public void ShowBb()
{
_consoleHost.ExecuteCommand("physics shapes");
}
}
}