Give a behavior more ways in and out, and hear it as an event (#294)
A behavior run by another one had a single flow port at its Start and at its End, so it could not branch for its caller. And it could not be used as an event: a call needs a pulse at its flow input, and the events of a called graph never fire. An input like "Confirm" (Space or Enter) had to be built again in every graph. - A declared port of a Start or an End node can be of the kind Flow. It sits above the values and shares their names, exec stays reserved. Only these two nodes declare one, a struct does not. - Run behavior shows a flow port of the Start as a further flow input. A call arriving through it leaves the Start through the output of that name and not through exec. - Run behavior shows a flow port of the End as a further flow output. The call goes on through the one the End was reached by last, and then through exec. exec fires always, as before. - On behavior is a new event node without a flow input. The behavior it names runs at the node for as long as the behavior around it runs, with all of its own events and one set of variables per node. - Its outputs are those of the End. It fires once the inner pulse is through, by the output the End was reached by last, exec only for End.exec. A pulse that never reaches the End is not seen. - The value ports of the Start are its inputs, read anew for each inner pulse. The Start itself never fires there. - It nests to any depth. Under a Run behavior it stays silent. A behavior hearing itself, however far round, is not started and the node says "A behavior cannot listen to itself". - The palette offers every other behavior with an End once more as "On <name>". A node naming one without End says so. - An On node removed while the game runs ends its behavior with On disable and On destroy. The sounds of the entity end only with the behavior placed on it. - Renaming and deleting a declared port follows the edges at On behavior nodes as it does at Run behavior nodes. - The flow outputs of the Start of a behavior placed on an object never fire, like its exec. - The engine prompt of the benchmark names flow ports and On behavior. Tests: - Gate on melektaus-atx right before this commit: 215 files, 3319 tests (3278 + 41), exit 0. - e2e 19 on melektaus-atx: 39 checks (+4), all pass. e2e 1-6,17-24,26,36,51: 628 checks, all pass. - 19 unit tests in flow-ports.test.ts, 19 in on-behavior.test.ts on a real world, the rest in the node catalog. - Four new e2e checks in module 19: a flow port declared by mouse at the End, On Confirm in the graph, the call leaving through the further output while playing, Enter and Space on a real keyboard. - 19 unit counter-probes all fail their tests. One did not at first (a removed node kept its instance), a test was added. Two browser counter-probes fail their checks. - One screenshot looked at: On Confirm with exec and pressed, the second flow pin at the calling node. - The e2e sum of 1680 is counted (1676 + 4), the full suite and the smokes did not run. - Not seen in the browser: flow inputs at the Start, nesting, the ring, values through On behavior, the palette entry. No test holds that the sounds of the entity go on when a heard behavior ends. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b5339b96c2
commit
46c620ae3b
26 files changed
+1211
-42
No files matched your search
@@ -9,7 +9,7 @@ import {
|
||||
findNode,
|
||||
type GraphNode,
|
||||
nodeDef,
|
||||
RUN_BEHAVIOR,
|
||||
namesBehavior,
|
||||
} from '../core/graph';
|
||||
import type { GraphAsset } from '../core/model/Asset';
|
||||
import { type Clip, copyGraph, copyObjects, type GraphClip, type ObjectClip } from '../core/model/clipboard';
|
||||
@@ -160,7 +160,7 @@ function fitsGraph(project: Project, asset: GraphAsset, node: GraphNode): boolea
|
||||
return paletteEntries(project, asset).some(
|
||||
(entry) =>
|
||||
entry.def.type === node.type &&
|
||||
(node.type !== RUN_BEHAVIOR || entry.params[BEHAVIOR_PARAM] === node.params[BEHAVIOR_PARAM]),
|
||||
(!namesBehavior(node.type) || entry.params[BEHAVIOR_PARAM] === node.params[BEHAVIOR_PARAM]),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
type PortDef,
|
||||
type PortSide,
|
||||
resolveDef,
|
||||
namesBehavior,
|
||||
RUN_BEHAVIOR,
|
||||
startStateOf,
|
||||
} from '../../core/graph';
|
||||
@@ -627,7 +628,7 @@ export class GraphCanvas extends Widget {
|
||||
}
|
||||
|
||||
private openCalledBehavior(node: GraphNode): boolean {
|
||||
if (node.type !== RUN_BEHAVIOR) return false;
|
||||
if (!namesBehavior(node.type)) return false;
|
||||
const id = textOf(node.params[BEHAVIOR_PARAM] ?? '');
|
||||
const asset = id ? findAsset(this.state.project, id) : undefined;
|
||||
if (asset?.type !== 'behavior') return false;
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import { searchRank } from '../../ui/search';
|
||||
import {
|
||||
allNodeDefs,
|
||||
BEHAVIOR_END,
|
||||
BEHAVIOR_PARAM,
|
||||
createEmptyGraph,
|
||||
isTerminalType,
|
||||
namesBehavior,
|
||||
nextStateName,
|
||||
type NodeCategory,
|
||||
type NodeDef,
|
||||
ON_BEHAVIOR,
|
||||
resolveDef,
|
||||
RUN_BEHAVIOR,
|
||||
State,
|
||||
@@ -83,7 +86,8 @@ function filterEntry(find: NodeDef): PaletteEntry {
|
||||
* The node types offerable in `asset`'s graph. A state machine holds states and nothing else, each
|
||||
* new one named by its number; a shader holds shader nodes, its one Output dropping out once
|
||||
* placed. In a behavior, every other behavior appears under its own name instead of behind a
|
||||
* generic "Run behavior", and the two terminals drop out once the graph has them.
|
||||
* generic "Run behavior" – and once more as the event "On <name>" if it has an End to be heard
|
||||
* through (#294) –, and the two terminals drop out once the graph has them.
|
||||
*/
|
||||
export function paletteEntries(project: Project, asset: GraphAsset): PaletteEntry[] {
|
||||
if (asset.type === 'statemachine') {
|
||||
@@ -109,7 +113,7 @@ export function paletteEntries(project: Project, asset: GraphAsset): PaletteEntr
|
||||
}
|
||||
const entries: PaletteEntry[] = [];
|
||||
for (const def of allNodeDefs()) {
|
||||
if (def.type === RUN_BEHAVIOR || def.category === 'state') continue;
|
||||
if (namesBehavior(def.type) || def.category === 'state') continue;
|
||||
if (def.category === 'shader' || def.category === 'particles') continue;
|
||||
if (isTerminalType(def.type) && terminalNode(asset.graph, def.type)) continue;
|
||||
entries.push({ id: def.type, hint: def.category, def, params: {} });
|
||||
@@ -121,8 +125,12 @@ export function paletteEntries(project: Project, asset: GraphAsset): PaletteEntr
|
||||
if (other.type !== 'behavior' || other.id === asset.id) continue;
|
||||
const params = { [BEHAVIOR_PARAM]: other.id };
|
||||
// The entry is a preview of a node that sits in no graph yet, hence the empty one.
|
||||
const def = resolveDef({ id: '', type: RUN_BEHAVIOR, x: 0, y: 0, params }, createEmptyGraph(), lookup);
|
||||
const preview = (type: string) =>
|
||||
resolveDef({ id: '', type, x: 0, y: 0, params }, createEmptyGraph(), lookup);
|
||||
const def = preview(RUN_BEHAVIOR);
|
||||
if (def) entries.push({ id: `${RUN_BEHAVIOR}:${other.id}`, hint: 'behavior', def, params });
|
||||
const heard = terminalNode(other.graph, BEHAVIOR_END) ? preview(ON_BEHAVIOR) : undefined;
|
||||
if (heard) entries.push({ id: `${ON_BEHAVIOR}:${other.id}`, hint: 'event', def: heard, params });
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
@@ -231,7 +231,9 @@ export function buildPortSection(
|
||||
if (noun === 'Field') addShapePicker(host, assetId, node, variables, header);
|
||||
const add = new Dropdown(`+ ${noun}`, { variant: 'ghost' });
|
||||
add.onClick = () => {
|
||||
const items = kindMenu(DECLARED_PORT_KINDS, (kind) =>
|
||||
// A further way in or out is a start or end node's to declare; a struct has fields only.
|
||||
const kinds = DECLARED_PORT_KINDS.filter((kind) => kind !== 'flow' || noun !== 'Field');
|
||||
const items = kindMenu(kinds, (kind) =>
|
||||
host.state.execute(new AddPortCommand(assetId, node.id, { key: nextPortName(node, base), kind })),
|
||||
);
|
||||
new Menu(items).openBelow(add);
|
||||
@@ -246,8 +248,8 @@ export function buildPortSection(
|
||||
noun === 'Field'
|
||||
? 'No fields yet. Every field added here becomes a port of the struct.'
|
||||
: onStart
|
||||
? 'No inputs yet. Every input added here becomes a port on the node that runs this behavior.'
|
||||
: 'No outputs yet. Every output added here becomes a result of running this behavior.',
|
||||
? 'No inputs yet. Every input added here becomes a port on the node that runs this behavior; one of the kind Flow is a further way in.'
|
||||
: 'No outputs yet. Every output added here becomes a result of running this behavior; one of the kind Flow is a further way out.',
|
||||
);
|
||||
|
||||
for (const port of ports) portRow(host, assetId, node, port, portNameField(host, assetId, node, port));
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" id="kind-flow" viewBox="-8 -8 16 16" width="16" height="16">
|
||||
<path d="M-3 -4.5 L4 0 L-3 4.5 Z" fill="currentColor" stroke="none" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 181 B |
@@ -13,6 +13,7 @@ import animation from './icons/kind-animation.svg?raw';
|
||||
import asset from './icons/kind-asset.svg?raw';
|
||||
import boolean from './icons/kind-boolean.svg?raw';
|
||||
import color from './icons/kind-color.svg?raw';
|
||||
import flow from './icons/kind-flow.svg?raw';
|
||||
import list from './icons/kind-list.svg?raw';
|
||||
import object from './icons/kind-object.svg?raw';
|
||||
import scene from './icons/kind-scene.svg?raw';
|
||||
@@ -30,6 +31,7 @@ export const KIND_ICON_SVG: Partial<Record<Kind, string>> = {
|
||||
asset,
|
||||
boolean,
|
||||
color,
|
||||
flow,
|
||||
list,
|
||||
object,
|
||||
scene,
|
||||
|
||||
Reference in new issue
Block a user