Tooling: - Prettier as the single formatting authority (110 columns, single quotes, measured against the existing style); Markdown excluded because table-cell padding turns the README glossary into 1000-character lines. - Type-aware ESLint ending in eslint-config-prettier, so a rule always means "this is a bug", never "this looks different". - .editorconfig and an `npm run check` that runs typecheck, lint, format and tests in one go. Findings fixed on the first run: three more duplicate imports, four String(unknown) calls (parameter types narrowed instead of casts), two dead initialisers, two redundant casts, a console.log for a real error. Two warnings were false here and are disabled with a reason in place. Tests 132 -> 269: - node-catalog.test.ts covers every node with a run(), with a guard that fails when a new node has no row. - behavior-events.test.ts covers the ten event nodes through a running World, checking timing rather than existence. - Input's state machine (press/release/releaseAll) is reachable without DOM events now; the DOM handlers are thin adapters. Compare fell back to == without a configured operator although the schema default is <; aligned. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
35 lines
1.4 KiB
TypeScript
35 lines
1.4 KiB
TypeScript
import type { NodeDef } from '../../NodeRegistry';
|
||
import { asBoolean, asEntity, asNumber } from '../../values';
|
||
import { bool, exec, num, obj, withDefault } from '../shared';
|
||
|
||
export const Move: NodeDef = {
|
||
type: 'Move',
|
||
label: 'Move',
|
||
category: 'action',
|
||
description:
|
||
"Moves an object by (dx, dy) × scale × dt. Connect dt to an event's dt for per-second movement; " +
|
||
'leave it at 1 for per-frame. With "Collide with solids" on, the object\'s solid colliders stop at ' +
|
||
'other solid colliders and slide along them; blocked x/y tell which axes hit.',
|
||
inputs: [
|
||
exec(),
|
||
obj('object'),
|
||
num('dx'),
|
||
num('dy'),
|
||
withDefault(num('scale'), 1),
|
||
withDefault(num('dt'), 1),
|
||
],
|
||
outputs: [exec(), bool('blockedX', 'blocked x'), bool('blockedY', 'blocked y')],
|
||
params: [{ key: 'collide', label: 'Collide with solids', kind: 'boolean', default: false }],
|
||
run: (ctx, inputs, params) => {
|
||
const target = asEntity(inputs.object);
|
||
if (!target) return { next: 'exec', outputs: { blockedX: false, blockedY: false } };
|
||
const factor = asNumber(inputs.scale) * asNumber(inputs.dt);
|
||
const dx = asNumber(inputs.dx) * factor;
|
||
const dy = asNumber(inputs.dy) * factor;
|
||
if (asBoolean(params.collide)) return { next: 'exec', outputs: ctx.moveAndSlide(target, dx, dy) };
|
||
target.x += dx;
|
||
target.y += dy;
|
||
return { next: 'exec', outputs: { blockedX: false, blockedY: false } };
|
||
},
|
||
};
|