UNPKG

@tsparticles/editor

Version:

tsParticles Configuration Editor

87 lines (86 loc) 3.88 kB
(function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports", "object-gui", "../../../EditorBase"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InfectionOptionsEditor = void 0; const object_gui_1 = require("object-gui"); const EditorBase_1 = require("../../../EditorBase"); class InfectionOptionsEditor extends EditorBase_1.EditorBase { constructor(particles) { super(particles); } addToGroup(parent) { this.group = parent.addGroup("infection", "Infection"); this.options = this.group.data; this.addStages(); this.addProperties(); } addProperties() { this.group.addProperty("cure", "Cure", object_gui_1.EditorType.boolean).change(() => { void this.particles().refresh(); }); this.group.addProperty("delay", "Delay", object_gui_1.EditorType.number).change(() => { void this.particles().refresh(); }); this.group.addProperty("enable", "Enable", object_gui_1.EditorType.boolean).change(() => { void this.particles().refresh(); }); this.group.addProperty("infections", "Infections", object_gui_1.EditorType.number).change(() => { void this.particles().refresh(); }); } addStage(parent, stages, index) { const stageGroup = parent.addGroup(index().toString(10), `Stage ${index()}`, true, stages); const stage = stageGroup.data; stageGroup.addProperty("color", "Color", object_gui_1.EditorType.color, stage().color, false).change((value) => { if (typeof value === "string") { if (typeof stage().color === "string") { stage().color = value; } else { stage().color = { value, }; } } void this.particles().refresh(); }); stageGroup.addProperty("duration", "Duration", object_gui_1.EditorType.number).change(() => { void this.particles().refresh(); }); stageGroup.addProperty("infectedStage", "Infected Stage", object_gui_1.EditorType.number).change(() => { void this.particles().refresh(); }); stageGroup.addProperty("radius", "Radius", object_gui_1.EditorType.number).change(() => { void this.particles().refresh(); }); stageGroup.addProperty("rate", "Rate", object_gui_1.EditorType.number).change(() => { void this.particles().refresh(); }); } addStages() { const options = this.options(); const stagesGroup = this.group.addGroup("stages", "Stages"); if (options && !options.stages) { options.stages = []; } if (options) { for (let i = 0; i < options.stages.length; i++) { this.addStage(stagesGroup, () => options.stages, () => i + 1); } } stagesGroup.addButton("addStage", "Add Stage", false).click(() => { this.addStage(stagesGroup, () => this.options().stages, () => this.options().stages.length); void this.particles().refresh(); }); } } exports.InfectionOptionsEditor = InfectionOptionsEditor; });