CultLib/src/GameCult.Caching/CultInspectorAttributes.cs

113 lines
4.4 KiB
C#
Raw Normal View History

Add the engine-free CultCache inspection model The CultInspector* attributes move from the Unity-only GameCult.Unity.Caching runtime assembly into GameCult.Caching, so headless shared models carry them. CultInspectorAssetPath keeps a System.Type the consumer names. CultInspectorDrawer claims either a value type (open generic definitions claim every closed form) or an Attribute subclass. CultInspectorModel owns what an inspector shows and which edits it may make, with no engine reference: - members: registry catalog slots for documents, [Key] slots for other MessagePack objects, public fields for unkeyed structs; Label, Hidden, ReadOnly, Order, Range, TextArea and AssetPath metadata; assignability by the rule the registry persists by. - shapes: string, integer, float, bool, enum, composite (an unkeyed value type rebuilt through the constructor whose parameters match its members, which covers the CultMath vectors, rect and Color32 without naming them), CultRecordRef<T> with candidate records, rank-1 list or array, dictionary, union limited to declared [Union] subtypes, nested, and unsupported with a reason (multi-dimensional arrays included). - CultInspectorDrawerClaims: attribute claims, then type claims, then built-in; invalid drawers and contested claims are errors and draw nothing. - dictionary keys by serialized identity (a record reference by its key string, null and "" alike), refusal of null, empty-reference and duplicate keys, fresh keys, and collections rebuilt as new instances. - CultInspectorEdit: a codec clone of the stored document; Commit upserts the copy, so a refused upsert leaves the cached object unchanged. ICultRecordRef exposes CultRecordRef<T>.Key without T, replacing the Studio's by-name GetProperty lookup. Tests (CultInspectorModelTests): member list and metadata, claim resolution order, declared-only union choices, record-reference candidates, dictionary key refusal, refused commit leaving the cached document unchanged, and shape classification. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 13:43:45 +02:00
using System;
using System.Collections.Generic;
Add the engine-free CultCache inspection model The CultInspector* attributes move from the Unity-only GameCult.Unity.Caching runtime assembly into GameCult.Caching, so headless shared models carry them. CultInspectorAssetPath keeps a System.Type the consumer names. CultInspectorDrawer claims either a value type (open generic definitions claim every closed form) or an Attribute subclass. CultInspectorModel owns what an inspector shows and which edits it may make, with no engine reference: - members: registry catalog slots for documents, [Key] slots for other MessagePack objects, public fields for unkeyed structs; Label, Hidden, ReadOnly, Order, Range, TextArea and AssetPath metadata; assignability by the rule the registry persists by. - shapes: string, integer, float, bool, enum, composite (an unkeyed value type rebuilt through the constructor whose parameters match its members, which covers the CultMath vectors, rect and Color32 without naming them), CultRecordRef<T> with candidate records, rank-1 list or array, dictionary, union limited to declared [Union] subtypes, nested, and unsupported with a reason (multi-dimensional arrays included). - CultInspectorDrawerClaims: attribute claims, then type claims, then built-in; invalid drawers and contested claims are errors and draw nothing. - dictionary keys by serialized identity (a record reference by its key string, null and "" alike), refusal of null, empty-reference and duplicate keys, fresh keys, and collections rebuilt as new instances. - CultInspectorEdit: a codec clone of the stored document; Commit upserts the copy, so a refused upsert leaves the cached object unchanged. ICultRecordRef exposes CultRecordRef<T>.Key without T, replacing the Studio's by-name GetProperty lookup. Tests (CultInspectorModelTests): member list and metadata, claim resolution order, declared-only union choices, record-reference candidates, dictionary key refusal, refused commit leaving the cached document unchanged, and shape classification. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 13:43:45 +02:00
namespace GameCult.Caching
{
// Inspection metadata for document members. Engine-free: headless models carry it, and every inspector lowering
// (the Unity editor Studio, a runtime CultUI panel) reads it through CultInspectorModel.
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Class, Inherited = true)]
public sealed class CultInspectorLabelAttribute : Attribute
{
public CultInspectorLabelAttribute(string label)
{
Label = label ?? string.Empty;
}
public string Label { get; }
}
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = true)]
public sealed class CultInspectorHiddenAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = true)]
public sealed class CultInspectorReadOnlyAttribute : Attribute
{
}
// Lower values appear first; members without it keep their slot order.
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = true)]
public sealed class CultInspectorOrderAttribute : Attribute
{
public CultInspectorOrderAttribute(int order)
{
Order = order;
}
public int Order { get; }
}
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = true)]
public sealed class CultInspectorTextAreaAttribute : Attribute
{
public CultInspectorTextAreaAttribute(int minLines = 3, int maxLines = 12)
{
MinLines = minLines;
MaxLines = maxLines;
}
public int MinLines { get; }
public int MaxLines { get; }
}
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = true)]
public sealed class CultInspectorRangeAttribute : Attribute
{
public CultInspectorRangeAttribute(float min, float max)
{
Min = min;
Max = max;
}
public float Min { get; }
public float Max { get; }
}
// A string member holding an engine asset's stable identity; in Unity, the `.meta` GUID. AssetType is the
// engine's asset type, named by the consumer (typeof(UnityEngine.Texture2D) in a Unity assembly); a lowering
// that does not know the type ignores it.
Add the engine-free CultCache inspection model The CultInspector* attributes move from the Unity-only GameCult.Unity.Caching runtime assembly into GameCult.Caching, so headless shared models carry them. CultInspectorAssetPath keeps a System.Type the consumer names. CultInspectorDrawer claims either a value type (open generic definitions claim every closed form) or an Attribute subclass. CultInspectorModel owns what an inspector shows and which edits it may make, with no engine reference: - members: registry catalog slots for documents, [Key] slots for other MessagePack objects, public fields for unkeyed structs; Label, Hidden, ReadOnly, Order, Range, TextArea and AssetPath metadata; assignability by the rule the registry persists by. - shapes: string, integer, float, bool, enum, composite (an unkeyed value type rebuilt through the constructor whose parameters match its members, which covers the CultMath vectors, rect and Color32 without naming them), CultRecordRef<T> with candidate records, rank-1 list or array, dictionary, union limited to declared [Union] subtypes, nested, and unsupported with a reason (multi-dimensional arrays included). - CultInspectorDrawerClaims: attribute claims, then type claims, then built-in; invalid drawers and contested claims are errors and draw nothing. - dictionary keys by serialized identity (a record reference by its key string, null and "" alike), refusal of null, empty-reference and duplicate keys, fresh keys, and collections rebuilt as new instances. - CultInspectorEdit: a codec clone of the stored document; Commit upserts the copy, so a refused upsert leaves the cached object unchanged. ICultRecordRef exposes CultRecordRef<T>.Key without T, replacing the Studio's by-name GetProperty lookup. Tests (CultInspectorModelTests): member list and metadata, claim resolution order, declared-only union choices, record-reference candidates, dictionary key refusal, refused commit leaving the cached document unchanged, and shape classification. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 13:43:45 +02:00
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = true)]
public sealed class CultInspectorAssetGuidAttribute : Attribute
Add the engine-free CultCache inspection model The CultInspector* attributes move from the Unity-only GameCult.Unity.Caching runtime assembly into GameCult.Caching, so headless shared models carry them. CultInspectorAssetPath keeps a System.Type the consumer names. CultInspectorDrawer claims either a value type (open generic definitions claim every closed form) or an Attribute subclass. CultInspectorModel owns what an inspector shows and which edits it may make, with no engine reference: - members: registry catalog slots for documents, [Key] slots for other MessagePack objects, public fields for unkeyed structs; Label, Hidden, ReadOnly, Order, Range, TextArea and AssetPath metadata; assignability by the rule the registry persists by. - shapes: string, integer, float, bool, enum, composite (an unkeyed value type rebuilt through the constructor whose parameters match its members, which covers the CultMath vectors, rect and Color32 without naming them), CultRecordRef<T> with candidate records, rank-1 list or array, dictionary, union limited to declared [Union] subtypes, nested, and unsupported with a reason (multi-dimensional arrays included). - CultInspectorDrawerClaims: attribute claims, then type claims, then built-in; invalid drawers and contested claims are errors and draw nothing. - dictionary keys by serialized identity (a record reference by its key string, null and "" alike), refusal of null, empty-reference and duplicate keys, fresh keys, and collections rebuilt as new instances. - CultInspectorEdit: a codec clone of the stored document; Commit upserts the copy, so a refused upsert leaves the cached object unchanged. ICultRecordRef exposes CultRecordRef<T>.Key without T, replacing the Studio's by-name GetProperty lookup. Tests (CultInspectorModelTests): member list and metadata, claim resolution order, declared-only union choices, record-reference candidates, dictionary key refusal, refused commit leaving the cached document unchanged, and shape classification. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 13:43:45 +02:00
{
public CultInspectorAssetGuidAttribute(Type? assetType = null)
Add the engine-free CultCache inspection model The CultInspector* attributes move from the Unity-only GameCult.Unity.Caching runtime assembly into GameCult.Caching, so headless shared models carry them. CultInspectorAssetPath keeps a System.Type the consumer names. CultInspectorDrawer claims either a value type (open generic definitions claim every closed form) or an Attribute subclass. CultInspectorModel owns what an inspector shows and which edits it may make, with no engine reference: - members: registry catalog slots for documents, [Key] slots for other MessagePack objects, public fields for unkeyed structs; Label, Hidden, ReadOnly, Order, Range, TextArea and AssetPath metadata; assignability by the rule the registry persists by. - shapes: string, integer, float, bool, enum, composite (an unkeyed value type rebuilt through the constructor whose parameters match its members, which covers the CultMath vectors, rect and Color32 without naming them), CultRecordRef<T> with candidate records, rank-1 list or array, dictionary, union limited to declared [Union] subtypes, nested, and unsupported with a reason (multi-dimensional arrays included). - CultInspectorDrawerClaims: attribute claims, then type claims, then built-in; invalid drawers and contested claims are errors and draw nothing. - dictionary keys by serialized identity (a record reference by its key string, null and "" alike), refusal of null, empty-reference and duplicate keys, fresh keys, and collections rebuilt as new instances. - CultInspectorEdit: a codec clone of the stored document; Commit upserts the copy, so a refused upsert leaves the cached object unchanged. ICultRecordRef exposes CultRecordRef<T>.Key without T, replacing the Studio's by-name GetProperty lookup. Tests (CultInspectorModelTests): member list and metadata, claim resolution order, declared-only union choices, record-reference candidates, dictionary key refusal, refused commit leaving the cached document unchanged, and shape classification. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 13:43:45 +02:00
{
AssetType = assetType;
}
public Type? AssetType { get; }
}
// Groups a document type's record list by the named members, outermost first: the argument order is the nesting order.
// The nearest declaration up the inheritance chain wins, so a derived type may re-declare, and an empty declaration
// opts out of a base's. A member must be a visible, editable string, integer, bool, non-[Flags] enum or CultRecordRef;
// anything else gives a flat list and a notice. Presentation only: no schema, index or stored byte changes.
[AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = false)]
public sealed class CultInspectorGroupByAttribute : Attribute
{
public CultInspectorGroupByAttribute(params string[] members)
{
Members = members ?? throw new ArgumentNullException(nameof(members));
}
public IReadOnlyList<string> Members { get; }
}
Add the engine-free CultCache inspection model The CultInspector* attributes move from the Unity-only GameCult.Unity.Caching runtime assembly into GameCult.Caching, so headless shared models carry them. CultInspectorAssetPath keeps a System.Type the consumer names. CultInspectorDrawer claims either a value type (open generic definitions claim every closed form) or an Attribute subclass. CultInspectorModel owns what an inspector shows and which edits it may make, with no engine reference: - members: registry catalog slots for documents, [Key] slots for other MessagePack objects, public fields for unkeyed structs; Label, Hidden, ReadOnly, Order, Range, TextArea and AssetPath metadata; assignability by the rule the registry persists by. - shapes: string, integer, float, bool, enum, composite (an unkeyed value type rebuilt through the constructor whose parameters match its members, which covers the CultMath vectors, rect and Color32 without naming them), CultRecordRef<T> with candidate records, rank-1 list or array, dictionary, union limited to declared [Union] subtypes, nested, and unsupported with a reason (multi-dimensional arrays included). - CultInspectorDrawerClaims: attribute claims, then type claims, then built-in; invalid drawers and contested claims are errors and draw nothing. - dictionary keys by serialized identity (a record reference by its key string, null and "" alike), refusal of null, empty-reference and duplicate keys, fresh keys, and collections rebuilt as new instances. - CultInspectorEdit: a codec clone of the stored document; Commit upserts the copy, so a refused upsert leaves the cached object unchanged. ICultRecordRef exposes CultRecordRef<T>.Key without T, replacing the Studio's by-name GetProperty lookup. Tests (CultInspectorModelTests): member list and metadata, claim resolution order, declared-only union choices, record-reference candidates, dictionary key refusal, refused commit leaving the cached document unchanged, and shape classification. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 13:43:45 +02:00
// Marks a lowering's drawer class as the drawer for a claimed type. Claimed is either an Attribute subclass (the
// drawer draws every member carrying that attribute) or a value type (every value of that type, or of any closed
// form when Claimed is an open generic definition). Attribute claims win over type claims, which win over the
// built-in kinds. A claim two drawers make is used by neither.
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public sealed class CultInspectorDrawerAttribute : Attribute
{
public CultInspectorDrawerAttribute(Type claimed)
{
Claimed = claimed ?? throw new ArgumentNullException(nameof(claimed));
}
public Type Claimed { get; }
public bool ClaimsAttribute => typeof(Attribute).IsAssignableFrom(Claimed);
}
}