"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.CheckGeometryFormatInfoGeneratorTest = void 0;
const ProjectInfoItem_1 = require("../ProjectInfoItem");
const IInfoItemData_1 = require("../IInfoItemData");
const ProjectInfoUtilities_1 = require("../ProjectInfoUtilities");
const IProjectItemData_1 = require("../../app/IProjectItemData");
const StorageUtilities_1 = require("../../storage/StorageUtilities");
var CheckGeometryFormatInfoGeneratorTest;
(function (CheckGeometryFormatInfoGeneratorTest) {
    CheckGeometryFormatInfoGeneratorTest[CheckGeometryFormatInfoGeneratorTest["restrictedPolyMeshFound"] = 101] = "restrictedPolyMeshFound";
    CheckGeometryFormatInfoGeneratorTest[CheckGeometryFormatInfoGeneratorTest["jsonParseError"] = 102] = "jsonParseError";
})(CheckGeometryFormatInfoGeneratorTest = exports.CheckGeometryFormatInfoGeneratorTest || (exports.CheckGeometryFormatInfoGeneratorTest = {}));
/***********
 * Generator for Checking Geometry Format
 *
 * Will check:
 *  * models folder JSON files for restricted "poly_mesh" string if project is not first party
 *
 */
class CheckGeometryFormatInfoGenerator {
    id = "GEOFMT";
    title = "Geometry Format";
    canAlwaysProcess = true;
    getTopicData(topicId) {
        return {
            title: ProjectInfoUtilities_1.default.getTitleFromEnum(CheckGeometryFormatInfoGeneratorTest, topicId),
        };
    }
    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;

//# sourceMappingURL=../../maps/info/projectGenerators/CheckGeometryFormatInfoGenerator.js.map
