bedrock-development
Version:
APIs for creating and editing files related to Minecraft Bedrock development.
70 lines (69 loc) • 3.57 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var _a;
import { chalk } from "../../utils.js";
import { MOJANG, MinecraftWorld } from "../../types/index.js";
import { Option } from "commander";
import { createInterface } from "readline";
import { Directories } from "../../file_manager.js";
import { CommandMap } from "../command_map.js";
CommandMap.addCommand("root.world.packs", {
parent: (_a = CommandMap.getCommandEntry("root.world")) === null || _a === void 0 ? void 0 : _a.command,
commandOptions(command) {
command
.name("packs")
.description("attach packs to world")
.option("-w --world <name|index>", "the name or index of the world to add packs to")
.addOption(new Option("-b, --bpack <folder name>", "the name of the behavior pack to add"))
.addOption(new Option("-r, --rpack <folder name>", "the name of the resource pack to add"))
.addOption(new Option("-l, --local", "use the local packs in this workspace"))
.addOption(new Option("-d, --delete", "should the packs be removed"));
},
commandAction: triggerWorldsPacks,
});
function triggerWorldsPacks(options) {
return __awaiter(this, void 0, void 0, function* () {
const worlds = MinecraftWorld.getAllWorlds();
if (!options.world) {
yield new Promise(resolve => {
const readline = createInterface({
input: process.stdin,
output: process.stdout
});
const worldOptions = worlds.map((world, index) => `[${index}] ${chalk.green(`${world.Name}`)}`);
readline.question(`Select World \n${worldOptions.join('\n')}\nIndex or Name: `, (selection) => {
options.world = selection;
readline.close();
resolve();
});
});
}
if (options.local) {
options.bpack = Directories.BEHAVIOR_PATH + 'manifest.json';
options.rpack = Directories.RESOURCE_PATH + 'manifest.json';
}
else {
options.bpack = MOJANG + '/development_behavior_packs/' + options.bpack + '/manifest.json';
options.rpack = MOJANG + '/development_resource_packs/' + options.rpack + '/manifest.json';
}
const selectedWorld = worlds.find((worldOption, index) => index === Number(options.world) || worldOption.Name === options.world);
if (selectedWorld) {
if (options.bpack) {
selectedWorld.addPack(MinecraftWorld.getPackFromManifest(options.bpack));
}
if (options.rpack) {
selectedWorld.addPack(MinecraftWorld.getPackFromManifest(options.rpack));
}
}
else {
console.error(`${chalk.red(`${options.world} does not match the any names or indices in the world list`)}`);
}
});
}