From e0fbf57ae989a6955972491e1ae563daf38a4850 Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Sun, 22 Jan 2023 19:25:38 -0300 Subject: [PATCH 1/4] Implement score blocks. --- src/blocks/icon.js | 1 + src/blocks/score.js | 47 ++++++++++++++++++++++++++++++ src/components/ActionEditor.vue | 1 + src/components/blockly-toolbox.xml | 11 +++++++ 4 files changed, 60 insertions(+) create mode 100644 src/blocks/score.js diff --git a/src/blocks/icon.js b/src/blocks/icon.js index 5c2afa0..e83e258 100644 --- a/src/blocks/icon.js +++ b/src/blocks/icon.js @@ -6,3 +6,4 @@ export const HEIGHT_ICON = String.fromCodePoint(0x1F4CF); export const JOYSTICK_ICON = String.fromCodePoint(0x1F579); export const FIRE_ICON = String.fromCodePoint(0x1F518); export const PLAYFIELD_ICON = String.fromCodePoint(0x1F5FA); +export const SCORE_ICON = String.fromCodePoint(0x1F4AF); diff --git a/src/blocks/score.js b/src/blocks/score.js new file mode 100644 index 0000000..5e9d2ae --- /dev/null +++ b/src/blocks/score.js @@ -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'], + }, +]); diff --git a/src/components/ActionEditor.vue b/src/components/ActionEditor.vue index 04710a0..044358c 100644 --- a/src/components/ActionEditor.vue +++ b/src/components/ActionEditor.vue @@ -19,6 +19,7 @@ import BlocklyComponent from './BlocklyComponent.vue'; import '../blocks/collision'; import '../blocks/input'; import '../blocks/sprites'; +import '../blocks/score'; import blocklyToolbox from 'raw-loader!./blockly-toolbox.xml'; import BlocklyBB from '../generators/bbasic'; import {useWorkspaceStorage} from '../hooks/project'; diff --git a/src/components/blockly-toolbox.xml b/src/components/blockly-toolbox.xml index b8b49b5..63c96da 100644 --- a/src/components/blockly-toolbox.xml +++ b/src/components/blockly-toolbox.xml @@ -84,4 +84,15 @@ + + + + + + + 1 + + + + \ No newline at end of file From 294dcb58c57df88426c63c2e67602737fb208028 Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Sun, 22 Jan 2023 19:43:09 -0300 Subject: [PATCH 2/4] Implement generators for score blocks. --- src/generators/bbasic.js | 3 ++- src/generators/bbasic/score.js | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/generators/bbasic/score.js diff --git a/src/generators/bbasic.js b/src/generators/bbasic.js index 3ed7c4b..0a40510 100644 --- a/src/generators/bbasic.js +++ b/src/generators/bbasic.js @@ -414,11 +414,12 @@ import logic from './bbasic/logic'; import loops from './bbasic/loops'; import math from './bbasic/math'; import procedures from './bbasic/procedures'; +import score from './bbasic/score'; import sprites from './bbasic/sprites'; import text from './bbasic/text'; import variables from './bbasic/variables'; -[collision, colour, input, logic, loops, math, procedures, sprites, text, variables] +[collision, colour, input, logic, loops, math, procedures, sprites, score, text, variables] .forEach((init) => init(Blockly)); export default Blockly.BBasic; diff --git a/src/generators/bbasic/score.js b/src/generators/bbasic/score.js new file mode 100644 index 0000000..69ff8f4 --- /dev/null +++ b/src/generators/bbasic/score.js @@ -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`; + }; +}; From 9a1a791b3bc754088d8c0aff00b8d9cb329cee3c Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Sun, 22 Jan 2023 19:49:08 -0300 Subject: [PATCH 3/4] Add default values for all the setter blocks. --- src/components/blockly-toolbox.xml | 48 ++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/src/components/blockly-toolbox.xml b/src/components/blockly-toolbox.xml index 63c96da..cfcc052 100644 --- a/src/components/blockly-toolbox.xml +++ b/src/components/blockly-toolbox.xml @@ -28,7 +28,13 @@ - + + + + 1 + + + @@ -38,7 +44,13 @@ - + + + + 1 + + + @@ -48,7 +60,13 @@ - + + + + 1 + + + @@ -58,7 +76,13 @@ - + + + + 1 + + + @@ -68,7 +92,13 @@ - + + + + 1 + + + @@ -86,7 +116,13 @@ - + + + + 1 + + + From c53b3f7f200e928d5459a95aea2b67078b3134d0 Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Sun, 22 Jan 2023 19:51:40 -0300 Subject: [PATCH 4/4] Bump version to 0.9.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6b137df..2bdd5d1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vcs-game-maker", - "version": "0.8.1", + "version": "0.9.0", "private": true, "scripts": { "serve": "vue-cli-service serve",