"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.GeometryInfoGeneratorTest = void 0;
const ProjectInfoItem_1 = require("./ProjectInfoItem");
const IProjectItemData_1 = require("../app/IProjectItemData");
const IInfoItemData_1 = require("./IInfoItemData");
const ProjectInfoUtilities_1 = require("./ProjectInfoUtilities");
const ModelGeometryDefinition_1 = require("../minecraft/ModelGeometryDefinition");
var GeometryInfoGeneratorTest;
(function (GeometryInfoGeneratorTest) {
    GeometryInfoGeneratorTest[GeometryInfoGeneratorTest["blockGeometry"] = 101] = "blockGeometry";
    GeometryInfoGeneratorTest[GeometryInfoGeneratorTest["entityGeometry"] = 102] = "entityGeometry";
    GeometryInfoGeneratorTest[GeometryInfoGeneratorTest["itemGeometry"] = 103] = "itemGeometry";
    GeometryInfoGeneratorTest[GeometryInfoGeneratorTest["overlyComplexBlockGeometry"] = 501] = "overlyComplexBlockGeometry";
})(GeometryInfoGeneratorTest = exports.GeometryInfoGeneratorTest || (exports.GeometryInfoGeneratorTest = {}));
class GeometryInfoGenerator {
    id = "GEOMETRY";
    title = "Model Geometry Validation";
    getTopicData(topicId) {
        return {
            title: ProjectInfoUtilities_1.default.getTitleFromEnum(GeometryInfoGeneratorTest, topicId),
        };
    }
    summarize(info, infoSet) { }
    async generate(project, contentIndex) {
        const itemsCopy = project.getItemsCopy();
        const blockGeometryPi = new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.featureAggregate, this.id, GeometryInfoGeneratorTest.blockGeometry, "Block Geometry");
        const entityGeometryPi = new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.featureAggregate, this.id, GeometryInfoGeneratorTest.entityGeometry, "Entity Geometry");
        const itemGeometryPi = new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.featureAggregate, this.id, GeometryInfoGeneratorTest.itemGeometry, "Items Geometry");
        const items = [blockGeometryPi, entityGeometryPi, itemGeometryPi];
        for (const projectItem of itemsCopy) {
            if (projectItem.itemType === IProjectItemData_1.ProjectItemType.modelGeometryJson) {
                await projectItem.ensureFileStorage();
                if (projectItem.primaryFile) {
                    const srPath = projectItem.primaryFile.storageRelativePath.toLowerCase();
                    const modGeo = await ModelGeometryDefinition_1.default.ensureOnFile(projectItem.primaryFile);
                    if (modGeo && modGeo.definitions) {
                        for (const geoDef of modGeo.definitions) {
                            if (geoDef.bones) {
                                let totalCubes = 0;
                                for (const bone of geoDef.bones) {
                                    if (bone.cubes) {
                                        totalCubes += bone.cubes.length;
                                    }
                                }
                                if (srPath.indexOf("/blocks/") >= 0) {
                                    blockGeometryPi.spectrumIntFeature("Cubes", totalCubes);
                                    const blockCubeBudget = 50;
                                    if (totalCubes > blockCubeBudget) {
                                        items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.warning, this.id, GeometryInfoGeneratorTest.overlyComplexBlockGeometry, `More than ${blockCubeBudget} cubes in custom blocks may lead to degraded performance. Cubes used`, projectItem, totalCubes));
                                    }
                                }
                                else if (srPath.indexOf("/items/") >= 0 || srPath.indexOf("/attachable") >= 0) {
                                    // note that sometimes this is in /entity, e.g., /entity/attachables, so this check needs to be first
                                    itemGeometryPi.spectrumIntFeature("Cubes", totalCubes);
                                }
                                else if (srPath.indexOf("/entity/") >= 0) {
                                    entityGeometryPi.spectrumIntFeature("Cubes", totalCubes);
                                }
                            }
                        }
                    }
                }
            }
        }
        return items;
    }
}
exports.default = GeometryInfoGenerator;

//# sourceMappingURL=../maps/info/GeometryInfoGenerator.js.map
