Files
RobustToolbox/Robust.Shared/Map/Events/MapSerializationEvents.cs
Leon Friedrich 64baee0a22 Add support for including map/game saves in replays. (#6189)
* Improve map serialization error logging

* Prevent remove children of erroring entities

* better logging

* Improve error tolerance

* Even more exception tolerance

* missing !

* Add WriteYaml and WriteObject to IReplayFileWriter

* Add MapLoaderSystem.TrySaveAllEntities()

* On second thought, WriteObject will just be abused

* I forgot to commit

* Add default implementation to avoid breaking changes

* release notes

* fix merge issues

---------

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2025-11-13 22:14:56 +11:00

46 lines
2.1 KiB
C#

using System.Collections.Generic;
using Robust.Shared.EntitySerialization;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Markdown.Mapping;
namespace Robust.Shared.Map.Events;
/// <summary>
/// This event is broadcast just before the map loader reads the entity section. It can be used to somewhat modify
/// how the map data is read, as a super basic kind of map migration tool.
/// </summary>
public sealed class BeforeEntityReadEvent
{
/// <summary>
/// Set of deleted entity prototypes.
/// </summary>
/// <remarks>
/// While reading the map, these entities will be treated as if they have no prototype. After the map has been
/// loaded, these entities will get deleted. This is so that entities parented to this entity (e.g., stored in
/// containers) also get deleted, instead of just causing errors. Note that this has not been properly tested is
/// quite likely to cause unexpected errors and should be used with care.
/// </remarks>
public readonly HashSet<string> DeletedPrototypes = new();
/// <summary>
/// This dictionary maps old entity prototype IDs to some new value. As with <see cref="DeletedPrototypes"/>, this
/// might cause unexpected errors, user beware.
/// </summary>
public readonly Dictionary<string, string> RenamedPrototypes = new();
}
/// <summary>
/// This event is broadcast just before the given entities (and their children) are serialized.
/// For convenience, the event also contains a set with all the maps that the entities are on. This does not
/// necessarily mean that the maps are themselves getting serialized.
/// </summary>
public readonly record struct BeforeSerializationEvent(
HashSet<EntityUid> Entities,
HashSet<MapId> MapIds,
FileCategory Category = FileCategory.Unknown);
/// <summary>
/// This event is broadcast just after entities (and their children) have been serialized, but before it gets written to a yaml file.
/// </summary>
public readonly record struct AfterSerializationEvent(HashSet<EntityUid> Entities, MappingDataNode Node, FileCategory Category);