sb-edit
Version:
Import, edit, and export Scratch project files
62 lines (61 loc) • 2.33 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var OpCode_1 = require("./OpCode");
var Script = /** @class */ (function () {
function Script(options) {
var _a, _b;
this.blocks = options.blocks;
this.x = (_a = options.x) !== null && _a !== void 0 ? _a : 0;
this.y = (_b = options.y) !== null && _b !== void 0 ? _b : 0;
if (typeof options.name === "undefined") {
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_".concat(this.blocks[0].inputs.BROADCAST_OPTION.value);
break;
case OpCode_1.OpCode.event_whenkeypressed:
this.name = "when_key_".concat(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("_");
}
}
else {
this.name = options.name;
}
}
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: false,
configurable: true
});
Object.defineProperty(Script.prototype, "body", {
get: function () {
return this.blocks.filter(function (block) { return !block.isHat; });
},
enumerable: false,
configurable: true
});
Script.prototype.setName = function (name) {
this.name = name;
};
return Script;
}());
exports.default = Script;