UNPKG

@tsparticles/editor

Version:

tsParticles Configuration Editor

64 lines (63 loc) 2.27 kB
import { CollisionMode } from "@tsparticles/engine"; import { EditorType } from "object-gui"; import { EditorBase } from "../../../../EditorBase"; export class CollisionsOptionsEditor extends EditorBase { constructor(particles) { super(particles); } addToGroup(parent) { this.group = parent.addGroup("collisions", "Collisions"); this.options = this.group.data; this.addBounce(); this.addOverlap(); this.addProperties(); } addBounce() { const group = this.group.addGroup("bounce", "Bounce"); this.addBounceFactor(group, "horizontal", "Horizontal"); this.addBounceFactor(group, "vertical", "Vertical"); } addBounceFactor(parentGroup, name, title) { const group = parentGroup.addGroup(name, title); const randomGroup = group.addGroup("random", "Random"); randomGroup.addProperty("enable", "Enable", EditorType.boolean).change(() => { void this.particles().refresh(); }); randomGroup.addProperty("minimumValue", "Minimum Value", EditorType.number).change(() => { void this.particles().refresh(); }); group.addProperty("value", "Value", EditorType.number).change(() => { void this.particles().refresh(); }); } addOverlap() { const group = this.group.addGroup("overlap", "Overlap"); group.addProperty("enable", "Enable", EditorType.boolean).change(() => { void this.particles().refresh(); }); group.addProperty("retries", "Retries", EditorType.number).change(() => { void this.particles().refresh(); }); } addProperties() { this.group.addProperty("enable", "Enable", EditorType.boolean).change(() => { void this.particles().refresh(); }); this.group .addProperty("mode", "Mode", EditorType.select) .change(() => { void this.particles().refresh(); }) .addItems([ { value: CollisionMode.absorb, }, { value: CollisionMode.bounce, }, { value: CollisionMode.destroy, }, ]); } }