@osbjs/osbjs
Version:
a minimalist osu! storyboarding framework
68 lines (67 loc) • 2.64 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Component = void 0;
const uuid_1 = require("uuid");
const _1 = require(".");
const Enums_1 = require("../Enums");
class Component {
constructor() {
this.uuid = (0, uuid_1.v4)();
this.layers = {
background: [],
foreground: [],
fail: [],
pass: [],
overlay: [],
sample: [],
};
if (this.constructor == Component) {
throw new Error('Component can not be instantiated. To create a new Component, extends this class.');
}
}
/**
* Register components to this component. You can supply as many components as you want.
* Note: later component will have higher z-index therefore it might appear on top of earlier components if their active time overlap.
* @param components Component instances
*/
registerComponents(...components) {
components.forEach((component) => {
component.generate();
this._addToLayer(component);
});
}
_addToLayer(component) {
if (component instanceof _1.Sprite || component instanceof _1.Animation) {
switch (component.layer) {
case Enums_1.Layer.Background:
this.layers.background.push(component);
break;
case Enums_1.Layer.Foreground:
this.layers.foreground.push(component);
break;
case Enums_1.Layer.Fail:
this.layers.fail.push(component);
break;
case Enums_1.Layer.Pass:
this.layers.pass.push(component);
break;
case Enums_1.Layer.Overlay:
this.layers.overlay.push(component);
default:
break;
}
}
else if (component instanceof _1.Sample) {
this.layers.sample.push(component);
}
else {
this.layers.background = this.layers.background.concat(component.layers.background);
this.layers.foreground = this.layers.foreground.concat(component.layers.foreground);
this.layers.fail = this.layers.fail.concat(component.layers.fail);
this.layers.pass = this.layers.pass.concat(component.layers.pass);
this.layers.overlay = this.layers.overlay.concat(component.layers.overlay);
}
}
generate() { }
}
exports.Component = Component;