UNPKG

bc-minecraft-bedrock-project

Version:

The typescript library responsible for reading/parsing minecraft bedrock data

377 lines 14.6 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.BehaviorPack = void 0; const bc_minecraft_project_1 = require("bc-minecraft-project"); const types_1 = require("../../types"); const pack_type_1 = require("../pack-type"); const file_type_1 = require("./file-type"); const Animation = __importStar(require("./animation")); const AnimationController = __importStar(require("./animation-controller")); const Biome = __importStar(require("./biome")); const Block = __importStar(require("./block")); const Entity = __importStar(require("./entity")); const Feature = __importStar(require("./feature")); const FeatureRule = __importStar(require("./feature_rule")); const Item = __importStar(require("./item")); const ItemCatalog = __importStar(require("./item_catalog")); const LootTable = __importStar(require("./loot-table")); const Function = __importStar(require("./mcfunction")); const Recipe = __importStar(require("./recipe")); const Script = __importStar(require("./script")); const Structure = __importStar(require("./structure")); const Trading = __importStar(require("./trading")); const VoxelShape = __importStar(require("./voxel-shape")); /** */ class BehaviorPack { type = pack_type_1.PackType.behavior_pack; folder; context; manifest; /**The collection of animations*/ animations; /**The collection of animations controllers*/ animationControllers; /**The collection of biomes*/ biomes; /**The collection of blocks*/ blocks; /**The collection of entities*/ entities; /**The collection of features*/ features; /**The collection of features*/ featuresRules; /**The collection of mcfunctions*/ functions; /**The collection of items*/ itemGroups; /**The collection of items*/ items; /**The collection of loot tables*/ lootTables; /**The collection of recipes*/ recipes; /**The collection of structures*/ structures; /**The collection of trading tables*/ trading; /**The collection of voxel shapes*/ voxelShapes; /**The collection of script-defined custom commands*/ customCommands; /** * @param folder The folder of the behavior * @param context The Mcproject data or the filepath to read from.*/ constructor(folder, context, manifest) { this.folder = folder; this.manifest = manifest; this.context = typeof context === 'object' ? context : bc_minecraft_project_1.MCProject.loadSync(context); this.animations = new types_1.DataSet(); this.animationControllers = new types_1.DataSet(); this.biomes = new types_1.DataSet(); this.blocks = new types_1.DataSet(); this.entities = new types_1.DataSet(); this.functions = new types_1.DataSet(); this.items = new types_1.DataSet(); this.lootTables = new types_1.DataSet(); this.recipes = new types_1.DataSet(); this.structures = new types_1.DataSet(); this.trading = new types_1.DataSet(); this.features = new types_1.DataSet(); this.featuresRules = new types_1.DataSet(); this.itemGroups = new types_1.DataSet(); this.voxelShapes = new types_1.DataSet(); this.customCommands = new types_1.DataSet(); } /** * * @param doc */ process(doc) { this.deleteFile(doc.uri); const Type = file_type_1.FileType.detect(doc.uri); //If extended, also extend the delete switch (Type) { case file_type_1.FileType.animation: return this.animations.set(Animation.process(doc)); case file_type_1.FileType.animation_controller: return this.animationControllers.set(AnimationController.process(doc)); case file_type_1.FileType.block: return this.blocks.set(Block.process(doc)); case file_type_1.FileType.entity: return this.entities.set(Entity.process(doc)); case file_type_1.FileType.function: return this.functions.set(Function.process(doc)); case file_type_1.FileType.item: return this.items.set(Item.process(doc)); case file_type_1.FileType.loot_table: return this.lootTables.set(LootTable.process(doc)); case file_type_1.FileType.structure: return this.structures.set(Structure.process(doc)); case file_type_1.FileType.trading: return this.trading.set(Trading.process(doc)); case file_type_1.FileType.feature: return this.features.set(Feature.process(doc)); case file_type_1.FileType.feature_rule: return this.featuresRules.set(FeatureRule.process(doc)); case file_type_1.FileType.item_catalog: return this.itemGroups.set(ItemCatalog.process(doc)); case file_type_1.FileType.biome: return this.biomes.set(Biome.process(doc)); case file_type_1.FileType.recipe: return this.recipes.set(Recipe.process(doc)); case file_type_1.FileType.voxel_shape: return this.voxelShapes.set(VoxelShape.process(doc)); case file_type_1.FileType.script: return this.customCommands.set(Script.process(doc)); } return undefined; } /** * * @param uri * @returns */ getDataset(uri) { const Type = file_type_1.FileType.detect(uri); switch (Type) { case file_type_1.FileType.animation: return this.animations; case file_type_1.FileType.animation_controller: return this.animationControllers; case file_type_1.FileType.block: return this.blocks; case file_type_1.FileType.entity: return this.entities; case file_type_1.FileType.feature: return this.features; case file_type_1.FileType.feature_rule: return this.featuresRules; case file_type_1.FileType.function: return this.functions; case file_type_1.FileType.item: return this.items; case file_type_1.FileType.item_catalog: return this.itemGroups; case file_type_1.FileType.loot_table: return this.lootTables; case file_type_1.FileType.structure: return this.structures; case file_type_1.FileType.trading: return this.trading; case file_type_1.FileType.biome: return this.biomes; case file_type_1.FileType.recipe: return this.recipes; case file_type_1.FileType.voxel_shape: return this.voxelShapes; case file_type_1.FileType.script: return this.customCommands; default: return undefined; } } /** * * @param uri * @returns */ deleteFile(uri) { let out = false; out = this.animations.deleteFile(uri) || out; out = this.animationControllers.deleteFile(uri) || out; out = this.biomes.deleteFile(uri) || out; out = this.blocks.deleteFile(uri) || out; out = this.entities.deleteFile(uri) || out; out = this.features.deleteFile(uri) || out; out = this.featuresRules.deleteFile(uri) || out; out = this.functions.deleteFile(uri) || out; out = this.items.deleteFile(uri) || out; out = this.itemGroups.deleteFile(uri) || out; out = this.lootTables.deleteFile(uri) || out; out = this.recipes.deleteFile(uri) || out; out = this.structures.deleteFile(uri) || out; out = this.trading.deleteFile(uri) || out; out = this.voxelShapes.deleteFile(uri) || out; out = this.customCommands.deleteFile(uri) || out; return out; } /** * * @param uri */ deleteFolder(uri) { let out = false; out = this.animations.deleteFolder(uri) || out; out = this.animationControllers.deleteFolder(uri) || out; out = this.biomes.deleteFolder(uri) || out; out = this.blocks.deleteFolder(uri) || out; out = this.entities.deleteFolder(uri) || out; out = this.features.deleteFolder(uri) || out; out = this.featuresRules.deleteFolder(uri) || out; out = this.functions.deleteFolder(uri) || out; out = this.items.deleteFolder(uri) || out; out = this.itemGroups.deleteFolder(uri) || out; out = this.lootTables.deleteFolder(uri) || out; out = this.recipes.deleteFolder(uri) || out; out = this.structures.deleteFolder(uri) || out; out = this.trading.deleteFolder(uri) || out; out = this.voxelShapes.deleteFolder(uri) || out; out = this.customCommands.deleteFolder(uri) || out; return out; } /** * * @param predicate * @returns */ find(predicate) { let value; if ((value = this.animations.find(predicate))) return value; if ((value = this.animationControllers.find(predicate))) return value; if ((value = this.biomes.find(predicate))) return value; if ((value = this.blocks.find(predicate))) return value; if ((value = this.entities.find(predicate))) return value; if ((value = this.features.find(predicate))) return value; if ((value = this.featuresRules.find(predicate))) return value; if ((value = this.functions.find(predicate))) return value; if ((value = this.items.find(predicate))) return value; if ((value = this.itemGroups.find(predicate))) return value; if ((value = this.lootTables.find(predicate))) return value; if ((value = this.recipes.find(predicate))) return value; if ((value = this.structures.find(predicate))) return value; if ((value = this.trading.find(predicate))) return value; if ((value = this.voxelShapes.find(predicate))) return value; if ((value = this.customCommands.find(predicate))) return value; return value; } /** * * @param predicate * @returns */ forEach(callbackfn) { this.animations.forEach(callbackfn); this.animationControllers.forEach(callbackfn); this.biomes.forEach(callbackfn); this.blocks.forEach(callbackfn); this.entities.forEach(callbackfn); this.features.forEach(callbackfn); this.featuresRules.forEach(callbackfn); this.functions.forEach(callbackfn); this.items.forEach(callbackfn); this.itemGroups.forEach(callbackfn); this.lootTables.forEach(callbackfn); this.recipes.forEach(callbackfn); this.structures.forEach(callbackfn); this.trading.forEach(callbackfn); this.voxelShapes.forEach(callbackfn); this.customCommands.forEach(callbackfn); } } exports.BehaviorPack = BehaviorPack; /** * */ (function (BehaviorPack) { /** * * @param value * @returns */ function is(value) { if (typeof value === 'object') { const temp = value; //Order is determined buy likely / unlikely it is that it missing if (typeof temp.functions !== 'object') return false; if (typeof temp.items !== 'object') return false; if (typeof temp.lootTables !== 'object') return false; if (typeof temp.structures !== 'object') return false; if (typeof temp.trading !== 'object') return false; if (typeof temp.animations !== 'object') return false; if (typeof temp.animationControllers !== 'object') return false; if (typeof temp.blocks !== 'object') return false; if (typeof temp.entities !== 'object') return false; if (typeof temp.features !== 'object') return false; if (typeof temp.featuresRules !== 'object') return false; if (typeof temp.itemGroups !== 'object') return false; if (typeof temp.biomes !== 'object') return false; if (typeof temp.recipes !== 'object') return false; if (typeof temp.voxelShapes !== 'object') return false; if (typeof temp.customCommands !== 'object') return false; if (typeof temp.context !== 'object') return false; if (typeof temp.folder !== 'string') return false; return true; } return false; } BehaviorPack.is = is; })(BehaviorPack || (exports.BehaviorPack = BehaviorPack = {})); //# sourceMappingURL=behavior-pack.js.map