@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
459 lines (458 loc) • 12.9 kB
JavaScript
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ManagedFilterClauseOrFilterClauseSet_1 = __importDefault(require("./ManagedFilterClauseOrFilterClauseSet"));
class ManagedEventActionOrActionSet {
_data;
get data() {
return this._data;
}
get addGroups() {
if (!this._data) {
return undefined;
}
const addGroups = this._data.add;
if (!addGroups) {
return undefined;
}
return addGroups.component_groups;
}
get removeGroups() {
if (!this._data) {
return undefined;
}
const removeGroups = this._data.remove;
if (!removeGroups) {
return undefined;
}
return removeGroups.component_groups;
}
constructor(data) {
this._data = data;
}
toString() {
if (this._data === undefined) {
return "undefined";
}
return JSON.stringify(this._data);
}
get filters() {
if (!this._data) {
return undefined;
}
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() {
return this.addGroups || this.removeGroups;
}
get hasCommand() {
return this.command !== undefined;
}
get sound() {
if (!this._data) {
return undefined;
}
const playSound = this._data.play_sound;
if (!playSound) {
return undefined;
}
return playSound.sound;
}
get hasSound() {
return this.sound !== undefined;
}
get vibration() {
if (!this._data) {
return undefined;
}
const emitVibration = this._data.emit_vibration;
if (!emitVibration) {
return undefined;
}
return emitVibration.vibration;
}
get hasVibration() {
return this.vibration !== undefined;
}
get particle() {
if (!this._data) {
return undefined;
}
const emitParticle = this._data.emit_particle;
if (!emitParticle) {
return undefined;
}
return emitParticle.particle;
}
get hasParticle() {
return this.particle !== undefined;
}
get trigger() {
if (!this._data) {
return undefined;
}
return this._data.trigger;
}
get hasTrigger() {
return this.trigger !== undefined;
}
get command() {
if (!this._data) {
return "";
}
const queueCommand = this._data.queue_command;
if (!queueCommand) {
return "";
}
if (!queueCommand.command) {
return "";
}
return queueCommand.command;
}
ensureCommand(commandStr) {
if (!this._data) {
this.ensureData();
}
if (!this._data) {
return;
}
let queueCommand = this._data.queue_command;
if (!queueCommand) {
queueCommand = {
command: "",
};
this._data.queue_command = queueCommand;
}
if (!queueCommand.command || commandStr) {
queueCommand.command = commandStr ? commandStr : "";
}
return queueCommand;
}
ensureSound(newSound) {
if (!this._data) {
this.ensureData();
}
if (!this._data) {
return;
}
let playSound = this._data.play_sound;
if (!playSound) {
playSound = {
sound: "",
};
this._data.play_sound = playSound;
}
if (!playSound.sound || newSound) {
playSound.sound = newSound ? newSound : "";
}
return playSound;
}
ensureVibration(newVibration) {
if (!this._data) {
this.ensureData();
}
if (!this._data) {
return;
}
let emitVibration = this._data.emit_vibration;
if (!emitVibration) {
emitVibration = {
vibration: "",
};
this._data.emit_vibration = emitVibration;
}
if (!emitVibration.vibration || newVibration) {
emitVibration.vibration = newVibration ? newVibration : "";
}
return emitVibration;
}
get randomize() {
if (!this._data) {
return undefined;
}
const randomize = this._data.randomize;
if (!randomize || !Array.isArray(randomize)) {
return undefined;
}
const managedRandomizeNodes = [];
for (const node of randomize) {
managedRandomizeNodes.push(new ManagedEventActionOrActionSet(node));
}
return managedRandomizeNodes;
}
get weight() {
if (!this._data) {
return undefined;
}
return this._data.weight;
}
get sequence() {
if (!this._data) {
return undefined;
}
const sequence = this._data.sequence;
if (!sequence || !Array.isArray(sequence)) {
return undefined;
}
const managedSequenceNodes = [];
for (const node of sequence) {
managedSequenceNodes.push(new ManagedEventActionOrActionSet(node));
}
return managedSequenceNodes;
}
ensureTrigger(newTrigger) {
if (!this._data) {
this.ensureData();
}
if (!this._data) {
return;
}
if (!this._data.trigger) {
this._data.trigger = newTrigger ? newTrigger : "";
}
return this._data.trigger;
}
getPotentialActions(conditionSeed) {
if (!this._data) {
return [];
}
if (!conditionSeed) {
conditionSeed = "";
}
const randomize = this.randomize;
const sequence = this.sequence;
if (randomize && Array.isArray(randomize)) {
const actions = [];
for (const randomNode of randomize) {
if (randomNode.filters) {
const managedFilter = new ManagedFilterClauseOrFilterClauseSet_1.default(randomNode.filters);
conditionSeed += managedFilter.getHumanSummary();
}
if (randomNode.weight) {
conditionSeed += "randomly chosen with a weight of " + randomNode.weight;
}
else {
conditionSeed += "randomly chosen ";
}
actions.push(...randomNode.getPotentialActions(conditionSeed));
}
}
else if (sequence && Array.isArray(sequence)) {
const actions = [];
for (const sequenceNode of sequence) {
if (sequenceNode.filters) {
const managedFilter = new ManagedFilterClauseOrFilterClauseSet_1.default(sequenceNode.filters);
conditionSeed += managedFilter.getHumanSummary();
}
conditionSeed += "runs ";
actions.push(...sequenceNode.getPotentialActions(conditionSeed));
}
}
return [
{
conditionDescription: conditionSeed + " fires",
action: this,
},
];
}
ensureParticle(newParticle) {
if (!this._data) {
this.ensureData();
}
if (!this._data) {
return;
}
let emitParticle = this._data.emit_particle;
if (!emitParticle) {
emitParticle = {
particle: "",
};
this._data.emit_particle = emitParticle;
}
if (!emitParticle.particle || newParticle) {
emitParticle.particle = newParticle ? newParticle : "";
}
return emitParticle;
}
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 (!action.remove) {
action.remove = { component_groups: [] };
}
if (!action.remove.component_groups) {
action.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 || !Array.isArray(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) {
return false;
}
const remove = this._data.remove;
if (!remove || !remove.component_groups || !Array.isArray(remove.component_groups)) {
return false;
}
if (remove.component_groups.includes(id)) {
const newarr = [];
for (const elt of remove.component_groups) {
if (elt !== id) {
newarr.push(elt);
}
}
remove.component_groups = newarr;
return true;
}
return false;
}
}
exports.default = ManagedEventActionOrActionSet;