Refactor map loading & saving

This commit is contained in:
ElectroJr
2024-12-22 15:13:10 +13:00
parent 1abe9db99c
commit 6242567aff
33 changed files with 553 additions and 362 deletions

View File

@@ -1,11 +1,9 @@
using System.Linq;
using System.Numerics;
using Content.Server.GameTicking;
using Content.Server.Maps;
using Content.Shared.Administration;
using Robust.Server.Maps;
using Robust.Shared.Console;
using Robust.Shared.ContentPack;
using Robust.Shared.EntitySerialization;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
@@ -25,6 +23,7 @@ namespace Content.Server.Administration.Commands
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
var entityManager = IoCManager.Resolve<IEntityManager>();
var gameTicker = entityManager.EntitySysManager.GetEntitySystem<GameTicker>();
var mapSys = entityManager.EntitySysManager.GetEntitySystem<SharedMapSystem>();
if (args.Length is not (2 or 4 or 5))
{
@@ -32,29 +31,28 @@ namespace Content.Server.Administration.Commands
return;
}
if (prototypeManager.TryIndex<GameMapPrototype>(args[1], out var gameMap))
{
if (!int.TryParse(args[0], out var mapId))
return;
var loadOptions = new MapLoadOptions()
{
LoadMap = false,
};
var stationName = args.Length == 5 ? args[4] : null;
if (args.Length >= 4 && int.TryParse(args[2], out var x) && int.TryParse(args[3], out var y))
{
loadOptions.Offset = new Vector2(x, y);
}
var grids = gameTicker.LoadGameMap(gameMap, new MapId(mapId), loadOptions, stationName);
shell.WriteLine($"Loaded {grids.Count} grids.");
}
else
if (!prototypeManager.TryIndex<GameMapPrototype>(args[1], out var gameMap))
{
shell.WriteError($"The given map prototype {args[0]} is invalid.");
return;
}
if (!int.TryParse(args[0], out var mapId))
return;
var stationName = args.Length == 5 ? args[4] : null;
Vector2? offset = null;
if (args.Length >= 4)
offset = new Vector2(int.Parse(args[2]), int.Parse(args[3]));
var id = new MapId(mapId);
var grids = mapSys.MapExists(id)
? gameTicker.MergeGameMap(gameMap, id, stationName: stationName, offset: offset)
: gameTicker.LoadGameMapWithId(gameMap, id, stationName: stationName, offset: offset);
shell.WriteLine($"Loaded {grids.Count} grids.");
}
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)

View File

@@ -5,6 +5,7 @@ using Robust.Shared.Configuration;
using Robust.Shared.Console;
using Robust.Shared.Map;
using System.Linq;
using Robust.Shared.EntitySerialization.Systems;
namespace Content.Server.Administration.Commands;

View File

@@ -1,8 +1,7 @@
using Robust.Server.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.EntitySerialization.Systems;
using Robust.Shared.Network;
using Robust.Shared.Player;
using Robust.Shared.Utility;
namespace Content.Server.Administration.Systems;
@@ -11,8 +10,7 @@ namespace Content.Server.Administration.Systems;
/// </summary>
public sealed class AdminTestArenaSystem : EntitySystem
{
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly MapLoaderSystem _map = default!;
[Dependency] private readonly MapLoaderSystem _loader = default!;
[Dependency] private readonly MetaDataSystem _metaDataSystem = default!;
public const string ArenaMapPath = "/Maps/Test/admin_test_arena.yml";
@@ -28,26 +26,24 @@ public sealed class AdminTestArenaSystem : EntitySystem
{
return (arenaMap, arenaGrid);
}
else
{
ArenaGrid[admin.UserId] = null;
return (arenaMap, null);
}
}
ArenaMap[admin.UserId] = _mapManager.GetMapEntityId(_mapManager.CreateMap());
_metaDataSystem.SetEntityName(ArenaMap[admin.UserId], $"ATAM-{admin.Name}");
var grids = _map.LoadMap(Comp<MapComponent>(ArenaMap[admin.UserId]).MapId, ArenaMapPath);
if (grids.Count != 0)
{
_metaDataSystem.SetEntityName(grids[0], $"ATAG-{admin.Name}");
ArenaGrid[admin.UserId] = grids[0];
}
else
{
ArenaGrid[admin.UserId] = null;
return (arenaMap, null);
}
return (ArenaMap[admin.UserId], ArenaGrid[admin.UserId]);
var path = new ResPath(ArenaMapPath);
if (!_loader.TryLoadMap(path, out var map, out var grids))
throw new Exception($"Failed to load admin arena");
ArenaMap[admin.UserId] = map.Value.Owner;
_metaDataSystem.SetEntityName(map.Value.Owner, $"ATAM-{admin.Name}");
var grid = grids.FirstOrNull();
ArenaGrid[admin.UserId] = grid?.Owner;
if (grid != null)
_metaDataSystem.SetEntityName(grid.Value.Owner, $"ATAG-{admin.Name}");
return (map.Value.Owner, grid?.Owner);
}
}