Files
Nerfed/Nerfed.Runtime/Scene/SceneData.cs
T
max fec2cd8d24 testing building some core systems
- serialization
- chunks
- parralelfor test
2026-04-24 19:21:03 +02:00

66 lines
2.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
namespace Nerfed.Runtime.Scene;
/// <summary>
/// Root data model for a scene. A scene and a prefab are the same thing —
/// there is no distinction between the two, mirroring Godot's design.
/// </summary>
public sealed class SceneData
{
/// <summary>Incremented when the file format changes in a breaking way.</summary>
public int Version { get; set; } = SceneData.CurrentVersion;
public string Name { get; set; } = string.Empty;
public List<SceneEntityData> Entities { get; set; } = new();
/// <summary>All user-defined relations between entities in this scene.</summary>
public List<SceneRelationData> Relations { get; set; } = new();
public const int CurrentVersion = 1;
}
/// <summary>
/// Serialized representation of a single entity.
/// The <see cref="Id"/> is a scene-local identifier that only exists in the
/// serialized data and is used to reconstruct parentchild and relation references.
/// It is never stored as a component on a live entity.
/// An entity is included if it owns at least one <see cref="SceneComponentAttribute"/> component
/// OR participates in at least one <see cref="SceneRelationAttribute"/> relation.
/// </summary>
public sealed class SceneEntityData
{
public Guid Id { get; set; } = Guid.NewGuid();
public string Tag { get; set; } = string.Empty;
/// <summary>
/// Scene-local <see cref="Id"/> of this entity's <see cref="Components.ChildParentRelation"/>
/// parent, or <c>null</c> if this is a root entity.
/// </summary>
public Guid? ParentId { get; set; }
public List<SceneComponentData> Components { get; set; } = new();
}
/// <summary>
/// Serialized representation of a single component value on an entity.
/// <see cref="Type"/> is the fully-qualified CLR type name used to resolve the component on load.
/// <see cref="Value"/> is the boxed runtime value; each <see cref="ISceneSerializer"/> is
/// responsible for converting it to/from its wire format.
/// </summary>
public sealed class SceneComponentData
{
public string Type { get; set; } = string.Empty;
public ValueType Value { get; set; } = default!;
}
/// <summary>
/// Serialized representation of a relation between two entities.
/// <see cref="EntityA"/> and <see cref="EntityB"/> reference scene-local <see cref="SceneEntityData.Id"/> values.
/// <see cref="Type"/> identifies the relation kind (must be marked with <see cref="SceneRelationAttribute"/>).
/// <see cref="Value"/> holds the relation data payload (may be an empty struct).
/// </summary>
public sealed class SceneRelationData
{
public string Type { get; set; } = string.Empty;
public Guid EntityA { get; set; }
public Guid EntityB { get; set; }
public ValueType Value { get; set; } = default!;
}