UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

76 lines (75 loc) 2.19 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const Log_1 = __importDefault(require("../core/Log")); const ste_events_1 = require("ste-events"); class TypeScriptDefinition { _data; _file; _isLoaded = false; _onLoaded = new ste_events_1.EventDispatcher(); id; get data() { if (!this._file || !this._file.content || typeof this._file.content != "string") { return undefined; } return this._file.content; } get isLoaded() { return this._isLoaded; } get file() { return this._file; } get onLoaded() { return this._onLoaded.asEvent(); } set file(newFile) { this._file = newFile; } static async ensureOnFile(file, loadHandler) { let tsd; if (file.manager === undefined) { tsd = new TypeScriptDefinition(); tsd.file = file; file.manager = tsd; } if (file.manager !== undefined && file.manager instanceof TypeScriptDefinition) { tsd = file.manager; if (!tsd.isLoaded) { if (loadHandler) { tsd.onLoaded.subscribe(loadHandler); } await tsd.load(); } } return tsd; } persist() { return false; } async load() { if (this._isLoaded) { return; } if (this._file === undefined) { Log_1.default.unexpectedUndefined("TSCDF"); return; } if (!this._file.isContentLoaded) { await this._file.loadContent(); } if (!this._file.content || this._file.content instanceof Uint8Array) { this._isLoaded = true; this._onLoaded.dispatch(this, this); return; } this._isLoaded = true; this._onLoaded.dispatch(this, this); } } exports.default = TypeScriptDefinition;