asajs
Version:
Make your Minecraft JsonUI with ScriptingAPI
92 lines (91 loc) • 3.37 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var Sounds_exports = {};
__export(Sounds_exports, {
SoundHandler: () => SoundHandler
});
module.exports = __toCommonJS(Sounds_exports);
var import_fs = __toESM(require("fs"));
var import_jsonc_parser = require("jsonc-parser");
var import_Class = require("../../components/Class");
var import_Random = require("../../components/Random");
var import_PreCompile = require("../PreCompile");
const sounds = {};
class SoundHandler extends import_Class.Class {
static get(path) {
if (sounds[path]) {
return sounds[path];
} else {
return sounds[path] = "jsonui_scripting.".concat(import_Random.Random.getName());
}
}
static compile(installPath) {
const soundIds = Object.keys(sounds);
if (soundIds.length) {
if (!import_fs.default.existsSync("".concat(installPath, "/sounds"))) import_fs.default.mkdirSync("".concat(installPath, "/sounds"));
const soundDefinitions = {};
for (const soundPath of soundIds) {
const soundId = sounds[soundPath];
soundDefinitions[soundId] = {
category: "ui",
sounds: [
{
load_on_low_memory: true,
name: soundPath,
stream: true,
volume: 1
}
]
};
}
let bak;
if (import_fs.default.existsSync(".bedrock/sounds/sound_definitions.json")) {
bak = (0, import_jsonc_parser.parse)(
import_fs.default.readFileSync(".bedrock/sounds/sound_definitions.json", "utf-8")
).sound_definitions;
}
(0, import_PreCompile.UIWriteJson)(
"".concat(installPath, "/sounds/sound_definitions.json"),
{
format_version: "1.20.20",
sound_definitions: {
...bak,
...soundDefinitions
}
},
"utf-8"
);
}
return soundIds.length;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
SoundHandler
});