-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
129 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import * as Blockly from 'blockly/core'; | ||
|
||
import {SCORE_ICON} from './icon'; | ||
|
||
const SCORE_COLOR = '#f2691e'; | ||
|
||
Blockly.defineBlocksWithJsonArray([ | ||
// Block for the getter. | ||
{ | ||
'type': `score_get`, | ||
'message0': `${SCORE_ICON} Score`, | ||
'output': 'Number', | ||
'colour': SCORE_COLOR, | ||
'tooltip': `Reads the score`, | ||
}, | ||
// Block for the setter. | ||
{ | ||
'type': `score_set`, | ||
'message0': `${SCORE_ICON} Score: set to: %1`, | ||
'args0': [ | ||
{ | ||
'type': 'input_value', | ||
'name': 'VALUE', | ||
}, | ||
], | ||
'previousStatement': null, | ||
'nextStatement': null, | ||
'colour': SCORE_COLOR, | ||
'tooltip': `Updates the score`, | ||
}, | ||
// Block for adding to a variable in place. | ||
{ | ||
'type': `score_change`, | ||
'message0': `${SCORE_ICON} Score: change by: %1`, | ||
'args0': [ | ||
{ | ||
'type': 'input_value', | ||
'name': 'DELTA', | ||
'check': 'Number', | ||
}, | ||
], | ||
'previousStatement': null, | ||
'nextStatement': null, | ||
'colour': SCORE_COLOR, | ||
'extensions': ['math_change_tooltip'], | ||
}, | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
export default (Blockly) => { | ||
Blockly.BBasic[`score_get`] = function(block) { | ||
// Score getter. | ||
const code = 'score'; | ||
return [code, Blockly.BBasic.ORDER_ATOMIC]; | ||
}; | ||
|
||
Blockly.BBasic[`score_set`] = function(block) { | ||
// Score setter. | ||
const argument0 = Blockly.BBasic.valueToCode(block, 'VALUE', | ||
Blockly.BBasic.ORDER_ASSIGNMENT) || '0'; | ||
return 'score = ' + argument0 + '\n'; | ||
}; | ||
|
||
Blockly.BBasic[`score_change`] = function(block) { | ||
// Add value to the score. | ||
const argument0 = Blockly.BBasic.valueToCode(block, 'DELTA', | ||
Blockly.BBasic.ORDER_ASSIGNMENT) || '0'; | ||
const isNegativeConstant = /^\s*-\s*\d+\s*$/.test(argument0); | ||
const operator = isNegativeConstant ? '' : '+'; | ||
return `score = score ${operator} ${argument0}\n`; | ||
}; | ||
}; |