UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

106 lines (104 loc) 3.85 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. Object.defineProperty(exports, "__esModule", { value: true }); exports.CoordinateType = exports.CoordinateLocation = exports.CommandArgumentType = void 0; const Utilities_1 = require("../core/Utilities"); var CommandArgumentType; (function (CommandArgumentType) { CommandArgumentType[CommandArgumentType["coordinate"] = 0] = "coordinate"; CommandArgumentType[CommandArgumentType["unknown"] = 1] = "unknown"; })(CommandArgumentType = exports.CommandArgumentType || (exports.CommandArgumentType = {})); var CoordinateLocation; (function (CoordinateLocation) { CoordinateLocation[CoordinateLocation["x"] = 0] = "x"; CoordinateLocation[CoordinateLocation["y"] = 1] = "y"; CoordinateLocation[CoordinateLocation["z"] = 2] = "z"; })(CoordinateLocation = exports.CoordinateLocation || (exports.CoordinateLocation = {})); var CoordinateType; (function (CoordinateType) { CoordinateType[CoordinateType["absolute"] = 0] = "absolute"; CoordinateType[CoordinateType["relativeTilde"] = 1] = "relativeTilde"; CoordinateType[CoordinateType["localCaret"] = 2] = "localCaret"; })(CoordinateType = exports.CoordinateType || (exports.CoordinateType = {})); class CommandArgument { get value() { if (this._type === CommandArgumentType.coordinate && this._pos !== undefined) { let result = this._pos.toString(); if (this._coordinateType === CoordinateType.localCaret) { result = "^" + result; } else if (this._coordinateType === CoordinateType.relativeTilde) { result = "~" + result; } return result; } return this._content; } get position() { if (this._pos === undefined) { return 0; } return this._pos; } set position(value) { this._pos = value; } get coordinateType() { if (this._coordinateType === undefined) { return CoordinateType.absolute; } return this._coordinateType; } set coordinateType(type) { this._coordinateType = type; } get type() { return this._type; } get location() { return this._location; } set location(newLocation) { this._location = newLocation; } constructor(content) { this._content = content; this._type = CommandArgumentType.unknown; this.setValue(content); } setValue(content) { this._content = content; const startsWithCaret = this._content.startsWith("^"); const startsWithTilde = this._content.startsWith("~"); if (startsWithCaret || startsWithTilde) { const substr = this._content.substring(1, this._content.length); if (Utilities_1.default.isNumeric(substr)) { this._type = CommandArgumentType.coordinate; if (startsWithTilde) { this._coordinateType = CoordinateType.relativeTilde; } else if (startsWithCaret) { this._coordinateType = CoordinateType.localCaret; } this._pos = parseInt(substr); } else { this._type = CommandArgumentType.unknown; } } else if (Utilities_1.default.isNumeric(this._content)) { this._type = CommandArgumentType.coordinate; this._coordinateType = CoordinateType.absolute; this._pos = parseInt(content); } else { this._type = CommandArgumentType.unknown; } } toString() { return this.value; } } exports.default = CommandArgument; //# sourceMappingURL=../maps/minecraft/CommandArgument.js.map