UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

103 lines (102 loc) 5.48 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.BlocksCatalogInfo = exports.BlocksCatalogUpdate = void 0; const ProjectInfoItem_1 = __importDefault(require("../info/ProjectInfoItem")); const IProjectItemData_1 = require("../app/IProjectItemData"); const IInfoItemData_1 = require("../info/IInfoItemData"); const ProjectUpdateResult_1 = __importDefault(require("../updates/ProjectUpdateResult")); const IUpdateResult_1 = require("../updates/IUpdateResult"); const BlocksCatalogDefinition_1 = __importDefault(require("../minecraft/BlocksCatalogDefinition")); var BlocksCatalogUpdate; (function (BlocksCatalogUpdate) { BlocksCatalogUpdate[BlocksCatalogUpdate["removeUnusedBlockResourceIdentifiers"] = 1051] = "removeUnusedBlockResourceIdentifiers"; })(BlocksCatalogUpdate || (exports.BlocksCatalogUpdate = BlocksCatalogUpdate = {})); var BlocksCatalogInfo; (function (BlocksCatalogInfo) { BlocksCatalogInfo[BlocksCatalogInfo["unusedBlockCatalogResource"] = 100] = "unusedBlockCatalogResource"; BlocksCatalogInfo[BlocksCatalogInfo["foundBlockCatalogResource"] = 101] = "foundBlockCatalogResource"; BlocksCatalogInfo[BlocksCatalogInfo["vanillaOverrideBlockCatalogResource"] = 102] = "vanillaOverrideBlockCatalogResource"; BlocksCatalogInfo[BlocksCatalogInfo["blockResourceIdentifier"] = 53] = "blockResourceIdentifier"; })(BlocksCatalogInfo || (exports.BlocksCatalogInfo = BlocksCatalogInfo = {})); /** * Validates and manages blocks catalog (blocks.json) resources in resource packs. * * @see {@link ../../../public/data/forms/mctoolsval/blockscat.form.json} for topic definitions */ class BlocksCatalogManager { id = "BLOCKSCAT"; title = "Blocks Catalog"; getUpdaterData(updaterId) { return { title: updaterId.toString(), }; } summarize(info, infoSet) { } async generate(project, contentIndex) { const results = []; const itemsCopy = project.getItemsCopy(); for (let i = 0; i < itemsCopy.length; i++) { const pi = itemsCopy[i]; if (pi.itemType === IProjectItemData_1.ProjectItemType.blocksCatalogResourceJson) { if (!pi.isContentLoaded) { await pi.loadContent(); } if (pi.primaryFile) { const blocksCatalog = await BlocksCatalogDefinition_1.default.ensureOnFile(pi.primaryFile); results.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.info, this.id, BlocksCatalogInfo.foundBlockCatalogResource, `Blocks catalog resource found`, pi)); if (blocksCatalog) { const dependencies = await blocksCatalog.getDependenciesList(project); for (const id of dependencies.unused) { results.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.warning, this.id, BlocksCatalogInfo.unusedBlockCatalogResource, `Blocks catalog resource is not used`, pi, id)); } for (const id of dependencies.vanillaOverride) { results.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.recommendation, this.id, BlocksCatalogInfo.vanillaOverrideBlockCatalogResource, `Overrides vanilla resource, which is not recommended`, pi, id)); } } } } } return results; } async update(project, updateId) { const results = []; const itemsCopy = project.getItemsCopy(); for (let i = 0; i < itemsCopy.length; i++) { const pi = itemsCopy[i]; if (pi.itemType === IProjectItemData_1.ProjectItemType.blocksCatalogResourceJson) { if (!pi.isContentLoaded) { await pi.loadContent(); } if (pi.primaryFile) { const blocksCatalog = await BlocksCatalogDefinition_1.default.ensureOnFile(pi.primaryFile); let wasUpdated = false; if (blocksCatalog) { switch (updateId) { case BlocksCatalogUpdate.removeUnusedBlockResourceIdentifiers: const dependencies = await blocksCatalog.getDependenciesList(project); for (const id of dependencies.unused) { blocksCatalog.removeId(id); wasUpdated = true; results.push(new ProjectUpdateResult_1.default(IUpdateResult_1.UpdateResultType.updatedFile, this.id, BlocksCatalogUpdate.removeUnusedBlockResourceIdentifiers, "Removed ununused blocks catalog resource", pi, id)); } break; } } if (wasUpdated) { blocksCatalog?.persist(); } } } } return results; } getUpdateIds() { return [BlocksCatalogUpdate.removeUnusedBlockResourceIdentifiers]; } } exports.default = BlocksCatalogManager;