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

@@ -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)