sb-edit
Version:
Import, edit, and export Scratch project files
120 lines (119 loc) • 4.38 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.Sprite = exports.Stage = void 0;
var Target = /** @class */ (function () {
function Target(options) {
this.costumes = [];
this.costumeNumber = 0;
this.sounds = [];
this.scripts = [];
this.variables = [];
this.lists = [];
this.volume = 100;
this.layerOrder = 0;
this.isStage = false;
Object.assign(this, options);
}
Object.defineProperty(Target.prototype, "blocks", {
get: function () {
var collector = [];
for (var _i = 0, _a = this.scripts; _i < _a.length; _i++) {
var script = _a[_i];
for (var _b = 0, _c = script.blocks; _b < _c.length; _b++) {
var block = _c[_b];
recursive(block);
}
}
return collector;
function recursive(block) {
collector.push(block);
for (var _i = 0, _a = Object.values(block.inputs); _i < _a.length; _i++) {
var input = _a[_i];
switch (input.type) {
case "block":
recursive(input.value);
break;
case "blocks":
if (!input.value)
break;
for (var _b = 0, _c = input.value; _b < _c.length; _b++) {
var block_1 = _c[_b];
recursive(block_1);
}
break;
}
}
}
},
enumerable: false,
configurable: true
});
Target.prototype.setName = function (name) {
this.name = name;
};
Target.prototype.getCostume = function (name) {
return this.costumes.find(function (costume) { return costume.name === name; });
};
Target.prototype.getSound = function (name) {
return this.sounds.find(function (sound) { return sound.name === name; });
};
Target.prototype.getVariable = function (name) {
return this.variables.find(function (variable) { return variable.name === name; });
};
Target.prototype.getList = function (name) {
return this.lists.find(function (list) { return list.name === name; });
};
return Target;
}());
exports.default = Target;
var Stage = /** @class */ (function (_super) {
__extends(Stage, _super);
function Stage(options) {
if (options === void 0) { options = { name: "Stage" }; }
var _this = _super.call(this, options) || this;
_this.name = "Stage";
_this.isStage = true;
Object.assign(_this, options);
return _this;
}
return Stage;
}(Target));
exports.Stage = Stage;
var Sprite = /** @class */ (function (_super) {
__extends(Sprite, _super);
function Sprite(options) {
var _this = _super.call(this, options) || this;
_this.x = 0;
_this.y = 0;
_this.size = 1;
_this.direction = 90;
_this.rotationStyle = "normal";
_this.isDraggable = true;
_this.visible = true;
Object.assign(_this, options);
return _this;
}
Sprite.prototype.delete = function () {
if (!this.project)
return;
var index = this.project.sprites.indexOf(this);
this.project.sprites.splice(index, 1);
};
return Sprite;
}(Target));
exports.Sprite = Sprite;