@throw-out-error/minecraft-mcfunction
Version:
A simple way to create your mcfunction files using Typescript syntax.
109 lines • 4.17 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.Command = void 0;
const arguments_1 = require("../arguments");
const transpiler_1 = require("../transpiler");
const NAME = Symbol('name');
const ARGUMENTS = Symbol('arguments');
let Command = /** @class */ (() => {
class Command extends arguments_1.ArgumentObject {
/**
* @param {CommandName} name the command to be executed
* @param {Argument[]} args the parameters to be passed to the command
*/
constructor(name, args) {
super();
this[NAME] = name;
if (args) {
this[ARGUMENTS] = args;
}
transpiler_1.Transpiler.emit('command', this);
}
async *compile() {
yield this[NAME];
for (let arg of this[ARGUMENTS]) {
yield ' ';
if (typeof arg === 'string') {
yield arg;
continue;
}
if (typeof arg === 'number') {
yield `${arg}`;
continue;
}
if (arg instanceof arguments_1.ArgumentObject) {
for await (let s of arg.compile()) {
yield s;
}
continue;
}
if (Array.isArray(arg) && arg.length === 2) {
yield arguments_1.rangeToString(arg);
continue;
}
throw Error('Unknown type of argument');
}
}
/**
* @deprecated Use compile instead */
toString() {
let cmd = this[NAME];
for (let arg of this[ARGUMENTS]) {
cmd += ' ';
if (typeof arg === 'string') {
cmd += arg;
continue;
}
if (typeof arg === 'number') {
cmd += `${arg}`;
continue;
}
if (arg instanceof arguments_1.ArgumentObject) {
cmd += arg.toString();
continue;
}
if (Array.isArray(arg) && arg.length === 2) {
cmd += arguments_1.rangeToString(arg);
continue;
}
throw Error('Unknown type of argument');
}
return cmd;
}
static registerCommand(name, cmd) {
if (this.commands[name]) {
throw Error(`Trying to register command ${name} failed. Command already registered.`);
}
this.commands[name] = cmd;
}
}
Command.NAME = NAME;
Command.ARGUMENTS = ARGUMENTS;
Command.commands = {};
return Command;
})();
exports.Command = Command;
__exportStar(require("./java/advancement"), exports);
__exportStar(require("./java/clear"), exports);
__exportStar(require("./java/datapack"), exports);
__exportStar(require("./java/difficulty"), exports);
__exportStar(require("./java/effect"), exports);
__exportStar(require("./java/execute"), exports);
__exportStar(require("./java/function"), exports);
__exportStar(require("./java/gamemode"), exports);
__exportStar(require("./java/give"), exports);
__exportStar(require("./java/kill"), exports);
__exportStar(require("./java/say"), exports);
__exportStar(require("./java/scoreboard"), exports);
__exportStar(require("./java/summon"), exports);
//# sourceMappingURL=index.js.map