Skip to content

Commit 15f94bd

Browse files
authored
Fix mapinit persistence when overwriting existing maps (#5057)
* Fix mapinit persistence when overwriting existing maps * Hours wasted chasing fucking chickens in a crate
1 parent 68888c4 commit 15f94bd

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

‎Robust.Server/GameObjects/EntitySystems/MapLoaderSystem.cs‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public sealed class MapLoaderSystem : EntitySystem
4949
private ISawmill _logLoader = default!;
5050
private ISawmill _logWriter = default!;
5151

52-
private static readonly MapLoadOptions DefaultLoadOptions = new();
5352
private const int MapFormatVersion = 6;
5453
private const int BackwardsVersion = 2;
5554

@@ -132,7 +131,7 @@ public void Load(MapId mapId, string path, MapLoadOptions? options = null)
132131
public bool TryLoad(MapId mapId, string path, [NotNullWhen(true)] out IReadOnlyList<EntityUid>? rootUids,
133132
MapLoadOptions? options = null)
134133
{
135-
options ??= DefaultLoadOptions;
134+
options ??= new();
136135

137136
var resPath = new ResPath(path).ToRootedPath();
138137

@@ -663,6 +662,7 @@ private void SwapRootNode(MapData data)
663662
// If map exists swap out
664663
if (_mapSystem.TryGetMap(data.TargetMap, out var existing))
665664
{
665+
data.Options.DoMapInit |= _mapSystem.IsInitialized(data.TargetMap);
666666
data.MapIsPaused = _mapSystem.IsPaused(existing.Value);
667667
// Map exists but we also have a map file with stuff on it soooo swap out the old map.
668668
if (data.Options.LoadMap)
@@ -887,8 +887,7 @@ private void StartupEntity(EntityUid uid, MetaDataComponent metadata, MapData da
887887
{
888888
EntityManager.SetLifeStage(metadata, EntityLifeStage.MapInitialized);
889889
}
890-
// TODO MAP LOAD cache this
891-
else if (_mapManager.IsMapInitialized(data.TargetMap))
890+
else if (data.Options.DoMapInit)
892891
{
893892
_serverEntityManager.RunMapInit(uid, metadata);
894893
}
@@ -1090,17 +1089,17 @@ private void PopulateEntityList(EntityUid uid, List<EntityUid> entities, Diction
10901089
}
10911090
}
10921091

1093-
private bool IsSaveable(EntityUid uid, EntityQuery<MetaDataComponent> metaQuery, EntityQuery<TransformComponent> transformQuery)
1092+
private bool IsSaveable(EntityUid uid)
10941093
{
10951094
// Don't serialize things parented to un savable things.
10961095
// For example clothes inside a person.
10971096
while (uid.IsValid())
10981097
{
1099-
var meta = metaQuery.GetComponent(uid);
1098+
var meta = MetaData(uid);
11001099

11011100
if (meta.EntityDeleted || meta.EntityPrototype?.MapSavable == false) break;
11021101

1103-
uid = transformQuery.GetComponent(uid).ParentUid;
1102+
uid = Transform(uid).ParentUid;
11041103
}
11051104

11061105
// If we manage to get up to the map (root node) then it's saveable.
@@ -1115,7 +1114,7 @@ private void RecursivePopulate(EntityUid uid,
11151114
EntityQuery<TransformComponent> transformQuery,
11161115
EntityQuery<MapSaveIdComponent> saveCompQuery)
11171116
{
1118-
if (!IsSaveable(uid, metaQuery, transformQuery))
1117+
if (!IsSaveable(uid))
11191118
return;
11201119

11211120
entities.Add(uid);

‎Robust.Server/Maps/MapLoadOptions.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,7 @@ public Angle Rotation
5353
/// This should be set to false if you want to load a map file onto an existing map and do not wish to overwrite the existing entity.
5454
/// </remarks>
5555
public bool LoadMap { get; set; } = true;
56+
57+
public bool DoMapInit = false;
5658
}
5759
}

0 commit comments

Comments
 (0)