Add block for individual mouse buttons being down
This commit is contained in:
1 file changed
+58
-3
@@ -1,5 +1,34 @@
|
||||
const formatMessage = require('format-message');
|
||||
const BlockType = require('../../extension-support/block-type');
|
||||
const ArgumentType = require('../../extension-support/argument-type');
|
||||
const Cast = require('../../util/cast');
|
||||
|
||||
const MOUSE_BUTTONS = [
|
||||
{
|
||||
text: formatMessage({
|
||||
id: 'tw.blocks.mouseButtons.left',
|
||||
default: '(0) left',
|
||||
description: 'left mouse button'
|
||||
}),
|
||||
value: 0
|
||||
},
|
||||
{
|
||||
text: formatMessage({
|
||||
id: 'tw.blocks.mouseButtons.middle',
|
||||
default: '(1) middle',
|
||||
description: 'middle mouse button'
|
||||
}),
|
||||
value: 1
|
||||
},
|
||||
{
|
||||
text: formatMessage({
|
||||
id: 'tw.blocks.mouseButtons.right',
|
||||
default: '(2) right',
|
||||
description: 'right mouse button'
|
||||
}),
|
||||
value: 2
|
||||
}
|
||||
];
|
||||
|
||||
/**
|
||||
* Class for TurboWarp blocks
|
||||
@@ -22,24 +51,50 @@ class TurboWarpBlocks {
|
||||
id: 'tw',
|
||||
name: 'TurboWarp',
|
||||
color1: '#ff4c4c',
|
||||
color2: '#cc3333',
|
||||
color2: '#dd3737',
|
||||
blocks: [
|
||||
{
|
||||
opcode: 'getLastKeyPressed',
|
||||
text: formatMessage({
|
||||
id: 'tw.lastKeyPressed',
|
||||
id: 'tw.blocks.lastKeyPressed',
|
||||
default: 'last key pressed',
|
||||
description: 'get the last key that was pressed'
|
||||
}),
|
||||
blockType: BlockType.REPORTER
|
||||
},
|
||||
{
|
||||
opcode: 'getButtonIsDown',
|
||||
text: formatMessage({
|
||||
id: 'tw.blocks.buttonIsDown',
|
||||
default: '[MOUSE_BUTTON] mouse button down?'
|
||||
}),
|
||||
blockType: BlockType.BOOLEAN,
|
||||
arguments: {
|
||||
MOUSE_BUTTON: {
|
||||
type: ArgumentType.NUMBER,
|
||||
menu: 'mouseButton',
|
||||
defaultValue: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
menus: {
|
||||
mouseButton: {
|
||||
items: MOUSE_BUTTONS,
|
||||
acceptReporters: true
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
getLastKeyPressed (args, util) {
|
||||
return util.ioQuery('keyboard', 'getLastKeyPressed');
|
||||
}
|
||||
|
||||
getButtonIsDown (args, util) {
|
||||
const button = Cast.toNumber(args.MOUSE_BUTTON);
|
||||
return util.ioQuery('mouse', 'getButtonIsDown', [button]);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TurboWarpBlocks;
|
||||
Reference in new issue
Block a user