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
@@ -0,0 +1,32 @@
|
||||
import type { NodeDef } from '../../NodeRegistry';
|
||||
import { textOf } from '../../../model/Properties';
|
||||
import { BEHAVIOR_END, BEHAVIOR_PARAM, BEHAVIOR_START, declaredPorts, ON_BEHAVIOR } from '../../nested';
|
||||
import { exec } from '../shared';
|
||||
|
||||
/**
|
||||
* Another behavior used as an event (#294): it lives at this node for as long as the behavior around
|
||||
* it runs, its own events fire, and each of its pulses that reaches its end node goes on here. The
|
||||
* running game keeps that second behavior; the interpreter only ever sees the pulse arriving.
|
||||
*/
|
||||
export const OnBehavior: NodeDef = {
|
||||
type: ON_BEHAVIOR,
|
||||
label: 'On behavior',
|
||||
category: 'event',
|
||||
description:
|
||||
'Listens to another behavior. That behavior runs here with its own events and variables, and ' +
|
||||
'whenever one of its flows reaches its End, this node fires: through the output named like ' +
|
||||
'the flow port the End was reached by last, with the values the End was handed. The inputs ' +
|
||||
'are what its Start hands out.',
|
||||
inputs: [],
|
||||
outputs: [exec()],
|
||||
params: [{ key: BEHAVIOR_PARAM, label: 'Behavior', kind: 'asset', default: '', assetTypes: ['behavior'] }],
|
||||
derivePorts: ({ node, lookup }) => {
|
||||
const program = lookup.behavior(textOf(node.params[BEHAVIOR_PARAM] ?? ''));
|
||||
return {
|
||||
label: program ? `On ${program.name}` : undefined,
|
||||
// No flow in: the behavior starts its own pulses, so the ways into its Start have no use here.
|
||||
inputs: declaredPorts(program?.graph, BEHAVIOR_START).filter((port) => port.type !== 'exec'),
|
||||
outputs: declaredPorts(program?.graph, BEHAVIOR_END),
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -13,7 +13,8 @@ export const BehaviorEnd: NodeDef = {
|
||||
category: 'flow',
|
||||
description:
|
||||
'Ends this behavior and hands its results back to the graph that ran it. Every output declared ' +
|
||||
'here becomes an output port on that node.',
|
||||
'here becomes an output port on that node. An output of the kind Flow is a further way out: ' +
|
||||
'the node that ran or hears this behavior goes on through the one reached last.',
|
||||
inputs: [exec()],
|
||||
outputs: [],
|
||||
params: [],
|
||||
|
||||
@@ -12,7 +12,8 @@ export const BehaviorStart: NodeDef = {
|
||||
category: 'event',
|
||||
description:
|
||||
'Where this behavior begins when another graph runs it as a node. Every input declared here ' +
|
||||
'becomes an input port on that node.',
|
||||
'becomes an input port on that node. An input of the kind Flow is a further way in: a call ' +
|
||||
'arriving through it leaves here through the output of that name and not through the plain one.',
|
||||
inputs: [],
|
||||
outputs: [exec()],
|
||||
params: [],
|
||||
|
||||
@@ -16,7 +16,9 @@ export const RunBehavior: NodeDef = {
|
||||
'Runs another behavior as a step of this one, passing values in and taking results out. It ' +
|
||||
'begins at the Behavior start node, or at On start if that behavior has none. A ' +
|
||||
'variable marked Keep in that behavior carries on from the last call of this node on this ' +
|
||||
'object; the others start at their defaults every time.',
|
||||
'object; the others start at their defaults every time. A flow port declared at that ' +
|
||||
"behavior's Start is a further way in, one declared at its End a further way out: the " +
|
||||
'call leaves through the one its End was reached by last, and then through the plain one.',
|
||||
inputs: [exec()],
|
||||
outputs: [exec()],
|
||||
params: [{ key: BEHAVIOR_PARAM, label: 'Behavior', kind: 'asset', default: '', assetTypes: ['behavior'] }],
|
||||
@@ -29,8 +31,8 @@ export const RunBehavior: NodeDef = {
|
||||
outputs: declaredPorts(program?.graph, BEHAVIOR_END),
|
||||
};
|
||||
},
|
||||
run: (_ctx, inputs, params) => ({
|
||||
call: { behaviorId: textOf(params[BEHAVIOR_PARAM] ?? ''), inputs },
|
||||
run: (_ctx, inputs, params, _def, entry) => ({
|
||||
call: { behaviorId: textOf(params[BEHAVIOR_PARAM] ?? ''), inputs, entry },
|
||||
next: 'exec',
|
||||
}),
|
||||
};
|
||||
@@ -106,6 +106,7 @@ import { SetItem } from './data/SetItem';
|
||||
import { SubList } from './data/SubList';
|
||||
import { TextureSize } from './data/TextureSize';
|
||||
import { OnAnimationFinished } from './events/OnAnimationFinished';
|
||||
import { OnBehavior } from './events/OnBehavior';
|
||||
import { OnClick } from './events/OnClick';
|
||||
import { OnMouseWheel } from './events/OnMouseWheel';
|
||||
import { OnCollisionEnter } from './events/OnCollisionEnter';
|
||||
@@ -160,6 +161,7 @@ export const BUILT_IN_NODES: readonly NodeDef[] = [
|
||||
OnClick,
|
||||
OnMouseWheel,
|
||||
OnAnimationFinished,
|
||||
OnBehavior,
|
||||
OnStateEntered,
|
||||
OnStateExited,
|
||||
BehaviorStart,
|
||||
|
||||
Reference in new issue
Block a user