HMR for blockly blocks

This commit is contained in:
azykov@mail.ru
2026-06-13 15:29:55 +03:00
parent 1ed3203ec5
commit a61b5f0105
36 changed files with 533 additions and 463 deletions
@@ -1,29 +1,25 @@
import * as Blockly from "blockly";
import { javascriptGenerator, Order } from "blockly/javascript";
import { Order } from "blockly/javascript";
import type { BlockDef } from "../../toolbox";
Blockly.Blocks['physics_apply_impulse_action'] = {
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');
this.setColour(150);
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`;
}
};
javascriptGenerator.forBlock['physics_apply_impulse_action'] = function (block, generator) {
const positionValue = generator.valueToCode(block, 'POSITION', Order.ATOMIC);
const forceValue = block.getFieldValue('FORCE');
return `yield helpers.actions.ApplyImpulse(${positionValue}, ${forceValue});\n`;
};
export { };