26 lines
1020 B
TypeScript
26 lines
1020 B
TypeScript
import * as Blockly from "blockly";
|
|
import { Order } from "blockly/javascript";
|
|
import type { BlockDef } from "../../toolbox";
|
|
|
|
export const physicsApplyImpulseAction: BlockDef = {
|
|
category: 'Actions',
|
|
block: {
|
|
init(this: Blockly.Block) {
|
|
this.appendDummyInput('').appendField('Push me in direction of');
|
|
this.appendValueInput('POSITION').setCheck('DPos');
|
|
this.appendDummyInput('')
|
|
.appendField('with force')
|
|
.appendField(new Blockly.FieldNumber(1, -10, 10, 0.01), 'FORCE');
|
|
this.setInputsInline(true);
|
|
this.setPreviousStatement(true, null);
|
|
this.setNextStatement(true, null);
|
|
this.setTooltip('Push me in a direction');
|
|
}
|
|
},
|
|
code(block, generator) {
|
|
const position = generator.valueToCode(block, 'POSITION', Order.ATOMIC);
|
|
const force = block.getFieldValue('FORCE');
|
|
return `yield helpers.actions.ApplyImpulse(${position}, ${force});\n`;
|
|
}
|
|
};
|