asajs
Version:
Make your Minecraft JsonUI with ScriptingAPI
124 lines (123 loc) • 5.36 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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
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 __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
var Installer_exports = {};
__export(Installer_exports, {
ResourcePacks: () => ResourcePacks
});
module.exports = __toCommonJS(Installer_exports);
var import_fs = __toESM(require("fs"));
var import_Save = require("./generator/Save");
var import_UIBuilder = require("./generator/UIBuilder");
var import_Config = require("./Config");
class ResourcePacks {
constructor(data) {
__publicField(this, "gamePath");
__publicField(this, "gameDataPath");
__publicField(this, "installPath");
__publicField(this, "globalResoucePacksPath");
const config = import_Config.Configs.getConfig();
if (config.installer.installPath && config.installer.customPath) {
this.gamePath = config.installer.installPath;
} else {
switch (process.platform) {
case "win32":
this.gamePath = "".concat(process.env.LOCALAPPDATA, "/Packages/").concat(data.installGame, "/LocalState");
break;
case "linux":
this.gamePath = "".concat(process.env.HOME, "/.local/share/mcpelauncher");
if (!import_fs.default.existsSync(this.gamePath))
this.gamePath = "".concat(process.env.HOME, "/.var/app/io.mrarm.mcpelauncher/data/mcpelauncher");
break;
default:
this.gamePath = "";
}
}
this.gameDataPath = "".concat(this.gamePath, "/games/com.mojang");
this.installPath = "".concat(this.gameDataPath, "/").concat(data.installFolder);
this.globalResoucePacksPath = "".concat(this.gameDataPath, "/minecraftpe/global_resource_packs.json");
}
isPackInstalled(uuid, version) {
const globalResourcePacks = import_fs.default.existsSync(
this.globalResoucePacksPath
) ? JSON.parse(import_fs.default.readFileSync(this.globalResoucePacksPath, "utf-8")) : [];
const versionIsArray = Array.isArray(version);
if (versionIsArray) version = JSON.stringify(version);
for (const packData of globalResourcePacks) {
if (packData.pack_id === uuid && (versionIsArray ? JSON.stringify(packData.version) : packData.version) === version)
return true;
}
return false;
}
installPack(uuid, version) {
if (this.isPackInstalled(uuid, version)) return;
const globalResourcePacks = import_fs.default.existsSync(
this.globalResoucePacksPath
) ? JSON.parse(import_fs.default.readFileSync(this.globalResoucePacksPath, "utf-8")) : [];
import_fs.default.writeFileSync(
this.globalResoucePacksPath,
JSON.stringify([
{
pack_id: uuid,
version
},
...globalResourcePacks
]),
"utf-8"
);
}
uninstallPack(uuid, version) {
const globalResourcePacks = import_fs.default.existsSync(
this.globalResoucePacksPath
) ? JSON.parse(import_fs.default.readFileSync(this.globalResoucePacksPath, "utf-8")) : [];
const versionIsArray = Array.isArray(version);
if (versionIsArray) version = JSON.stringify(version);
let i = -1;
for (const packData of globalResourcePacks) {
i++;
if (packData.pack_id === uuid && (versionIsArray ? JSON.stringify(packData.version) : packData.version) === version) {
globalResourcePacks.splice(i, 1);
break;
}
}
import_fs.default.writeFileSync(this.globalResoucePacksPath, JSON.stringify(globalResourcePacks));
}
getInstallPath() {
return "".concat(this.installPath, "/").concat(import_Save.Save.getBuildID());
}
packLink() {
import_UIBuilder.UIBuilder.delete(".minecraft");
import_fs.default.symlinkSync(this.getInstallPath(), ".minecraft", "junction");
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ResourcePacks
});