UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

124 lines (122 loc) 3.69 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. Object.defineProperty(exports, "__esModule", { value: true }); const ste_events_1 = require("ste-events"); const ManagedComponent_1 = require("./ManagedComponent"); const Molang_1 = require("./Molang"); class ManagedPermutation { constructor(data) { this._onComponentAdded = new ste_events_1.EventDispatcher(); this._onComponentRemoved = new ste_events_1.EventDispatcher(); this._onComponentChanged = new ste_events_1.EventDispatcher(); this._data = data; this._managed = {}; } get onComponentAdded() { return this._onComponentAdded.asEvent(); } get onComponentRemoved() { return this._onComponentRemoved.asEvent(); } get onComponentChanged() { return this._onComponentChanged.asEvent(); } get condition() { return this._data?.condition; } set condition(value) { if (value) { if (!this._data) { this._data = { condition: "", components: {}, }; } this._data.condition = value; } } get conditionExpression() { if (this._conditionMolang) { return this._conditionMolang; } const cond = this.condition; if (!cond) { return undefined; } this._conditionMolang = new Molang_1.default(cond); return this._conditionMolang; } addComponent(id, componentOrData) { if (!this._data) { this._data = { condition: "", components: {}, }; } if (!this._managed) { this._managed = {}; } const mc = componentOrData instanceof ManagedComponent_1.ManagedComponent ? componentOrData : new ManagedComponent_1.ManagedComponent(this._data.components, id, componentOrData); this._data.components[mc.id] = mc.getData(); this._managed[mc.id] = mc; return mc; } removeComponent(id) { if (!this._data) { return; } this._data.components[id] = undefined; } getComponent(id) { if (!this._data) { return undefined; } if (!this._managed) { this._managed = {}; } if (!this._managed[id]) { const data = this._data.components[id]; if (data) { this._managed[id] = new ManagedComponent_1.ManagedComponent(this._data.components, id, data); } } return this._managed[id]; } getAllComponents() { return this.getComponents(); } getComponents() { if (!this._data) { return []; } if (!this._managed) { this._managed = {}; } const comparr = []; for (const c in this._data) { const comp = this._data.components[c]; if (!this._managed[c] && comp) { this._managed[c] = new ManagedComponent_1.ManagedComponent(this._data.components, c, comp); } const mc = this._managed[c]; if (mc) { comparr.push(mc); } } return comparr; } notifyComponentUpdated(id) { if (!this._managed) { return; } const comp = this._managed[id]; if (comp) { this._onComponentChanged.dispatch(this, comp); } } } exports.default = ManagedPermutation; //# sourceMappingURL=../maps/minecraft/ManagedPermutation.js.map