2022-09-03 06:39:28 -07:00
|
|
|
using System.Linq;
|
2020-12-03 03:40:47 +01:00
|
|
|
using Content.Server.Administration;
|
2023-11-20 20:27:37 -08:00
|
|
|
using Content.Server.GameTicking;
|
2020-12-03 03:40:47 +01:00
|
|
|
using Content.Shared.Administration;
|
2021-02-01 16:49:43 -08:00
|
|
|
using Robust.Shared.Console;
|
2022-09-03 06:39:28 -07:00
|
|
|
using Robust.Shared.ContentPack;
|
2024-12-22 15:13:10 +13:00
|
|
|
using Robust.Shared.EntitySerialization;
|
|
|
|
|
using Robust.Shared.EntitySerialization.Systems;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.Map;
|
2025-02-18 23:25:14 +11:00
|
|
|
using Robust.Shared.Map.Components;
|
2024-12-22 15:13:10 +13:00
|
|
|
using Robust.Shared.Utility;
|
2020-12-03 03:40:47 +01:00
|
|
|
|
2022-09-03 06:39:28 -07:00
|
|
|
namespace Content.Server.Mapping
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
|
|
|
|
[AdminCommand(AdminFlags.Server | AdminFlags.Mapping)]
|
2025-06-17 05:39:42 -04:00
|
|
|
public sealed class MappingCommand : LocalizedEntityCommands
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2025-06-17 05:39:42 -04:00
|
|
|
[Dependency] private readonly IResourceManager _resourceMgr = default!;
|
|
|
|
|
[Dependency] private readonly SharedMapSystem _mapSystem = default!;
|
|
|
|
|
[Dependency] private readonly MappingSystem _mappingSystem = default!;
|
|
|
|
|
[Dependency] private readonly MapLoaderSystem _mapLoader = default!;
|
2021-12-05 21:02:04 +01:00
|
|
|
|
2025-06-17 05:39:42 -04:00
|
|
|
public override string Command => "mapping";
|
2022-06-09 14:38:31 +12:00
|
|
|
|
2025-06-17 05:39:42 -04:00
|
|
|
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
2022-06-09 14:38:31 +12:00
|
|
|
{
|
|
|
|
|
switch (args.Length)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
return CompletionResult.FromHint(Loc.GetString("cmd-hint-mapping-id"));
|
|
|
|
|
case 2:
|
2025-06-17 05:39:42 -04:00
|
|
|
var opts = CompletionHelper.UserFilePath(args[1], _resourceMgr.UserData)
|
|
|
|
|
.Concat(CompletionHelper.ContentFilePath(args[1], _resourceMgr));
|
2022-06-09 14:38:31 +12:00
|
|
|
return CompletionResult.FromHintOptions(opts, Loc.GetString("cmd-hint-mapping-path"));
|
2025-02-18 23:25:14 +11:00
|
|
|
case 3:
|
|
|
|
|
return CompletionResult.FromHintOptions(["false", "true"], Loc.GetString("cmd-mapping-hint-grid"));
|
2022-06-09 14:38:31 +12:00
|
|
|
}
|
|
|
|
|
return CompletionResult.Empty;
|
|
|
|
|
}
|
2020-12-03 03:40:47 +01:00
|
|
|
|
2025-06-17 05:39:42 -04:00
|
|
|
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2023-10-28 09:59:53 +11:00
|
|
|
if (shell.Player is not { } player)
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2024-08-11 09:46:57 +00:00
|
|
|
shell.WriteError(Loc.GetString("shell-cannot-run-command-from-server"));
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-18 23:25:14 +11:00
|
|
|
if (args.Length > 3)
|
2022-02-28 14:21:15 +13:00
|
|
|
{
|
|
|
|
|
shell.WriteLine(Help);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-07 06:36:34 +01:00
|
|
|
#if DEBUG
|
2024-04-24 17:38:43 +12:00
|
|
|
shell.WriteLine(Loc.GetString("cmd-mapping-warning"));
|
2021-02-07 06:36:34 +01:00
|
|
|
#endif
|
|
|
|
|
|
2025-02-18 23:25:14 +11:00
|
|
|
// For backwards compatibility, isGrid is optional and we allow mappers to try load grids without explicitly
|
|
|
|
|
// specifying that they are loading a grid. Currently content is not allowed to override a map's MapId, so
|
|
|
|
|
// without engine changes this needs to be done by brute force by just trying to load it as a map first.
|
|
|
|
|
// This can result in errors being logged if the file is actually a grid, but the command should still work.
|
|
|
|
|
// yipeeee
|
|
|
|
|
bool? isGrid = args.Length < 3 ? null : bool.Parse(args[2]);
|
|
|
|
|
|
2022-02-28 14:21:15 +13:00
|
|
|
MapId mapId;
|
2024-04-20 17:01:15 -04:00
|
|
|
string? toLoad = null;
|
2025-06-17 05:39:42 -04:00
|
|
|
|
2025-02-18 23:25:14 +11:00
|
|
|
Entity<MapGridComponent>? grid = null;
|
2020-12-03 03:40:47 +01:00
|
|
|
|
2022-02-28 14:21:15 +13:00
|
|
|
// Get the map ID to use
|
2025-02-18 23:25:14 +11:00
|
|
|
if (args.Length > 0)
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2022-06-09 14:38:31 +12:00
|
|
|
if (!int.TryParse(args[0], out var intMapId))
|
2022-02-28 14:21:15 +13:00
|
|
|
{
|
2022-06-09 14:38:31 +12:00
|
|
|
shell.WriteError(Loc.GetString("cmd-mapping-failure-integer", ("arg", args[0])));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mapId = new MapId(intMapId);
|
|
|
|
|
|
|
|
|
|
// no loading null space
|
|
|
|
|
if (mapId == MapId.Nullspace)
|
|
|
|
|
{
|
|
|
|
|
shell.WriteError(Loc.GetString("cmd-mapping-nullspace"));
|
2022-02-28 14:21:15 +13:00
|
|
|
return;
|
|
|
|
|
}
|
2020-12-03 03:40:47 +01:00
|
|
|
|
2025-06-17 05:39:42 -04:00
|
|
|
if (_mapSystem.MapExists(mapId))
|
2022-02-28 14:21:15 +13:00
|
|
|
{
|
2022-06-09 14:38:31 +12:00
|
|
|
shell.WriteError(Loc.GetString("cmd-mapping-exists", ("mapId", mapId)));
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
2022-02-28 14:21:15 +13:00
|
|
|
}
|
2022-06-09 14:38:31 +12:00
|
|
|
|
2024-04-20 17:01:15 -04:00
|
|
|
// either load a map or create a new one.
|
|
|
|
|
if (args.Length <= 1)
|
|
|
|
|
{
|
2025-06-17 05:39:42 -04:00
|
|
|
_mapSystem.CreateMap(mapId, runMapInit: false);
|
2024-04-20 17:01:15 -04:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-12-22 15:13:10 +13:00
|
|
|
var path = new ResPath(args[1]);
|
2025-02-18 23:25:14 +11:00
|
|
|
toLoad = path.FilenameWithoutExtension;
|
2024-12-22 15:13:10 +13:00
|
|
|
var opts = new DeserializationOptions {StoreYamlUids = true};
|
2025-02-18 23:25:14 +11:00
|
|
|
|
|
|
|
|
if (isGrid == true)
|
|
|
|
|
{
|
2025-06-17 05:39:42 -04:00
|
|
|
_mapSystem.CreateMap(mapId, runMapInit: false);
|
|
|
|
|
if (!_mapLoader.TryLoadGrid(mapId, path, out grid, opts))
|
2025-02-18 23:25:14 +11:00
|
|
|
{
|
|
|
|
|
shell.WriteError(Loc.GetString("cmd-mapping-error"));
|
2025-06-17 05:39:42 -04:00
|
|
|
_mapSystem.DeleteMap(mapId);
|
2025-02-18 23:25:14 +11:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-06-17 05:39:42 -04:00
|
|
|
else if (!_mapLoader.TryLoadMapWithId(mapId, path, out _, out _, opts))
|
2025-02-18 23:25:14 +11:00
|
|
|
{
|
|
|
|
|
if (isGrid == false)
|
|
|
|
|
{
|
|
|
|
|
shell.WriteError(Loc.GetString("cmd-mapping-error"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// isGrid was not specified and loading it as a map failed, so we fall back to trying to load
|
|
|
|
|
// the file as a grid
|
|
|
|
|
shell.WriteLine(Loc.GetString("cmd-mapping-try-grid"));
|
2025-06-17 05:39:42 -04:00
|
|
|
_mapSystem.CreateMap(mapId, runMapInit: false);
|
|
|
|
|
if (!_mapLoader.TryLoadGrid(mapId, path, out grid, opts))
|
2025-02-18 23:25:14 +11:00
|
|
|
{
|
|
|
|
|
shell.WriteError(Loc.GetString("cmd-mapping-error"));
|
2025-06-17 05:39:42 -04:00
|
|
|
_mapSystem.DeleteMap(mapId);
|
2025-02-18 23:25:14 +11:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-20 17:01:15 -04:00
|
|
|
}
|
2020-12-03 03:40:47 +01:00
|
|
|
|
2024-04-20 17:01:15 -04:00
|
|
|
// was the map actually created or did it fail somehow?
|
2025-06-17 05:39:42 -04:00
|
|
|
if (!_mapSystem.MapExists(mapId))
|
2024-04-20 17:01:15 -04:00
|
|
|
{
|
|
|
|
|
shell.WriteError(Loc.GetString("cmd-mapping-error"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-09-03 06:39:28 -07:00
|
|
|
}
|
2022-02-28 14:21:15 +13:00
|
|
|
else
|
2025-06-17 05:39:42 -04:00
|
|
|
_mapSystem.CreateMap(out mapId, runMapInit: false);
|
2021-12-02 20:25:50 -08:00
|
|
|
|
2022-02-28 14:21:15 +13:00
|
|
|
// map successfully created. run misc helpful mapping commands
|
|
|
|
|
if (player.AttachedEntity is { Valid: true } playerEntity &&
|
2025-07-07 15:57:05 -04:00
|
|
|
(EntityManager.GetComponent<MetaDataComponent>(playerEntity).EntityPrototype is not { } proto || proto != GameTicker.AdminObserverPrototypeName))
|
2021-12-05 21:02:04 +01:00
|
|
|
{
|
2021-11-23 06:31:21 +11:00
|
|
|
shell.ExecuteCommand("aghost");
|
2021-12-05 21:02:04 +01:00
|
|
|
}
|
2021-11-23 06:31:21 +11:00
|
|
|
|
2022-11-17 15:14:44 -08:00
|
|
|
// don't interrupt mapping with events or auto-shuttle
|
2025-02-18 11:26:08 +01:00
|
|
|
shell.ExecuteCommand("changecvar events.enabled false");
|
|
|
|
|
shell.ExecuteCommand("changecvar shuttle.auto_call_time 0");
|
2022-11-17 15:14:44 -08:00
|
|
|
|
2025-02-18 23:25:14 +11:00
|
|
|
if (grid != null)
|
2025-06-17 05:39:42 -04:00
|
|
|
_mappingSystem.ToggleAutosave(grid.Value.Owner, toLoad ?? "NEWGRID");
|
2025-02-18 23:25:14 +11:00
|
|
|
else
|
2025-06-17 05:39:42 -04:00
|
|
|
_mappingSystem.ToggleAutosave(mapId, toLoad ?? "NEWMAP");
|
2025-02-18 23:25:14 +11:00
|
|
|
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.ExecuteCommand($"tp 0 0 {mapId}");
|
2022-05-04 04:19:15 +01:00
|
|
|
shell.RemoteExecuteCommand("mappingclientsidesetup");
|
2025-06-17 05:39:42 -04:00
|
|
|
DebugTools.Assert(_mapSystem.IsPaused(mapId));
|
2022-02-28 14:21:15 +13:00
|
|
|
|
2025-02-18 23:25:14 +11:00
|
|
|
if (args.Length != 2)
|
2022-06-09 14:38:31 +12:00
|
|
|
shell.WriteLine(Loc.GetString("cmd-mapping-success", ("mapId", mapId)));
|
2025-02-18 23:25:14 +11:00
|
|
|
else if (grid == null)
|
|
|
|
|
shell.WriteLine(Loc.GetString("cmd-mapping-success-load", ("mapId", mapId), ("path", args[1])));
|
|
|
|
|
else
|
|
|
|
|
shell.WriteLine(Loc.GetString("cmd-mapping-success-load-grid", ("mapId", mapId), ("path", args[1])));
|
2020-12-03 03:40:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
2020-12-14 06:16:40 +01:00
|
|
|
}
|