"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.CheckExperimentalFlagInfoGeneratorTest = void 0;
const ProjectInfoItem_1 = require("../ProjectInfoItem");
const IInfoItemData_1 = require("../IInfoItemData");
const ProjectInfoUtilities_1 = require("../ProjectInfoUtilities");
const IProjectItemData_1 = require("../../app/IProjectItemData");
const MCWorld_1 = require("../../minecraft/MCWorld");
var CheckExperimentalFlagInfoGeneratorTest;
(function (CheckExperimentalFlagInfoGeneratorTest) {
    CheckExperimentalFlagInfoGeneratorTest[CheckExperimentalFlagInfoGeneratorTest["flagIsOrWasTrue"] = 101] = "flagIsOrWasTrue";
    CheckExperimentalFlagInfoGeneratorTest[CheckExperimentalFlagInfoGeneratorTest["levelDatNotFound"] = 102] = "levelDatNotFound";
    CheckExperimentalFlagInfoGeneratorTest[CheckExperimentalFlagInfoGeneratorTest["worldNotFound"] = 103] = "worldNotFound";
})(CheckExperimentalFlagInfoGeneratorTest = exports.CheckExperimentalFlagInfoGeneratorTest || (exports.CheckExperimentalFlagInfoGeneratorTest = {}));
/***********
 * Generator for Checking Experimental Flag for world
 *
 * Will ensure:
 *  * experimental flag is false and has always been false or null
 *
 */
class CheckExperimentalFlagInfoGenerator {
    id = "EXPFLAG";
    title = "Check Experimental Flag";
    getTopicData(topicId) {
        return {
            title: ProjectInfoUtilities_1.default.getTitleFromEnum(CheckExperimentalFlagInfoGeneratorTest, topicId),
        };
    }
    summarize(info, infoSet) {
        info.flagIsOrWasTrue = infoSet.getSummedDataValue(this.id, CheckExperimentalFlagInfoGeneratorTest.flagIsOrWasTrue);
        info.levelDatNotFound = infoSet.getSummedDataValue(this.id, CheckExperimentalFlagInfoGeneratorTest.levelDatNotFound);
        info.worldNotFound = infoSet.getSummedDataValue(this.id, CheckExperimentalFlagInfoGeneratorTest.worldNotFound);
    }
    async generate(project) {
        const items = [];
        const projItems = project.getItemsCopy();
        for (const item of projItems) {
            if (item.itemType !== IProjectItemData_1.ProjectItemType.MCWorld &&
                item.itemType !== IProjectItemData_1.ProjectItemType.MCTemplate &&
                item.itemType !== IProjectItemData_1.ProjectItemType.worldFolder &&
                item.itemType !== IProjectItemData_1.ProjectItemType.levelDat) {
                continue;
            }
            const mcworld = await MCWorld_1.default.ensureOnItem(item);
            if (!mcworld) {
                items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.warning, this.id, CheckExperimentalFlagInfoGeneratorTest.worldNotFound, "Could not load world.", item));
                continue;
            }
            await mcworld.load();
            await mcworld.loadData(false);
            if (!mcworld.levelData) {
                items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.warning, this.id, CheckExperimentalFlagInfoGeneratorTest.levelDatNotFound, "Could not load world file.", item));
                continue;
            }
            if (mcworld.levelData.experimentalGameplay === true || mcworld.levelData.experimentsEverUsed === true) {
                items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.warning, this.id, CheckExperimentalFlagInfoGeneratorTest.flagIsOrWasTrue, "Experimental gameplay is or was enabled in this world. Marketplace submissions cannot use experimental features.", item));
            }
        }
        return items;
    }
}
exports.default = CheckExperimentalFlagInfoGenerator;

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