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 } }; }, };