@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
109 lines (107 loc) • 3.43 kB
JavaScript
;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
const ste_events_1 = require("ste-events");
const ProjectItemManager_1 = require("../app/ProjectItemManager");
const StorageUtilities_1 = require("../storage/StorageUtilities");
class AudioDefinition {
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;
}
get id() {
if (this._file) {
return this._file.name;
}
return this._id;
}
set id(newId) {
this._id = newId;
}
static async ensureOnFile(file, loadHandler) {
let afd;
if (file.manager === undefined) {
afd = new AudioDefinition();
afd.file = file;
file.manager = afd;
}
if (file.manager !== undefined && file.manager instanceof AudioDefinition) {
afd = file.manager;
if (!afd.isLoaded && loadHandler) {
afd.onLoaded.subscribe(loadHandler);
}
await afd.load();
}
return afd;
}
persist() {
if (this._file === undefined) {
return;
}
}
static canonicalizeAudioPath(projectPath) {
if (projectPath === undefined) {
return undefined;
}
projectPath = projectPath.toLowerCase();
const lastPeriod = projectPath.lastIndexOf(".");
if (lastPeriod >= 0) {
const removedPart = projectPath.substring(lastPeriod + 1);
if (StorageUtilities_1.AllowedExtensions.includes(removedPart)) {
projectPath = projectPath.substring(0, lastPeriod);
}
}
/*
Log.assert(
projectPath.startsWith("sounds/") || projectPath.startsWith("music/") || projectPath.startsWith("$"),
"Unexpected audio path: " + projectPath
);*/
return projectPath;
}
async ensureSoundDefinitionsForFile(project) {
if (!this._file) {
return;
}
let soundDefinitionCat = await ProjectItemManager_1.default.ensureSoundDefinitionCatalogDefinition(project);
if (this._file && soundDefinitionCat) {
let matches = soundDefinitionCat.getSoundDefinitionMatchesByPath(this._file);
if (matches) {
let keyCount = 0;
for (const key in matches) {
if (key) {
keyCount++;
}
}
if (keyCount === 0) {
soundDefinitionCat.ensureDefintionForFile(project, this._file);
}
}
soundDefinitionCat.persist();
}
}
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._isLoaded = true;
}
}
exports.default = AudioDefinition;
//# sourceMappingURL=../maps/minecraft/AudioDefinition.js.map