"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.PackInfoGeneratorTest = void 0;
const ProjectInfoItem_1 = require("./ProjectInfoItem");
const IProjectItemData_1 = require("../app/IProjectItemData");
const IInfoItemData_1 = require("./IInfoItemData");
const StorageUtilities_1 = require("../storage/StorageUtilities");
const Utilities_1 = require("../core/Utilities");
const MinecraftUtilities_1 = require("../minecraft/MinecraftUtilities");
const ProjectInfoUtilities_1 = require("./ProjectInfoUtilities");
const MemoryTierBase = 40;
var PackInfoGeneratorTest;
(function (PackInfoGeneratorTest) {
    PackInfoGeneratorTest[PackInfoGeneratorTest["behaviorPackName"] = 104] = "behaviorPackName";
    PackInfoGeneratorTest[PackInfoGeneratorTest["behaviorPackDescription"] = 105] = "behaviorPackDescription";
    PackInfoGeneratorTest[PackInfoGeneratorTest["behaviorPackId"] = 106] = "behaviorPackId";
    PackInfoGeneratorTest[PackInfoGeneratorTest["behaviorPackMinEngineVersion"] = 107] = "behaviorPackMinEngineVersion";
    PackInfoGeneratorTest[PackInfoGeneratorTest["behaviorPackUuid"] = 108] = "behaviorPackUuid";
    PackInfoGeneratorTest[PackInfoGeneratorTest["behaviorPackManfiest"] = 109] = "behaviorPackManfiest";
    PackInfoGeneratorTest[PackInfoGeneratorTest["resourcePackMinEngineVersion"] = 111] = "resourcePackMinEngineVersion";
    PackInfoGeneratorTest[PackInfoGeneratorTest["resourcePackUuid"] = 112] = "resourcePackUuid";
    PackInfoGeneratorTest[PackInfoGeneratorTest["resourcePackManifest"] = 113] = "resourcePackManifest";
    PackInfoGeneratorTest[PackInfoGeneratorTest["resourcePackName"] = 114] = "resourcePackName";
    PackInfoGeneratorTest[PackInfoGeneratorTest["resourcePackDescription"] = 115] = "resourcePackDescription";
    PackInfoGeneratorTest[PackInfoGeneratorTest["resourcePackId"] = 116] = "resourcePackId";
    PackInfoGeneratorTest[PackInfoGeneratorTest["resourcePackFormatVersion"] = 117] = "resourcePackFormatVersion";
    PackInfoGeneratorTest[PackInfoGeneratorTest["subPacks"] = 118] = "subPacks";
    PackInfoGeneratorTest[PackInfoGeneratorTest["resourcePackIcon"] = 121] = "resourcePackIcon";
    PackInfoGeneratorTest[PackInfoGeneratorTest["behaviorPackIcon"] = 122] = "behaviorPackIcon";
    PackInfoGeneratorTest[PackInfoGeneratorTest["skinPackIcon"] = 123] = "skinPackIcon";
    PackInfoGeneratorTest[PackInfoGeneratorTest["subpackTiers"] = 245] = "subpackTiers";
})(PackInfoGeneratorTest = exports.PackInfoGeneratorTest || (exports.PackInfoGeneratorTest = {}));
class PackInfoGenerator {
    id = "PACK";
    title = "General info";
    canAlwaysProcess = true;
    getTopicData(topicId) {
        return {
            title: topicId.toString(),
        };
    }
    summarize(info, infoSet) {
        info.defaultBehaviorPackUuid = infoSet.getFirstStringValue(this.id, PackInfoGeneratorTest.behaviorPackUuid);
        info.defaultIcon = infoSet.getFirstStringValue(this.id, PackInfoGeneratorTest.resourcePackIcon);
        if (info.defaultIcon === undefined) {
            info.defaultIcon = infoSet.getFirstStringValue(this.id, PackInfoGeneratorTest.behaviorPackIcon);
        }
        // because it's heavy, remove pack icon from this list of issues. Though the summarize op is probably
        // the wrong place to do this.
        infoSet.removeItems(this.id, [PackInfoGeneratorTest.resourcePackIcon, PackInfoGeneratorTest.behaviorPackIcon]);
        info.defaultBehaviorPackMinEngineVersion = infoSet.getFirstNumberArrayValueAsVersionString(this.id, PackInfoGeneratorTest.behaviorPackMinEngineVersion);
        info.minBehaviorPackMinEngineVersionString = infoSet.getMinNumberArrayValueAsVersionString(this.id, PackInfoGeneratorTest.behaviorPackMinEngineVersion);
        info.minBehaviorPackMinEngineVersion = MinecraftUtilities_1.default.getVersionNumber(info.minBehaviorPackMinEngineVersionString);
        info.defaultBehaviorPackName = infoSet.getFirstNumberArrayValueAsVersionString(this.id, PackInfoGeneratorTest.behaviorPackName);
        info.defaultBehaviorPackDescription = infoSet.getFirstNumberArrayValueAsVersionString(this.id, PackInfoGeneratorTest.behaviorPackDescription);
        info.defaultResourcePackUuid = infoSet.getFirstStringValue(this.id, PackInfoGeneratorTest.resourcePackUuid);
        info.defaultResourcePackMinEngineVersion = infoSet.getFirstNumberArrayValueAsVersionString(this.id, PackInfoGeneratorTest.resourcePackMinEngineVersion);
        info.minResourcePackMinEngineVersionString = infoSet.getMinNumberArrayValueAsVersionString(this.id, PackInfoGeneratorTest.resourcePackMinEngineVersion);
        info.minResourcePackMinEngineVersion = MinecraftUtilities_1.default.getVersionNumber(info.minResourcePackMinEngineVersionString);
        info.defaultResourcePackName = infoSet.getFirstNumberArrayValueAsVersionString(this.id, PackInfoGeneratorTest.resourcePackName);
        info.defaultResourcePackDescription = infoSet.getFirstNumberArrayValueAsVersionString(this.id, PackInfoGeneratorTest.resourcePackDescription);
        info.subpackCount = infoSet.getFirstNumberDataValue(this.id, PackInfoGeneratorTest.subPacks);
    }
    async generate(project, contentIndex) {
        const memoryTiersPi = new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.featureAggregate, this.id, PackInfoGeneratorTest.subpackTiers, "Entity Geometry");
        const items = [memoryTiersPi];
        const itemsCopy = project.getItemsCopy();
        for (let i = 0; i < itemsCopy.length; i++) {
            const pi = itemsCopy[i];
            if (pi.itemType === IProjectItemData_1.ProjectItemType.packIconImage) {
                const itemFile = pi.primaryFile;
                if (itemFile) {
                    if (StorageUtilities_1.default.getBaseFromName(itemFile.name) === "pack_icon" &&
                        StorageUtilities_1.default.getTypeFromName(itemFile.name) === "png") {
                        await itemFile.loadContent(false);
                        if (itemFile.content && typeof itemFile.content !== "string") {
                            let index = PackInfoGeneratorTest.resourcePackIcon;
                            if (MinecraftUtilities_1.default.pathLooksLikeBehaviorPackName(itemFile.storageRelativePath)) {
                                index = PackInfoGeneratorTest.behaviorPackIcon;
                            }
                            else if (MinecraftUtilities_1.default.pathLooksLikeSkinPackName(itemFile.storageRelativePath)) {
                                index = PackInfoGeneratorTest.skinPackIcon;
                            }
                            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.info, this.id, index, ProjectInfoUtilities_1.default.getTitleFromEnum(PackInfoGeneratorTest, index), pi, Utilities_1.default.uint8ArrayToBase64(itemFile.content)));
                        }
                    }
                }
            }
            else if (pi.itemType === IProjectItemData_1.ProjectItemType.behaviorPackManifestJson) {
                const obj = (await pi.getJsonObject());
                if (obj) {
                    items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.info, this.id, PackInfoGeneratorTest.behaviorPackManfiest, ProjectInfoUtilities_1.default.getTitleFromEnum(PackInfoGeneratorTest, PackInfoGeneratorTest.behaviorPackManfiest), pi, JSON.stringify(obj)));
                    if (obj.format_version) {
                        items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.info, this.id, PackInfoGeneratorTest.behaviorPackMinEngineVersion, ProjectInfoUtilities_1.default.getTitleFromEnum(PackInfoGeneratorTest, PackInfoGeneratorTest.behaviorPackMinEngineVersion), pi, obj.format_version));
                    }
                    if (obj.header) {
                        if (obj.header.uuid) {
                            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.info, this.id, PackInfoGeneratorTest.behaviorPackUuid, ProjectInfoUtilities_1.default.getTitleFromEnum(PackInfoGeneratorTest, PackInfoGeneratorTest.behaviorPackUuid), pi, obj.header.uuid));
                        }
                        if (obj.header.uuid && obj.header.version) {
                            if (obj.header.version.length === 3) {
                                items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.info, this.id, PackInfoGeneratorTest.behaviorPackId, ProjectInfoUtilities_1.default.getTitleFromEnum(PackInfoGeneratorTest, PackInfoGeneratorTest.behaviorPackId), pi, obj.header.uuid +
                                    "|" +
                                    obj.header.version[0] +
                                    "." +
                                    obj.header.version[1] +
                                    "." +
                                    obj.header.version[2]));
                            }
                        }
                        if (obj.header.name) {
                            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.info, this.id, PackInfoGeneratorTest.behaviorPackName, ProjectInfoUtilities_1.default.getTitleFromEnum(PackInfoGeneratorTest, PackInfoGeneratorTest.behaviorPackName), pi, project.loc.getExpandedValue(obj.header.name)));
                        }
                        if (obj.header.description) {
                            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.info, this.id, PackInfoGeneratorTest.behaviorPackDescription, ProjectInfoUtilities_1.default.getTitleFromEnum(PackInfoGeneratorTest, PackInfoGeneratorTest.behaviorPackDescription), pi, project.loc.getExpandedValue(obj.header.description)));
                        }
                        if (obj.header.min_engine_version) {
                            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.info, this.id, PackInfoGeneratorTest.behaviorPackMinEngineVersion, ProjectInfoUtilities_1.default.getTitleFromEnum(PackInfoGeneratorTest, PackInfoGeneratorTest.behaviorPackMinEngineVersion), pi, obj.header.min_engine_version));
                        }
                    }
                }
            }
            else if (pi.itemType === IProjectItemData_1.ProjectItemType.resourcePackManifestJson) {
                const obj = (await pi.getJsonObject());
                if (obj) {
                    items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.info, this.id, PackInfoGeneratorTest.resourcePackManifest, ProjectInfoUtilities_1.default.getTitleFromEnum(PackInfoGeneratorTest, PackInfoGeneratorTest.resourcePackManifest), pi, JSON.stringify(obj)));
                    if (obj.subpacks) {
                        if (Array.isArray(obj.subpacks)) {
                            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.info, this.id, 18, "Subpacks", pi, obj.subpacks.length));
                            for (const sp of obj.subpacks) {
                                if (sp.memory_tier) {
                                    memoryTiersPi.spectrumIntFeature("Memory Tier", sp.memory_tier);
                                    items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.info, this.id, MemoryTierBase + sp.memory_tier, "Subpack Memory Tier " + sp.memory_tier, pi, sp.name));
                                }
                            }
                        }
                    }
                    if (obj.format_version) {
                        items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.info, this.id, PackInfoGeneratorTest.resourcePackFormatVersion, ProjectInfoUtilities_1.default.getTitleFromEnum(PackInfoGeneratorTest, PackInfoGeneratorTest.resourcePackFormatVersion), pi, obj.format_version));
                    }
                    if (obj.header) {
                        if (obj.header.uuid) {
                            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.info, this.id, PackInfoGeneratorTest.resourcePackUuid, ProjectInfoUtilities_1.default.getTitleFromEnum(PackInfoGeneratorTest, PackInfoGeneratorTest.resourcePackUuid), pi, obj.header.uuid));
                        }
                        if (obj.header.uuid && obj.header.version) {
                            if (obj.header.version.length === 3) {
                                items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.info, this.id, PackInfoGeneratorTest.resourcePackId, ProjectInfoUtilities_1.default.getTitleFromEnum(PackInfoGeneratorTest, PackInfoGeneratorTest.resourcePackId), pi, obj.header.uuid +
                                    "|" +
                                    obj.header.version[0] +
                                    "." +
                                    obj.header.version[1] +
                                    "." +
                                    obj.header.version[2]));
                            }
                        }
                        if (obj.header.name) {
                            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.info, this.id, PackInfoGeneratorTest.resourcePackName, ProjectInfoUtilities_1.default.getTitleFromEnum(PackInfoGeneratorTest, PackInfoGeneratorTest.resourcePackName), pi, project.loc.getExpandedValue(obj.header.name)));
                        }
                        if (obj.header.description) {
                            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.info, this.id, PackInfoGeneratorTest.resourcePackDescription, ProjectInfoUtilities_1.default.getTitleFromEnum(PackInfoGeneratorTest, PackInfoGeneratorTest.resourcePackDescription), pi, project.loc.getExpandedValue(obj.header.description)));
                        }
                        if (obj.header.min_engine_version) {
                            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.info, this.id, PackInfoGeneratorTest.resourcePackMinEngineVersion, ProjectInfoUtilities_1.default.getTitleFromEnum(PackInfoGeneratorTest, PackInfoGeneratorTest.resourcePackMinEngineVersion), pi, obj.header.min_engine_version));
                        }
                    }
                }
            }
        }
        return items;
    }
}
exports.default = PackInfoGenerator;

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