Delete the composite constructor heuristic from the inspector
Operator ruling: the heuristic that rebuilt unkeyed structs through a guessed constructor is removed, not guarded. Gone: the Composite value kind, CultInspectorShape.Composer, CultInspectorModel.Compose and Composite, the composite-component flag on CultInspectorMember, the IMGUI composite rebuild path, and the README text about it. An unkeyed struct is now edited in place through its public fields. A struct holding state it cannot write in place (a public readonly field or a get-only auto-property) is Unsupported with a reason naming the member, until a drawer claims it. Computed get-only properties are not state and do not lock a struct. The composite-rejection test goes with the heuristic; the replacement test pins both lock rules and fails with either removed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
2a46409017
commit
d03e376411
4 changed files with 53 additions and 117 deletions
|
|
@ -84,8 +84,6 @@ namespace GameCult.Unity.Caching.Editor
|
|||
case CultInspectorValueKind.Enum:
|
||||
var current = value as Enum ?? (Enum)Enum.ToObject(type, 0);
|
||||
return type.IsDefined(typeof(FlagsAttribute), false) ? EditorGUILayout.EnumFlagsField(label, current) : EditorGUILayout.EnumPopup(label, current);
|
||||
case CultInspectorValueKind.Composite:
|
||||
return DrawComposite(label, shape, value);
|
||||
case CultInspectorValueKind.RecordRef:
|
||||
return DrawRecordRef(label, type, value);
|
||||
case CultInspectorValueKind.List:
|
||||
|
|
@ -189,55 +187,6 @@ namespace GameCult.Unity.Caching.Editor
|
|||
}
|
||||
}
|
||||
|
||||
// Scalar components draw on one row; anything else folds out. A change composes a new value.
|
||||
private object DrawComposite(string label, CultInspectorShape shape, object value)
|
||||
{
|
||||
var path = _path;
|
||||
value = value ?? Model.CreateDefault(shape.Type);
|
||||
var components = shape.Members;
|
||||
var values = components.Select(component => component.GetValue(value)).ToArray();
|
||||
var changed = false;
|
||||
if (components.All(component => Model.ShapeOf(component.ValueType).Kind is CultInspectorValueKind.Float or CultInspectorValueKind.Integer or CultInspectorValueKind.Bool))
|
||||
{
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
EditorGUILayout.PrefixLabel(label);
|
||||
var indent = EditorGUI.indentLevel;
|
||||
var labelWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUI.indentLevel = 0;
|
||||
EditorGUIUtility.labelWidth = 8 + 7 * components.Max(component => component.Name.Length);
|
||||
for (var i = 0; i < components.Count; i++)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var next = DrawDefault(components[i].Name, components[i].ValueType, values[i], null);
|
||||
if (!EditorGUI.EndChangeCheck()) continue;
|
||||
values[i] = next;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
EditorGUIUtility.labelWidth = labelWidth;
|
||||
EditorGUI.indentLevel = indent;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!Foldout(path, label)) return value;
|
||||
EditorGUI.indentLevel++;
|
||||
for (var i = 0; i < components.Count; i++)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var next = DrawValue(LabelOf(components[i]), components[i].ValueType, values[i], components[i].Member, path + "." + components[i].Name);
|
||||
if (!EditorGUI.EndChangeCheck()) continue;
|
||||
values[i] = next;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
return changed ? Model.Compose(shape, values) : value;
|
||||
}
|
||||
|
||||
private object DrawRecordRef(string label, Type type, object value)
|
||||
{
|
||||
var key = CultInspectorModel.RecordKey(value);
|
||||
|
|
|
|||
|
|
@ -42,10 +42,10 @@ reloading scripts drops unsaved edits.
|
|||
in `GameCult.Caching`. Given a registry and the store's document codec it gives
|
||||
the member list of a type (registry catalog slots, `CultInspector*` metadata,
|
||||
whether a member is assignable), the shape of any value (string, integer,
|
||||
float, bool, enum, composite value rebuilt through its constructor,
|
||||
`CultRecordRef<T>` with its candidate records, rank-1 list or array,
|
||||
dictionary, `[Union]` with only its declared subtypes, nested keyed object, or
|
||||
unsupported with a reason), drawer claim resolution
|
||||
float, bool, enum, `CultRecordRef<T>` with its candidate records, rank-1 list
|
||||
or array, dictionary, `[Union]` with only its declared subtypes, nested keyed
|
||||
object, struct edited in place through its public fields, or unsupported with
|
||||
a reason), drawer claim resolution
|
||||
(`CultInspectorDrawerClaims`), dictionary key identity and refusal (null keys,
|
||||
empty record references and duplicates), and edits that work on a copy
|
||||
(`CultInspectorEdit`): a refused upsert leaves the cached object unchanged. The
|
||||
|
|
@ -55,11 +55,12 @@ the same documents under the same rules.
|
|||
|
||||
## Drawers
|
||||
|
||||
Built in: every model shape above. Composite values of scalars (`float2/3/4`,
|
||||
`int2`, `double2/3`, `bool2`, `quaternion`, `Color32`) draw as one row;
|
||||
`rect` folds out to its corners. Unity object references draw as object
|
||||
fields. A value no drawer claims and no shape covers shows a red error row, as
|
||||
does a multi-dimensional array.
|
||||
Built in: every model shape above. A struct without `[Key]` members folds out
|
||||
to its public fields and is edited in place; a struct with a readonly field or
|
||||
a get-only auto-property is unsupported until a drawer claims it. Unity object
|
||||
references draw as object fields. A value no drawer claims and no shape covers
|
||||
shows a red error row with the model's reason, as does a multi-dimensional
|
||||
array.
|
||||
|
||||
A project adds or overrides a drawer with an editor class. `Claimed` is either
|
||||
a value type (an open generic definition claims every closed form) or an
|
||||
|
|
|
|||
Loading…
Reference in a new issue