player object script block

This commit is contained in:
azykov@mail.ru 2026-06-05 21:53:42 +03:00
parent 6c3e1ae64e
commit 93e127b2f7
No known key found for this signature in database
4 changed files with 22 additions and 1 deletions

View File

@ -15,7 +15,7 @@ Blockly.Blocks['physics_apply_impulse_action'] = {
this.setInputsInline(true) this.setInputsInline(true)
this.setPreviousStatement(true, null); this.setPreviousStatement(true, null);
this.setNextStatement(true, null); this.setNextStatement(true, null);
this.setTooltip('Push me to a position'); this.setTooltip('Push me in a direction');
this.setColour(150); this.setColour(150);
} }
}; };

View File

@ -7,3 +7,4 @@ export * from './position';
export * from './direction'; export * from './direction';
export * from './objectById'; export * from './objectById';
export * from './directionToPosition'; export * from './directionToPosition';
export * from './playerObject';

View File

@ -0,0 +1,19 @@
import * as Blockly from "blockly";
import { javascriptGenerator, Order } from "blockly/javascript";
Blockly.Blocks['player_object_value'] = {
init(this: Blockly.Block) {
this.appendEndRowInput()
.appendField('Player');
this.setInputsInline(false)
this.setOutput(true, 'Object');
this.setTooltip('Returns object that is controlled by player');
this.setColour(315);
}
};
javascriptGenerator.forBlock['player_object_value'] = function (_block, _generator) {
return ['(scene.playerObjectId?scene.objects[scene.playerObjectId]:undefined)', Order.ATOMIC];
};
export { };

View File

@ -36,6 +36,7 @@ const TOOLBOX: Blockly.utils.toolbox.ToolboxDefinition = {
{ kind: 'block', type: 'dpos_value' }, { kind: 'block', type: 'dpos_value' },
{ kind: 'block', type: 'direction_to_position_value' }, { kind: 'block', type: 'direction_to_position_value' },
{ kind: 'block', type: 'object_by_id_value' }, { kind: 'block', type: 'object_by_id_value' },
{ kind: 'block', type: 'player_object_value' },
], ],
}, },
{ {