Give inspector drawers the record they sit in, read-only

A drawer saw only its value; Aetheria's schematic-shape drawer needs sibling
members of the owning document (texture path, aspect, hull tints).

The model owns the seam: CultInspectorEdit.Record is a second copy of the
stored document as the edit began, cloned on first read and kept for the
edit. The Studio lowers it as CultInspector.Record, so a runtime CultUI
panel gets the same seam from the same edit. The Draw signature is
unchanged, so existing drawers keep compiling.

Why not hand drawers the edit copy the Studio already draws: that copy is
what Commit upserts, so a write through it would be saved without passing
through the returned value, GUI.changed, or read-only metadata. The record
copy is read by nothing, so writing to it saves nothing and changes neither
the edit nor the cache. It does not show edits other drawers made earlier in
the same frame.

The Studio's separate document-type field collapses into the held edit.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-14 21:01:22 +02:00
commit 90e7dbee27
4 changed files with 35 additions and 7 deletions

View file

@ -238,14 +238,24 @@ namespace GameCult.Caching
// A private copy of one stored document. A lowering draws into Document; the cached object is never touched.
public sealed class CultInspectorEdit
{
internal CultInspectorEdit(CultStoredDocument source, object document)
private readonly Func<object> _snapshot;
private object? _record;
internal CultInspectorEdit(CultStoredDocument source, object document, Func<object> snapshot)
{
Source = source;
Document = document;
_snapshot = snapshot;
}
public CultStoredDocument Source { get; }
public object Document { get; }
// The record being drawn, as stored when this edit began, for drawers that read the document they sit in. It is a
// second copy, made on first read: not the cached object, and not Document, which a lowering commits. Nothing
// reads it back, so writing to it saves nothing and changes neither the edit nor the cache.
public object Record => _record ??= _snapshot();
public bool IsSpent { get; private set; }
public bool IsFor(CultStoredDocument record) => !IsSpent && ReferenceEquals(Source, record);
@ -342,7 +352,8 @@ namespace GameCult.Caching
public CultInspectorEdit BeginEdit(CultStoredDocument record)
{
if (record == null) throw new ArgumentNullException(nameof(record));
return new CultInspectorEdit(record, Clone(record.Document, record.Descriptor.DocumentType));
var type = record.Descriptor.DocumentType;
return new CultInspectorEdit(record, Clone(record.Document, type), () => Clone(record.Document, type));
}
// Whether CreateDefault makes a value: a string, struct, list or dictionary, or a concrete class with a parameterless constructor.