UNPKG

automatic-assessments

Version:

Automatic assessment of Marty and Scratch 3.0 projects

110 lines (109 loc) 4.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BACKDROP_CHANGES_OPCODE = exports.START_AS_CLONE_OPCODE = exports.SMTHNG_GREATER_THAN_OPCODE = exports.RECEIVE_MESSAGE_OPCODE = exports.KEY_CKLICKED_OPCODE = exports.SPRITE_CLICKED_OPCODE = exports.GREEN_FLAG_OPCODE = void 0; const Analyzer_1 = require("../Analyzer"); exports.GREEN_FLAG_OPCODE = 'event_whenflagclicked'; exports.SPRITE_CLICKED_OPCODE = 'event_whenthisspriteclicked'; exports.KEY_CKLICKED_OPCODE = 'event_whenkeypressed'; exports.RECEIVE_MESSAGE_OPCODE = 'event_whenbroadcastreceived'; exports.SMTHNG_GREATER_THAN_OPCODE = 'event_whengreaterthan'; exports.START_AS_CLONE_OPCODE = 'control_start_as_clone'; exports.BACKDROP_CHANGES_OPCODE = 'event_whenbackdropswitchesto'; class Parallelism extends Analyzer_1.default { constructor(targets) { super(); this.score = 0; this.targets = targets; } execute() { this.firstPointGreenFlagTwoScripts(); this.twoPointsKeyPressORSpriteClicked(); this.threePointsWhenAnyOfBlocksExecuted(); return this.score; } firstPointGreenFlagTwoScripts() { // one point for when two or more scripts run when green flag clicked let greenFlagsWithChildCounter = 0; for (const target of this.targets) { for (const _blockKey of Object.keys(target.blocks._blocks)) { const _block = target.blocks._blocks[_blockKey]; if (_block.opcode === exports.GREEN_FLAG_OPCODE && _block.next) { greenFlagsWithChildCounter += 1; if (greenFlagsWithChildCounter > 1) { this.score = 1; break; } } } } } twoPointsKeyPressORSpriteClicked() { // two points when two or more scripts run when a key pressed or when a single sprite is clicked on let keyPressedWithChildCounter = 0; let spriteClickedWithChildCounter = 0; for (const target of this.targets) { for (const _blockKey of Object.keys(target.blocks._blocks)) { const _block = target.blocks._blocks[_blockKey]; if (_block.opcode === exports.KEY_CKLICKED_OPCODE && _block.next) { keyPressedWithChildCounter += 1; if (keyPressedWithChildCounter > 1) { this.score = 2; break; } } if (_block.opcode === exports.SPRITE_CLICKED_OPCODE && _block.next) { spriteClickedWithChildCounter += 1; if (spriteClickedWithChildCounter > 1) { this.score = 2; break; } } } } } threePointsWhenAnyOfBlocksExecuted() { // three points when two scripts run on any of the following blocks being executed: // ‘when I receive message’; // ‘create clone’; // ‘when % is > %’; // ‘when backdrop changes to’ let receiceMessageWithChildeCounter = 0; let startAsCloneWithChildeCounter = 0; let smthGreaterThanWithChildCounter = 0; let backdropChangesWithChildCounter = 0; for (const target of this.targets) { for (const _blockKey of Object.keys(target.blocks._blocks)) { const _block = target.blocks._blocks[_blockKey]; if (_block.opcode === exports.RECEIVE_MESSAGE_OPCODE && _block.next) { receiceMessageWithChildeCounter += 1; if (receiceMessageWithChildeCounter > 1) { this.score = 3; break; } } if (_block.opcode === exports.SMTHNG_GREATER_THAN_OPCODE && _block.next) { startAsCloneWithChildeCounter += 1; if (startAsCloneWithChildeCounter > 1) { this.score = 3; break; } } if (_block.opcode === exports.START_AS_CLONE_OPCODE && _block.next) { smthGreaterThanWithChildCounter += 1; if (smthGreaterThanWithChildCounter > 1) { this.score = 3; break; } } if (_block.opcode === exports.BACKDROP_CHANGES_OPCODE && _block.next) { backdropChangesWithChildCounter += 1; if (backdropChangesWithChildCounter > 1) { this.score = 3; break; } } } } } } exports.default = Parallelism;