UNPKG

@robotical/scratch-to-python-transpiler

Version:
62 lines (61 loc) 2.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var OpCode_1 = require("./OpCode"); var Script = /** @class */ (function () { function Script(options) { this.x = 0; this.y = 0; this.name = null; Object.assign(this, options); if (!Object.prototype.hasOwnProperty.call(options, "name")) { switch (this.blocks[0].opcode) { case OpCode_1.OpCode.event_whenflagclicked: this.name = "when_green_flag_clicked"; break; case OpCode_1.OpCode.event_whenbroadcastreceived: this.name = "when_i_receive_" + this.blocks[0].inputs.BROADCAST_OPTION.value; break; case OpCode_1.OpCode.event_whenkeypressed: this.name = "when_key_" + this.blocks[0].inputs.KEY_OPTION.value + "_pressed"; break; case OpCode_1.OpCode.procedures_definition: this.name = this.blocks[0].inputs.ARGUMENTS.value .filter(function (argument) { return argument.type === "label"; }) .map(function (argument) { return argument.name; }) .join("_"); break; default: this.name = this.blocks[0].opcode .split("_") .slice(1) .join("_"); } } } Object.defineProperty(Script.prototype, "hat", { get: function () { if (this.blocks.length === 0) { return null; } var first = this.blocks[0]; if (!first.isHat) { return null; } return first; }, enumerable: true, configurable: true }); Object.defineProperty(Script.prototype, "body", { get: function () { return this.blocks.filter(function (block) { return !block.isHat; }); }, enumerable: true, configurable: true }); Script.prototype.setName = function (name) { this.name = name; }; return Script; }()); exports.default = Script;