Check the declared type when a graph writes a typed variable (#271)
A list variable with an item type only kept its shape in the editor. A graph could write any list into it at runtime, and the List node had no type at all. Now the declaration decides what a write may store. - Writing a list into a typed list variable leaves out every item that does not have exactly the fields of the type. The rest is written and the console names each item that was left out, like Add item does. - The same rule holds for typed list fields inside a struct variable and for lists inside typed items, at any depth. - A typed struct variable refuses a struct with a field the type does not have, and a value that is no struct. A struct with missing fields still merges in as before, so a partial Pack keeps working. - The check runs in the Variables node (own variables and Variables assets) and in the Properties node when it sets a behavior variable of another object. - Ports learn their declaration through GraphLookup: what a variable declares about its type, and which behavior owns a graph. The rule itself lives in the new src/core/graph/typedValues.ts, fitsType moved there from SetItem. - The List node gets a Type setting. With a type its items are shaped and marked, follow the struct asset, count when the type is deleted and offer Split into fields in For each. The mark never reaches the running game. - A type on a List node holding something other than structs is refused with a console line. - Setting the List node back to None removes the marks, unlike a list variable. A node list has no per-item type row, so marked items could never be freed there. Undo brings everything back. - tests/core/kinds.test.ts looked for the value as the first parameter of a literal. Type now comes first on the List node, so the test finds the value by its key. Tests: - Gate: 198 files, 2869 tests (2856 + 13), CHECK EXIT 0 - e2e 55: 19 checks (+55j write at runtime, +2 for 55k List node) - e2e 54: 16 checks, smokes 24 / 19 / 21 - Five mutations, each fails between 1 and 4 tests - e2e total 1606 is computed (1603 + 3), no full run Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f2282a81fb
commit
0f6e628616
19 files changed
+682
-52
No files matched your search
@@ -27,8 +27,14 @@ import type { GraphAsset } from '../../core/model/Asset';
|
||||
import { graphLookup } from '../../core/model/graphLookup';
|
||||
import { findGraphAsset, type Project } from '../../core/model/Project';
|
||||
import { type PropertyValue, textOf } from '../../core/model/Properties';
|
||||
import { isTypedNode, nodeStructType, structAssetOf } from '../../core/model/structTypes';
|
||||
import { SetStructTypeCommand } from '../../core/commands/structTypeCommands';
|
||||
import {
|
||||
isListNode,
|
||||
isTypedNode,
|
||||
listNodeItemType,
|
||||
nodeStructType,
|
||||
structAssetOf,
|
||||
} from '../../core/model/structTypes';
|
||||
import { SetListNodeTypeCommand, SetStructTypeCommand } from '../../core/commands/structTypeCommands';
|
||||
import type { PropertyDef } from '../../core/properties/PropertySchema';
|
||||
import { Label } from '../../ui';
|
||||
import { createFieldRow, type FieldHandlers } from './fieldFactory';
|
||||
@@ -67,8 +73,9 @@ export function nodeSignature(project: Project, assetId: string, nodeId: string)
|
||||
.join(',')
|
||||
: `${textOf(node.params[TRANSITION_PARAM] ?? '')}:${textOf(node.params[MACHINE_PORT] ?? '')}`;
|
||||
// The source names which declarations the port menu offers, so switching it has to rebuild.
|
||||
const typeName = structAssetOf(project, nodeStructType(node))?.name ?? '';
|
||||
const source = `${variablesSourceOf(node.params)}:${nodeStructType(node)}:${typeName}`;
|
||||
const typeId = nodeStructType(node) || listNodeItemType(node);
|
||||
const typeName = structAssetOf(project, typeId)?.name ?? '';
|
||||
const source = `${variablesSourceOf(node.params)}:${typeId}:${typeName}`;
|
||||
const choices = variableChoices(project, assetId, node)
|
||||
.map((v) => v.key)
|
||||
.join(',');
|
||||
@@ -116,6 +123,9 @@ export function buildNodeSection(host: InspectorHost, assetId: string, nodeId: s
|
||||
};
|
||||
addSetting(STRUCT_TYPE_SETTING, { onInput: () => {}, onChange: pick });
|
||||
}
|
||||
// A List node's type reshapes its items (#271), which is no plain param edit either.
|
||||
const pickItemType = (value: PropertyValue) =>
|
||||
host.state.execute(new SetListNodeTypeCommand(assetId, nodeId, textOf(value)));
|
||||
if (declaresVariablePorts(node.type)) buildVariablePortSection(host, assetId, node, addSetting);
|
||||
else if (ownSettings) buildPropertyPortSection(host, assetId, node, addSetting);
|
||||
else if (def.declaresPorts) {
|
||||
@@ -129,6 +139,8 @@ export function buildNodeSection(host: InspectorHost, assetId: string, nodeId: s
|
||||
for (const param of settings) {
|
||||
if (param.key === TRANSITION_PARAM && node.type === STATE_TRANSITION)
|
||||
buildTransitionPicker(host, assetId, node, asset.graph);
|
||||
else if (param.key === STRUCT_TYPE_PARAM && isListNode(node))
|
||||
addSetting(param, { onInput: () => {}, onChange: pickItemType });
|
||||
else addSetting(param);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user