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>
96 lines
3.4 KiB
C#
96 lines
3.4 KiB
C#
using System;
|
|
|
|
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 path. 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.
|
|
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = true)]
|
|
public sealed class CultInspectorAssetPathAttribute : Attribute
|
|
{
|
|
public CultInspectorAssetPathAttribute(Type? assetType = null)
|
|
{
|
|
AssetType = assetType;
|
|
}
|
|
|
|
public Type? AssetType { get; }
|
|
}
|
|
|
|
// 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);
|
|
}
|
|
}
|