UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

84 lines (82 loc) 2.27 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. Object.defineProperty(exports, "__esModule", { value: true }); const Anchor_1 = require("./Anchor"); class AnchorSet { constructor() { this.data = {}; this.anchors = {}; } clear(anchorName) { const exists = this.data[anchorName] !== undefined || this.anchors[anchorName] !== undefined; this.data[anchorName] = undefined; this.anchors[anchorName] = undefined; return exists; } clearAll() { this.data = {}; this.anchors = {}; } getLength() { let count = 0; // eslint-disable-next-line @typescript-eslint/no-unused-vars for (const strKey in this.data) { count++; } return count; } getKeys() { const keyArr = []; for (const strKey in this.data) { keyArr.push(strKey); } return keyArr; } get(name) { if (this.anchors[name]) { return this.anchors[name]; } if (this.data[name]) { this.anchors[name] = new Anchor_1.default(this.data[name]); return this.anchors[name]; } return undefined; } ensure(name, from, to) { let anchor; if (this.anchors[name]) { anchor = this.anchors[name]; } if (!anchor && this.data[name]) { this.anchors[name] = new Anchor_1.default(this.data[name]); anchor = this.anchors[name]; } if (!anchor) { this.data[name] = { from: from, to: to, name: name, }; this.anchors[name] = new Anchor_1.default(this.data[name]); anchor = this.anchors[name]; } if (anchor) { anchor.from = from; anchor.to = to; anchor.name = name; } return anchor; } getAsString() { return JSON.stringify(this.data); } fromString(incomingStr) { try { this.data = JSON.parse(incomingStr); } catch (e) { } } } exports.default = AnchorSet; //# sourceMappingURL=../maps/minecraft/AnchorSet.js.map