mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-15 23:02:34 +02:00
* Refactor map loading & saving * test fixes * ISerializationManager tweaks * Fix component composition * Try fix entity deserialization component composition * comments * CL * error preinit * a * cleanup * error if version is too new * Add AlwaysPushSerializationTest * Add auto-inclusion test * Better categorization * Combine test components * Save -> TrySave Also better handling for saving multiple entities individually * Create new partial class for map loading * Add OrphanSerializationTest * Include MapIds in BeforeSerializationEvent * Addd LifetimeSerializationTest * Add TestMixedLifetimeSerialization * Add CategorizationTest * explicitly serialize list of nullspace entities * Add backwards compatibility test * Version comments also fixes wrong v4 format * add MapMergeTest * Add NetEntity support * Optimize EntityDeserializer Avoid unnecessary component deserialization * fix assert & other bugs * fucking containers strike again * Fix deletion of pre-init entities * fix release note merge conflict * Update Robust.Shared/Map/MapManager.GridCollection.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * VV --------- Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
59 lines
2.0 KiB
C#
59 lines
2.0 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using NUnit.Framework;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Robust.UnitTesting.Shared.EntitySerialization;
|
|
|
|
[RegisterComponent]
|
|
public sealed partial class EntitySaveTestComponent : Component
|
|
{
|
|
/// <summary>
|
|
/// Give each entity a unique id to identify them across map saves & loads.
|
|
/// </summary>
|
|
[DataField] public string? Id;
|
|
|
|
[DataField] public EntityUid? Entity;
|
|
|
|
[DataField, AlwaysPushInheritance] public List<int> List = [];
|
|
|
|
/// <summary>
|
|
/// Find an entity with a <see cref="EntitySaveTestComponent"/> with the matching id.
|
|
/// </summary>
|
|
public static Entity<TransformComponent, EntitySaveTestComponent> Find(string id, IEntityManager entMan)
|
|
{
|
|
var ents = entMan.AllEntities<EntitySaveTestComponent>();
|
|
var matching = ents.Where(x => x.Comp.Id == id).ToArray();
|
|
Assert.That(matching, Has.Length.EqualTo(1));
|
|
return (matching[0].Owner, entMan.GetComponent<TransformComponent>(matching[0].Owner), matching[0].Comp);
|
|
}
|
|
|
|
public static Entity<TransformComponent, EntitySaveTestComponent> Get(EntityUid uid, IEntityManager entMan)
|
|
{
|
|
return new Entity<TransformComponent, EntitySaveTestComponent>(
|
|
uid,
|
|
entMan.GetComponent<TransformComponent>(uid),
|
|
entMan.EnsureComponent<EntitySaveTestComponent>(uid));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Dummy tile definition for serializing grids.
|
|
/// </summary>
|
|
public sealed class TileDef(string id) : ITileDefinition
|
|
{
|
|
public ushort TileId { get; set; }
|
|
public string Name => id;
|
|
public string ID => id;
|
|
public ResPath? Sprite => null;
|
|
public Dictionary<Direction, ResPath> EdgeSprites => new();
|
|
public int EdgeSpritePriority => 0;
|
|
public float Friction => 0;
|
|
public byte Variants => 0;
|
|
public void AssignTileId(ushort id) => TileId = id;
|
|
}
|