mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Fix MapLoaderSystem.SerializeEntitiesRecursive (#6246)
* Fix MapLoaderSystem.SerializeEntitiesRecursive * a * oops
This commit is contained in:
@@ -45,6 +45,7 @@ END TEMPLATE-->
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* Fixed `MapLoaderSystem.SerializeEntitiesRecursive()` not properly serialising when given multiple root entities (e.g., multiple maps)
|
||||
* Fixed yaml hot reloading throwing invalid path exceptions.
|
||||
* The `EntityManager.CreateEntityUninitialized` overload that uses MapCoordinates now actually attaches entities to a grid if one is present at those coordinates, as was stated in it's documentation.
|
||||
* Fixed physics joint relays not being properly updated when an entity is removed from a container.
|
||||
|
||||
@@ -253,6 +253,42 @@ public sealed class EntitySerializer : ISerializationContext,
|
||||
Truncate = EntityUid.Invalid;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes several entities and all of their children. Note that this will not automatically serialize the
|
||||
/// entity's parents.
|
||||
/// </summary>
|
||||
public void SerializeEntityRecursive(HashSet<EntityUid> roots)
|
||||
{
|
||||
if (roots.Count == 0)
|
||||
return;
|
||||
|
||||
InitializeTileMap(roots.First());
|
||||
|
||||
HashSet<EntityUid> allEntities = new();
|
||||
List<(EntityUid Root, HashSet<EntityUid> Children)> entities = new();
|
||||
|
||||
foreach(var root in roots)
|
||||
{
|
||||
if (!IsSerializable(root))
|
||||
throw new Exception($"{EntMan.ToPrettyString(root)} is not serializable");
|
||||
|
||||
var ents = new HashSet<EntityUid>();
|
||||
RecursivelyIncludeChildren(root, ents);
|
||||
entities.Add((root, ents));
|
||||
allEntities.UnionWith(ents);
|
||||
}
|
||||
|
||||
ReserveYamlIds(allEntities);
|
||||
|
||||
foreach (var (root, children) in entities)
|
||||
{
|
||||
Truncate = _xformQuery.GetComponent(root).ParentUid;
|
||||
Truncated.Add(Truncate);
|
||||
SerializeEntitiesInternal(children);
|
||||
Truncate = EntityUid.Invalid;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -16,7 +16,7 @@ public sealed partial class MapLoaderSystem
|
||||
public event EntitySerializer.IsSerializableDelegate? OnIsSerializable;
|
||||
|
||||
/// <summary>
|
||||
/// Recursively serialize the given entity and its children.
|
||||
/// Recursively serialize the given entities and all of their children.
|
||||
/// </summary>
|
||||
public (MappingDataNode Node, FileCategory Category) SerializeEntitiesRecursive(
|
||||
HashSet<EntityUid> entities,
|
||||
@@ -41,12 +41,7 @@ public sealed partial class MapLoaderSystem
|
||||
|
||||
var serializer = new EntitySerializer(_dependency, opts);
|
||||
serializer.OnIsSerializeable += OnIsSerializable;
|
||||
|
||||
foreach (var ent in entities)
|
||||
{
|
||||
serializer.SerializeEntityRecursive(ent);
|
||||
}
|
||||
|
||||
serializer.SerializeEntityRecursive(entities);
|
||||
var data = serializer.Write();
|
||||
var cat = serializer.GetCategory();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user