@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
325 lines (323 loc) • 8.95 kB
JavaScript
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
class ManagedEventAction {
constructor(data) {
this._data = data;
}
toString() {
if (this._data === undefined) {
return "undefined";
}
return JSON.stringify(this._data);
}
get filters() {
return this._data?.filters;
}
set filters(newFilters) {
if (this._data) {
this._data.filters = newFilters;
}
}
removeAddRemove() {
if (!this._data) {
return;
}
if (this._data.add) {
this._data.add = undefined;
}
if (this._data.remove) {
this._data.remove = undefined;
}
}
removeCommand() {
if (!this._data) {
return;
}
if (this._data.queue_command) {
this._data.queue_command = undefined;
}
}
removeSound() {
if (!this._data) {
return;
}
if (this._data.play_sound) {
this._data.play_sound = undefined;
}
}
removeVibration() {
if (!this._data) {
return;
}
if (this._data.emit_vibration) {
this._data.emit_vibration = undefined;
}
}
removeParticle() {
if (!this._data) {
return;
}
if (this._data.emit_particle) {
this._data.emit_particle = undefined;
}
}
removeTrigger() {
if (!this._data) {
return;
}
if (this._data.trigger) {
this._data.trigger = undefined;
}
}
get hasAddRemove() {
if (this._data && this._data.add && this._data.add.component_groups) {
return true;
}
if (this._data && this._data.remove && this._data.remove.component_groups) {
return true;
}
return false;
}
get hasCommand() {
if (this._data && this._data.queue_command && this._data.queue_command.command !== undefined) {
return true;
}
return false;
}
get hasSound() {
if (this._data && this._data.play_sound && this._data.play_sound.sound !== undefined) {
return true;
}
return false;
}
get hasVibration() {
if (this._data && this._data.emit_vibration && this._data.emit_vibration.vibration !== undefined) {
return true;
}
return false;
}
get hasParticle() {
if (this._data && this._data.emit_particle && this._data.emit_particle.particle !== undefined) {
return true;
}
return false;
}
get hasTrigger() {
if (this._data && this._data.trigger !== undefined) {
return true;
}
return false;
}
get command() {
if (!this._data) {
return "";
}
if (!this._data.queue_command) {
return "";
}
if (!this._data.queue_command.command) {
return "";
}
return this._data.queue_command.command;
}
ensureCommand(commandStr) {
if (!this._data) {
this.ensureData();
}
if (!this._data) {
return;
}
if (!this._data.queue_command) {
this._data.queue_command = {
command: "",
};
}
if (!this._data.queue_command?.command || commandStr) {
this._data.queue_command.command = commandStr ? commandStr : "";
}
return this._data.queue_command;
}
ensureSound(newSound) {
if (!this._data) {
this.ensureData();
}
if (!this._data) {
return;
}
if (!this._data.play_sound) {
this._data.play_sound = {
sound: "",
};
}
if (!this._data.play_sound?.sound || newSound) {
this._data.play_sound.sound = newSound ? newSound : "";
}
return this._data.play_sound;
}
ensureVibration(newVibration) {
if (!this._data) {
this.ensureData();
}
if (!this._data) {
return;
}
if (!this._data.emit_vibration) {
this._data.emit_vibration = {
vibration: "",
};
}
if (!this._data.emit_vibration?.vibration || newVibration) {
this._data.emit_vibration.vibration = newVibration ? newVibration : "";
}
return this._data.emit_vibration;
}
ensureTrigger(newTrigger) {
if (!this._data) {
this.ensureData();
}
if (!this._data) {
return;
}
if (!this._data.trigger) {
this._data.trigger = newTrigger ? newTrigger : "";
}
return this._data.trigger;
}
ensureParticle(newParticle) {
if (!this._data) {
this.ensureData();
}
if (!this._data) {
return;
}
if (!this._data.emit_particle) {
this._data.emit_particle = {
particle: "",
};
}
if (!this._data.emit_particle?.particle || newParticle) {
this._data.emit_particle.particle = newParticle ? newParticle : "";
}
return this._data.emit_particle;
}
ensureAddRemove() {
if (!this._data) {
this.ensureData();
}
if (!this._data) {
return;
}
const action = this._data;
if (!action.add) {
action.add = { component_groups: [] };
}
if (!action.add.component_groups) {
action.add.component_groups = [];
}
if (!this._data.remove) {
this._data.remove = { component_groups: [] };
}
if (!this._data.remove.component_groups) {
this._data.remove.component_groups = [];
}
}
hasAddComponentGroup(id) {
if (!this._data) {
return false;
}
const action = this._data;
if (!action.add || !action.add.component_groups) {
return false;
}
return action.add.component_groups.includes(id);
}
ensureData() {
if (this._data === undefined) {
this._data = {};
}
}
ensureAddComponentGroup(id) {
if (this.hasAddComponentGroup(id)) {
return;
}
this.ensureAddRemove();
if (!this._data) {
return;
}
const action = this._data;
if (!action.add || !action.add.component_groups) {
return;
}
if (action.add.component_groups.includes(id)) {
return;
}
action.add.component_groups.push(id);
}
removeAddComponentGroup(id) {
if (!this._data) {
return false;
}
const action = this._data;
if (!action.add || !action.add.component_groups) {
return false;
}
if (action.add.component_groups.includes(id)) {
const newarr = [];
for (const elt of action.add.component_groups) {
if (elt !== id) {
newarr.push(elt);
}
}
action.add.component_groups = newarr;
return true;
}
return false;
}
hasRemoveComponentGroup(id) {
if (!this._data) {
return false;
}
const action = this._data;
if (!action.remove || !action.remove.component_groups) {
return false;
}
return action.remove.component_groups.includes(id);
}
ensureRemoveComponentGroup(id) {
if (this.hasRemoveComponentGroup(id)) {
return;
}
this.ensureAddRemove();
if (!this._data) {
return;
}
const action = this._data;
if (!action.remove || !action.remove.component_groups) {
return;
}
if (action.remove.component_groups.includes(id)) {
return;
}
action.remove.component_groups.push(id);
}
removeRemoveComponentGroup(id) {
if (!this._data || !this._data.remove || !this._data.remove.component_groups) {
return false;
}
if (this._data.remove.component_groups.includes(id)) {
const newarr = [];
for (const elt of this._data.remove.component_groups) {
if (elt !== id) {
newarr.push(elt);
}
}
this._data.remove.component_groups = newarr;
return true;
}
return false;
}
}
exports.default = ManagedEventAction;
//# sourceMappingURL=../maps/minecraft/ManagedEventAction.js.map