UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

74 lines (73 loc) 4.07 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.CheckGeometryFormatInfoGeneratorTest = void 0; const ProjectInfoItem_1 = __importDefault(require("../ProjectInfoItem")); const IInfoItemData_1 = require("../IInfoItemData"); const IProjectItemData_1 = require("../../app/IProjectItemData"); const StorageUtilities_1 = __importDefault(require("../../storage/StorageUtilities")); var CheckGeometryFormatInfoGeneratorTest; (function (CheckGeometryFormatInfoGeneratorTest) { CheckGeometryFormatInfoGeneratorTest[CheckGeometryFormatInfoGeneratorTest["restrictedPolyMeshFound"] = 101] = "restrictedPolyMeshFound"; CheckGeometryFormatInfoGeneratorTest[CheckGeometryFormatInfoGeneratorTest["jsonParseError"] = 102] = "jsonParseError"; })(CheckGeometryFormatInfoGeneratorTest || (exports.CheckGeometryFormatInfoGeneratorTest = CheckGeometryFormatInfoGeneratorTest = {})); /*********** * Generator for Checking Geometry Format * * Will check: * * models folder JSON files for restricted "poly_mesh" string if project is not first party * * @see {@link ../../../public/data/forms/mctoolsval/geofmt.form.json} for topic definitions */ class CheckGeometryFormatInfoGenerator { id = "GEOFMT"; title = "Geometry Format"; canAlwaysProcess = true; summarize(info, infoSet) { info.restrictedPolyMeshFound = infoSet.getSummedDataValue(this.id, CheckGeometryFormatInfoGeneratorTest.restrictedPolyMeshFound); info.jsonParseError = infoSet.getSummedDataValue(this.id, CheckGeometryFormatInfoGeneratorTest.jsonParseError); } async generate(project) { const items = []; // This restriction is only on content from a 3rd party. poly_mesh is restricted to first party content. if (project.isMinecraftCreator === false) { const projItems = project.getItemsCopy(); for (const item of projItems) { if (item.itemType === IProjectItemData_1.ProjectItemType.modelGeometryJson) { if (!item.loadContent) { await item.loadContent(); } if (!item.primaryFile) { continue; } try { const jsonData = StorageUtilities_1.default.getJsonObject(item.primaryFile); if (jsonData && jsonData["minecraft:geometry"]) { const geometries = Array.isArray(jsonData["minecraft:geometry"]) ? jsonData["minecraft:geometry"] : [jsonData["minecraft:geometry"]]; for (const geometry of geometries) { if (geometry && geometry.bones) { for (const bone of geometry.bones) { if (bone && bone.poly_mesh) { items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, CheckGeometryFormatInfoGeneratorTest.restrictedPolyMeshFound, `Geometry bone "${bone.name || "unnamed"}" contains poly_mesh definition. This feature is not allowed!`, item, bone.name || "unnamed bone")); } } } } } } catch (error) { items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, CheckGeometryFormatInfoGeneratorTest.jsonParseError, `Failed to parse JSON for geometry file. Error: ${error}`, item)); } } } } return items; } } exports.default = CheckGeometryFormatInfoGenerator;