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

@@ -30,11 +30,13 @@ using Robust.Server.GameObjects;
using Robust.Shared.Collections;
using Robust.Shared.Configuration;
using Robust.Shared.Console;
using Robust.Shared.EntitySerialization.Systems;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using TimedDespawnComponent = Robust.Shared.Spawners.TimedDespawnComponent;
namespace Content.Server.Shuttles.Systems;
@@ -512,15 +514,13 @@ public sealed class ArrivalsSystem : EntitySystem
private void SetupArrivalsStation()
{
var mapUid = _mapSystem.CreateMap(out var mapId, false);
_metaData.SetEntityName(mapUid, Loc.GetString("map-name-terminal"));
if (!_loader.TryLoad(mapId, _cfgManager.GetCVar(CCVars.ArrivalsMap), out var uids))
{
var path = new ResPath(_cfgManager.GetCVar(CCVars.ArrivalsMap));
if (!_loader.TryLoadMap(path, out var map, out var grids))
return;
}
foreach (var id in uids)
_metaData.SetEntityName(map.Value, Loc.GetString("map-name-terminal"));
foreach (var id in grids)
{
EnsureComp<ArrivalsSourceComponent>(id);
EnsureComp<ProtectedGridComponent>(id);
@@ -531,15 +531,15 @@ public sealed class ArrivalsSystem : EntitySystem
if (_cfgManager.GetCVar(CCVars.ArrivalsPlanet))
{
var template = _random.Pick(_arrivalsBiomeOptions);
_biomes.EnsurePlanet(mapUid, _protoManager.Index(template));
_biomes.EnsurePlanet(map.Value, _protoManager.Index(template));
var restricted = new RestrictedRangeComponent
{
Range = 32f
};
AddComp(mapUid, restricted);
AddComp(map.Value, restricted);
}
_mapSystem.InitializeMap(mapId);
_mapSystem.InitializeMap(map.Value.Comp.MapId);
// Handle roundstart stations.
var query = AllEntityQuery<StationArrivalsComponent>();
@@ -600,9 +600,9 @@ public sealed class ArrivalsSystem : EntitySystem
var dummpMapEntity = _mapSystem.CreateMap(out var dummyMapId);
if (TryGetArrivals(out var arrivals) &&
_loader.TryLoad(dummyMapId, component.ShuttlePath.ToString(), out var shuttleUids))
_loader.TryLoadGrid(dummyMapId, component.ShuttlePath, out var shuttle))
{
component.Shuttle = shuttleUids[0];
component.Shuttle = shuttle.Value;
var shuttleComp = Comp<ShuttleComponent>(component.Shuttle);
var arrivalsComp = EnsureComp<ArrivalsShuttleComponent>(component.Shuttle);
arrivalsComp.Station = uid;

View File

@@ -29,10 +29,9 @@ using Content.Shared.Shuttles.Events;
using Content.Shared.Tag;
using Content.Shared.Tiles;
using Robust.Server.GameObjects;
using Robust.Server.Maps;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Configuration;
using Robust.Shared.Map;
using Robust.Shared.EntitySerialization.Systems;
using Robust.Shared.Map.Components;
using Robust.Shared.Player;
using Robust.Shared.Random;
@@ -60,7 +59,7 @@ public sealed partial class EmergencyShuttleSystem : EntitySystem
[Dependency] private readonly DockingSystem _dock = default!;
[Dependency] private readonly IdCardSystem _idSystem = default!;
[Dependency] private readonly NavMapSystem _navMap = default!;
[Dependency] private readonly MapLoaderSystem _map = default!;
[Dependency] private readonly MapLoaderSystem _loader = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly RoundEndSystem _roundEnd = default!;
@@ -531,10 +530,11 @@ public sealed partial class EmergencyShuttleSystem : EntitySystem
}
var map = _mapSystem.CreateMap(out var mapId);
var grid = _map.LoadGrid(mapId, component.Map.ToString(), new MapLoadOptions()
if (!_loader.TryLoadGrid(mapId, component.Map, out var grid))
{
LoadMap = false,
});
Log.Error($"Failed to set up centcomm grid!");
return;
}
if (!Exists(map))
{
@@ -608,15 +608,11 @@ public sealed partial class EmergencyShuttleSystem : EntitySystem
// Load escape shuttle
var shuttlePath = ent.Comp1.EmergencyShuttlePath;
var shuttle = _map.LoadGrid(map.MapId, shuttlePath.ToString(), new MapLoadOptions()
{
if (!_loader.TryLoadGrid(map.MapId,
shuttlePath,
out var shuttle,
// Should be far enough... right? I'm too lazy to bounds check CentCom rn.
Offset = new Vector2(500f + ent.Comp2.ShuttleIndex, 0f),
// fun fact: if you just fucking yeet centcomm into nullspace anytime you try to spawn the shuttle, then any distance is far enough. so lets not do that
LoadMap = false,
});
if (shuttle == null)
offset: new Vector2(500f + ent.Comp2.ShuttleIndex, 0f)))
{
Log.Error($"Unable to spawn emergency shuttle {shuttlePath} for {ToPrettyString(ent)}");
return;

View File

@@ -72,17 +72,15 @@ public sealed partial class ShuttleSystem
_mapSystem.CreateMap(out var mapId);
if (_loader.TryLoad(mapId, component.Path.ToString(), out var ent) && ent.Count > 0)
if (_loader.TryLoadGrid(mapId, component.Path, out var ent))
{
if (HasComp<ShuttleComponent>(ent[0]))
{
TryFTLProximity(ent[0], targetGrid.Value);
}
if (HasComp<ShuttleComponent>(ent))
TryFTLProximity(ent.Value, targetGrid.Value);
_station.AddGridToStation(uid, ent[0]);
_station.AddGridToStation(uid, ent.Value);
}
_mapManager.DeleteMap(mapId);
_mapSystem.DeleteMap(mapId);
}
private bool TryDungeonSpawn(Entity<MapGridComponent?> targetGrid, DungeonSpawnGroup group, out EntityUid spawned)
@@ -143,20 +141,18 @@ public sealed partial class ShuttleSystem
var path = paths[^1];
paths.RemoveAt(paths.Count - 1);
if (_loader.TryLoad(mapId, path.ToString(), out var ent) && ent.Count == 1)
if (_loader.TryLoadGrid(mapId, path, out var grid))
{
if (HasComp<ShuttleComponent>(ent[0]))
{
TryFTLProximity(ent[0], targetGrid);
}
if (HasComp<ShuttleComponent>(grid))
TryFTLProximity(grid.Value, targetGrid);
if (group.NameGrid)
{
var name = path.FilenameWithoutExtension;
_metadata.SetEntityName(ent[0], name);
_metadata.SetEntityName(grid.Value, name);
}
spawned = ent[0];
spawned = grid.Value;
return true;
}
@@ -227,7 +223,7 @@ public sealed partial class ShuttleSystem
}
}
_mapManager.DeleteMap(mapId);
_mapSystem.DeleteMap(mapId);
}
private void OnGridFillMapInit(EntityUid uid, GridFillComponent component, MapInitEvent args)
@@ -246,23 +242,22 @@ public sealed partial class ShuttleSystem
_mapSystem.CreateMap(out var mapId);
var valid = false;
if (_loader.TryLoad(mapId, component.Path.ToString(), out var ent) &&
ent.Count == 1 &&
TryComp(ent[0], out TransformComponent? shuttleXform))
if (_loader.TryLoadGrid(mapId, component.Path, out var grid))
{
var escape = GetSingleDock(ent[0]);
var escape = GetSingleDock(grid.Value);
if (escape != null)
{
var config = _dockSystem.GetDockingConfig(ent[0], xform.GridUid.Value, escape.Value.Entity, escape.Value.Component, uid, dock);
var config = _dockSystem.GetDockingConfig(grid.Value, xform.GridUid.Value, escape.Value.Entity, escape.Value.Component, uid, dock);
if (config != null)
{
FTLDock((ent[0], shuttleXform), config);
var shuttleXform = Transform(grid.Value);
FTLDock((grid.Value, shuttleXform), config);
if (TryComp<StationMemberComponent>(xform.GridUid, out var stationMember))
{
_station.AddGridToStation(stationMember.Station, ent[0]);
_station.AddGridToStation(stationMember.Station, grid.Value);
}
valid = true;
@@ -273,11 +268,11 @@ public sealed partial class ShuttleSystem
{
var compType = compReg.Component.GetType();
if (HasComp(ent[0], compType))
if (HasComp(grid.Value, compType))
continue;
var comp = _factory.GetComponent(compType);
AddComp(ent[0], comp, true);
AddComp(grid.Value, comp, true);
}
}
@@ -286,7 +281,7 @@ public sealed partial class ShuttleSystem
Log.Error($"Error loading gridfill dock for {ToPrettyString(uid)} / {component.Path}");
}
_mapManager.DeleteMap(mapId);
_mapSystem.DeleteMap(mapId);
}
private (EntityUid Entity, DockingComponent Component)? GetSingleDock(EntityUid uid)

View File

@@ -17,6 +17,7 @@ using Robust.Server.GameStates;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Configuration;
using Robust.Shared.EntitySerialization.Systems;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Physics;