"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.TextureReferenceInfoGeneratorTest = void 0;
const ProjectInfoItem_1 = require("./ProjectInfoItem");
const IProjectItemData_1 = require("../app/IProjectItemData");
const IInfoItemData_1 = require("./IInfoItemData");
const BlocksCatalogDefinition_1 = require("../minecraft/BlocksCatalogDefinition");
const TerrainTextureCatalogDefinition_1 = require("../minecraft/TerrainTextureCatalogDefinition");
const ItemTextureCatalogDefinition_1 = require("../minecraft/ItemTextureCatalogDefinition");
const ContentIndex_1 = require("../core/ContentIndex");
const ProjectInfoUtilities_1 = require("./ProjectInfoUtilities");
var TextureReferenceInfoGeneratorTest;
(function (TextureReferenceInfoGeneratorTest) {
    TextureReferenceInfoGeneratorTest[TextureReferenceInfoGeneratorTest["textureReferences"] = 101] = "textureReferences";
})(TextureReferenceInfoGeneratorTest = exports.TextureReferenceInfoGeneratorTest || (exports.TextureReferenceInfoGeneratorTest = {}));
class TextureReferenceInfoGenerator {
    id = "TEXTUREREF";
    title = "Texture Reference Info Aggregation";
    performAddOnValidations = false;
    getTopicData(topicId) {
        return {
            title: ProjectInfoUtilities_1.default.getTitleFromEnum(TextureReferenceInfoGeneratorTest, topicId),
        };
    }
    summarize(info, infoSet) {
        info.textureCount = infoSet.getSummedDataValue(this.id, TextureReferenceInfoGeneratorTest.textureReferences);
    }
    async generate(project, contentIndex) {
        const items = [];
        const textureRefCountPi = new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.featureAggregate, this.id, TextureReferenceInfoGeneratorTest.textureReferences, "Texture References");
        items.push(textureRefCountPi);
        const itemsCopy = project.getItemsCopy();
        for (const projectItem of itemsCopy) {
            if (projectItem.itemType === IProjectItemData_1.ProjectItemType.blocksCatalogResourceJson) {
                if (!projectItem.isContentLoaded) {
                    await projectItem.loadContent();
                }
                if (projectItem.primaryFile) {
                    const blockCat = await BlocksCatalogDefinition_1.default.ensureOnFile(projectItem.primaryFile);
                    if (blockCat && blockCat.blocksCatalog && projectItem.projectPath) {
                        const textureRefs = blockCat.getTextureReferences();
                        for (const textureRef of textureRefs) {
                            contentIndex.insert(textureRef, projectItem.projectPath, ContentIndex_1.AnnotationCategory.blockTextureReferenceDependent);
                        }
                    }
                }
            }
            else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.terrainTextureCatalogResourceJson) {
                if (!projectItem.isContentLoaded) {
                    await projectItem.loadContent();
                }
                if (projectItem.primaryFile) {
                    const blockCat = await TerrainTextureCatalogDefinition_1.default.ensureOnFile(projectItem.primaryFile);
                    if (blockCat && projectItem.projectPath) {
                        const textureRefs = blockCat.getTextureReferences();
                        for (const textureRef of textureRefs) {
                            contentIndex.insert(textureRef, projectItem.projectPath, ContentIndex_1.AnnotationCategory.blockTextureReferenceSource);
                        }
                    }
                }
            }
            else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.itemTextureJson) {
                if (!projectItem.isContentLoaded) {
                    await projectItem.loadContent();
                }
                if (projectItem.primaryFile) {
                    const itemCat = await ItemTextureCatalogDefinition_1.default.ensureOnFile(projectItem.primaryFile);
                    if (itemCat && projectItem.projectPath) {
                        const textureRefs = itemCat.getTextureReferences();
                        for (const textureRef of textureRefs) {
                            contentIndex.insert(textureRef, projectItem.projectPath, ContentIndex_1.AnnotationCategory.itemTextureReferenceSource);
                        }
                    }
                }
            }
        }
        return items;
    }
}
exports.default = TextureReferenceInfoGenerator;

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