UNPKG

bedrock-development

Version:

APIs for creating and editing files related to Minecraft Bedrock development.

165 lines (164 loc) 5.64 kB
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()); }); }; import axios from "axios"; import { v4 } from "uuid"; import { MinecraftDataType } from "./minecraft.js"; import { Directories } from "../file_manager.js"; const VERSION = [1, 21, 2]; /** * @remarks A class for working with manifest files. */ export class Manifest extends MinecraftDataType { constructor(filepath, template) { super(filepath, template); this.format_version = template.format_version; this.header = template.header; this.modules = template.modules; this.dependencies = template.dependencies; this.metadata = template.metadata; } } export class WorldManifest extends Manifest { static get DirectoryPath() { return `Content/world_template/manifest.json`; } static createFromTemplate() { return new WorldManifest(this.DirectoryPath, { format_version: 2, header: { name: "pack.name", description: "pack.description", uuid: v4(), lock_template_options: true, version: [1, 0, 0], base_game_version: VERSION, pack_scope: "world" }, modules: [ { type: "world_template", uuid: v4(), version: [1, 0, 0] } ], metadata: { authors: [] } }); } addAuthors(authors) { var _a, _b; (_b = (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.authors) === null || _b === void 0 ? void 0 : _b.push(...authors); } } export class SkinsManifest extends Manifest { static get DirectoryPath() { return `Content/skin_pack/manifest.json`; } static createFromTemplate() { return new WorldManifest(this.DirectoryPath, { format_version: 1, header: { name: "pack.name", uuid: v4(), version: [1, 0, 0], }, modules: [ { type: "skin_pack", uuid: v4(), version: [1, 0, 0] } ] }); } } export class BehaviorManifest extends Manifest { static get DirectoryPath() { return Directories.BEHAVIOR_PATH + 'manifest.json'; } static createFromTemplate() { return new BehaviorManifest(this.DirectoryPath, { format_version: 2, header: { name: "pack.name", description: "pack.description", uuid: v4(), pack_scope: "world", version: [1, 0, 0], min_engine_version: VERSION }, modules: [ { type: "data", uuid: v4(), version: [1, 0, 0] }, { language: "javascript", type: "script", uuid: v4(), version: [1, 0, 0], entry: "scripts/main.js" } ], dependencies: [], }); } addDependencies(uuids, scripts) { uuids.forEach(uuid => { var _a; (_a = this.dependencies) === null || _a === void 0 ? void 0 : _a.push({ uuid, version: [1, 0, 0] }); }); scripts.forEach((script) => __awaiter(this, void 0, void 0, function* () { var _a; const version = yield getnpmLatestVersion(script); (_a = this.dependencies) === null || _a === void 0 ? void 0 : _a.push({ module_name: script, version }); })); } } export class ResourceManifest extends Manifest { static get DirectoryPath() { return Directories.RESOURCE_PATH + 'manifest.json'; } static createFromTemplate() { return new ResourceManifest(this.DirectoryPath, { format_version: 2, header: { name: "pack.name", description: "pack.description", uuid: v4(), pack_scope: "world", version: [1, 0, 0], min_engine_version: VERSION }, modules: [ { type: "resources", uuid: v4(), version: [1, 0, 0] } ], dependencies: [], }); } addDependencies(uuids) { uuids.forEach(uuid => { var _a; (_a = this.dependencies) === null || _a === void 0 ? void 0 : _a.push({ uuid, version: [1, 0, 0] }); }); } } function getnpmLatestVersion(pack) { return __awaiter(this, void 0, void 0, function* () { const result = yield axios.get(`https://registry.npmjs.org/${pack}/latest`); return result.data.version; }); }