UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

67 lines (65 loc) 2.02 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. Object.defineProperty(exports, "__esModule", { value: true }); const ste_events_1 = require("ste-events"); const StorageUtilities_1 = require("../storage/StorageUtilities"); class LootTableBehaviorDefinition { constructor() { this._isLoaded = false; this._onLoaded = new ste_events_1.EventDispatcher(); } get isLoaded() { return this._isLoaded; } get file() { return this._file; } get onLoaded() { return this._onLoaded.asEvent(); } set file(newFile) { this._file = newFile; } _ensureDataInitialized() { if (this.data === undefined) { this.data = { pools: [] }; } } static async ensureOnFile(file, loadHandler) { let ltb; if (file.manager === undefined) { ltb = new LootTableBehaviorDefinition(); ltb.file = file; file.manager = ltb; } if (file.manager !== undefined && file.manager instanceof LootTableBehaviorDefinition) { ltb = file.manager; if (!ltb.isLoaded && loadHandler) { ltb.onLoaded.subscribe(loadHandler); } await ltb.load(); } return ltb; } persist() { if (this._file === undefined) { return; } const bpString = JSON.stringify(this.data, null, 2); this._file.setContent(bpString); } async load() { if (this._file === undefined || this._isLoaded) { return; } await this._file.loadContent(); if (this._file.content === null || this._file.content instanceof Uint8Array) { return; } this.data = StorageUtilities_1.default.getJsonObject(this._file); this._isLoaded = true; } } exports.default = LootTableBehaviorDefinition; //# sourceMappingURL=../maps/minecraft/LootTableBehaviorDefinition.js.map