"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ContentIndex_1 = require("../core/ContentIndex");
const LookupUtilities_1 = require("./LookupUtilities");
class ProjectLookupUtilities {
    static referenceCache = {};
    static cacheIteration = 0;
    static async getLookup(project, lookupId) {
        switch (lookupId.toLowerCase()) {
            case "blocktype":
                return await this.getBlockTypeReferences(project);
            case "entitytype":
                return await this.getEntityTypeReferences(project);
            case "itemtype":
                return await this.getItemTypeReferences(project);
            case "entitytypeevents":
                break;
            case "difficulty":
                break;
            case "damagecause":
                break;
            case "loottable":
                break;
            case "sounddefinition":
                return await this.getSoundDefinitionReferences(project);
            case "itemtexture":
                return await this.getItemTextureReferences(project);
            case "terraintexture":
                return await this.getTerrainTextureReferences(project);
            case "entitytypeplusvariants":
                break;
        }
        return undefined;
    }
    static async getBlockTypeReferences(project) {
        if (project.infoSet.contentIndex.iteration !== ProjectLookupUtilities.cacheIteration) {
            ProjectLookupUtilities.cacheIteration = project.infoSet.contentIndex.iteration;
            ProjectLookupUtilities.referenceCache = {};
        }
        if (ProjectLookupUtilities.referenceCache["blockType"]) {
            return ProjectLookupUtilities.referenceCache["blockType"];
        }
        await project.ensureInfoSetGenerated();
        let simpleRefs = [];
        const refs = LookupUtilities_1.default.getReferencesFromAnnotatedValues(project.infoSet.contentIndex.getAll([ContentIndex_1.AnnotationCategory.blockTypeSource]), ContentIndex_1.AnnotationCategory.blockTypeSource, "{0} block type from " + project.name);
        if (refs) {
            LookupUtilities_1.default.sortReferences(refs);
            simpleRefs = refs;
        }
        LookupUtilities_1.default.appendReferences(simpleRefs, await LookupUtilities_1.default.getLookup("blockType"));
        ProjectLookupUtilities.referenceCache["blockType"] = simpleRefs;
        return simpleRefs;
    }
    static async getEntityTypeReferences(project) {
        if (project.infoSet.contentIndex.iteration !== ProjectLookupUtilities.cacheIteration) {
            ProjectLookupUtilities.cacheIteration = project.infoSet.contentIndex.iteration;
            ProjectLookupUtilities.referenceCache = {};
        }
        if (ProjectLookupUtilities.referenceCache["entityType"]) {
            return ProjectLookupUtilities.referenceCache["entityType"];
        }
        await project.ensureInfoSetGenerated();
        let simpleRefs = [];
        const refs = LookupUtilities_1.default.getReferencesFromAnnotatedValues(project.infoSet.contentIndex.getAll([ContentIndex_1.AnnotationCategory.blockTypeSource]), ContentIndex_1.AnnotationCategory.entityTypeSource, "{0} entity type from " + project.name);
        if (refs) {
            LookupUtilities_1.default.sortReferences(refs);
            simpleRefs = refs;
        }
        LookupUtilities_1.default.appendReferences(simpleRefs, await LookupUtilities_1.default.getLookup("entityType"));
        ProjectLookupUtilities.referenceCache["entityType"] = simpleRefs;
        return simpleRefs;
    }
    static async getItemTypeReferences(project) {
        if (project.infoSet.contentIndex.iteration !== ProjectLookupUtilities.cacheIteration) {
            ProjectLookupUtilities.cacheIteration = project.infoSet.contentIndex.iteration;
            ProjectLookupUtilities.referenceCache = {};
        }
        if (ProjectLookupUtilities.referenceCache["itemType"]) {
            return ProjectLookupUtilities.referenceCache["itemType"];
        }
        await project.ensureInfoSetGenerated();
        let simpleRefs = [];
        const refs = LookupUtilities_1.default.getReferencesFromAnnotatedValues(project.infoSet.contentIndex.getAll([ContentIndex_1.AnnotationCategory.blockTypeSource]), ContentIndex_1.AnnotationCategory.itemTypeSource, "{0} item type from " + project.name);
        if (refs) {
            LookupUtilities_1.default.sortReferences(refs);
            simpleRefs = refs;
        }
        LookupUtilities_1.default.appendReferences(simpleRefs, await LookupUtilities_1.default.getLookup("itemType"));
        ProjectLookupUtilities.referenceCache["itemType"] = simpleRefs;
        return simpleRefs;
    }
    static async getSoundDefinitionReferences(project) {
        if (project.infoSet.contentIndex.iteration !== ProjectLookupUtilities.cacheIteration) {
            ProjectLookupUtilities.cacheIteration = project.infoSet.contentIndex.iteration;
            ProjectLookupUtilities.referenceCache = {};
        }
        if (ProjectLookupUtilities.referenceCache["soundDefinition"]) {
            return ProjectLookupUtilities.referenceCache["soundDefinition"];
        }
        await project.ensureInfoSetGenerated();
        let simpleRefs = [];
        const refs = LookupUtilities_1.default.getReferencesFromAnnotatedValues(project.infoSet.contentIndex.getAll([ContentIndex_1.AnnotationCategory.blockTypeSource]), ContentIndex_1.AnnotationCategory.blockTypeSource, "{0} sound from " + project.name);
        if (refs) {
            LookupUtilities_1.default.sortReferences(refs);
            simpleRefs = refs;
        }
        LookupUtilities_1.default.appendReferences(simpleRefs, await LookupUtilities_1.default.getLookup("soundDefinition"));
        ProjectLookupUtilities.referenceCache["soundDefinition"] = simpleRefs;
        return simpleRefs;
    }
    static async getTerrainTextureReferences(project) {
        if (project.infoSet.contentIndex.iteration !== ProjectLookupUtilities.cacheIteration) {
            ProjectLookupUtilities.cacheIteration = project.infoSet.contentIndex.iteration;
            ProjectLookupUtilities.referenceCache = {};
        }
        if (ProjectLookupUtilities.referenceCache["terrainTexture"]) {
            return ProjectLookupUtilities.referenceCache["terrainTexture"];
        }
        await project.ensureInfoSetGenerated();
        let simpleRefs = [];
        const refs = LookupUtilities_1.default.getReferencesFromAnnotatedValues(project.infoSet.contentIndex.getAll([ContentIndex_1.AnnotationCategory.terrainTextureSource]), ContentIndex_1.AnnotationCategory.terrainTextureSource, "{0} terrain texture from " + project.name);
        if (refs) {
            LookupUtilities_1.default.sortReferences(refs);
            simpleRefs = refs;
        }
        LookupUtilities_1.default.appendReferences(simpleRefs, await LookupUtilities_1.default.getLookup("terrainTexture"));
        ProjectLookupUtilities.referenceCache["terrainTexture"] = simpleRefs;
        return simpleRefs;
    }
    static async getItemTextureReferences(project) {
        if (project.infoSet.contentIndex.iteration !== ProjectLookupUtilities.cacheIteration) {
            ProjectLookupUtilities.cacheIteration = project.infoSet.contentIndex.iteration;
            ProjectLookupUtilities.referenceCache = {};
        }
        if (ProjectLookupUtilities.referenceCache["itemTexture"]) {
            return ProjectLookupUtilities.referenceCache["itemTexture"];
        }
        await project.ensureInfoSetGenerated();
        let simpleRefs = [];
        const refs = LookupUtilities_1.default.getReferencesFromAnnotatedValues(project.infoSet.contentIndex.getAll([ContentIndex_1.AnnotationCategory.itemTextureSource]), ContentIndex_1.AnnotationCategory.itemTextureSource, "{0} item texture from " + project.name);
        if (refs) {
            LookupUtilities_1.default.sortReferences(refs);
            simpleRefs = refs;
        }
        LookupUtilities_1.default.appendReferences(simpleRefs, await LookupUtilities_1.default.getLookup("itemTexture"));
        ProjectLookupUtilities.referenceCache["itemTexture"] = simpleRefs;
        return simpleRefs;
    }
}
exports.default = ProjectLookupUtilities;

//# sourceMappingURL=../maps/app/ProjectLookupUtilities.js.map
