@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
66 lines (64 loc) • 1.9 kB
JavaScript
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
const Log_1 = require("../core/Log");
const ste_events_1 = require("ste-events");
class TypeScriptDefinition {
constructor() {
this._isLoaded = false;
this._onLoaded = new ste_events_1.EventDispatcher();
}
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 && loadHandler) {
tsd.onLoaded.subscribe(loadHandler);
}
await tsd.load();
}
return tsd;
}
persist() { }
async load() {
if (this._isLoaded) {
return;
}
if (this._file === undefined) {
Log_1.default.unexpectedUndefined("TSCDF");
return;
}
await this._file.loadContent();
if (!this._file.content || this._file.content instanceof Uint8Array) {
return;
}
this._isLoaded = true;
this._onLoaded.dispatch(this, this);
}
}
exports.default = TypeScriptDefinition;
//# sourceMappingURL=../maps/minecraft/TypeScriptDefinition.js.map