UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

93 lines (91 loc) 4.54 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var _StorageBase_onFileAdded, _StorageBase_onFileRemoved, _StorageBase_onFileContentsUpdated, _StorageBase_onFolderMoved, _StorageBase_storagePath; Object.defineProperty(exports, "__esModule", { value: true }); const ste_events_1 = require("ste-events"); class StorageBase { constructor() { this.isContentUpdated = false; this.readOnly = false; _StorageBase_onFileAdded.set(this, new ste_events_1.EventDispatcher()); _StorageBase_onFileRemoved.set(this, new ste_events_1.EventDispatcher()); _StorageBase_onFileContentsUpdated.set(this, new ste_events_1.EventDispatcher()); _StorageBase_onFolderMoved.set(this, new ste_events_1.EventDispatcher()); _StorageBase_storagePath.set(this, void 0); } get folderDelimiter() { return StorageBase.slashFolderDelimiter; } get storagePath() { return __classPrivateFieldGet(this, _StorageBase_storagePath, "f"); } set storagePath(newStoragePath) { __classPrivateFieldSet(this, _StorageBase_storagePath, newStoragePath, "f"); } resetContentUpdated() { this.isContentUpdated = false; } get onFileAdded() { return __classPrivateFieldGet(this, _StorageBase_onFileAdded, "f").asEvent(); } get onFileRemoved() { return __classPrivateFieldGet(this, _StorageBase_onFileRemoved, "f").asEvent(); } get onFileContentsUpdated() { return __classPrivateFieldGet(this, _StorageBase_onFileContentsUpdated, "f").asEvent(); } get onFolderMoved() { return __classPrivateFieldGet(this, _StorageBase_onFolderMoved, "f").asEvent(); } async ensureFolderFromStorageRelativePath(path) { if (path.startsWith("/" + this.rootFolder.name + "/")) { path = path.substring(this.rootFolder.name.length + 1); } return this.rootFolder.ensureFolderFromRelativePath(path); } notifyFileAdded(file) { __classPrivateFieldGet(this, _StorageBase_onFileAdded, "f").dispatch(this, file); } notifyFileContentsUpdated(file) { this.isContentUpdated = true; __classPrivateFieldGet(this, _StorageBase_onFileContentsUpdated, "f").dispatch(this, file); } notifyFolderMoved(folderMove) { this.isContentUpdated = true; __classPrivateFieldGet(this, _StorageBase_onFolderMoved, "f").dispatch(this, folderMove); } notifyFileRemoved(fileName) { __classPrivateFieldGet(this, _StorageBase_onFileRemoved, "f").dispatch(this, fileName); } joinPath(pathA, pathB) { let fullPath = pathA; if (!fullPath.endsWith(StorageBase.slashFolderDelimiter)) { fullPath += StorageBase.slashFolderDelimiter; } fullPath += pathB; return fullPath; } static getParentFolderPath(path) { const lastDelim = path.lastIndexOf(StorageBase.slashFolderDelimiter); if (lastDelim < 0) { return path; } return path.substring(0, lastDelim); } } exports.default = StorageBase; _StorageBase_onFileAdded = new WeakMap(), _StorageBase_onFileRemoved = new WeakMap(), _StorageBase_onFileContentsUpdated = new WeakMap(), _StorageBase_onFolderMoved = new WeakMap(), _StorageBase_storagePath = new WeakMap(); StorageBase.slashFolderDelimiter = "/"; //# sourceMappingURL=../maps/storage/StorageBase.js.map