"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const EntityTypeDefinition_1 = require("../minecraft/EntityTypeDefinition");
const EntityTypeResourceDefinition_1 = require("../minecraft/EntityTypeResourceDefinition");
const IProjectItemData_1 = require("./IProjectItemData");
class ProjectItemRelations {
    static async calculate(project) {
        const items = project.getItemsCopy();
        // clear all existing relations
        for (const item of items) {
            item.childItems = undefined;
            item.parentItems = undefined;
        }
        for (const item of items) {
            if (item.itemType === IProjectItemData_1.ProjectItemType.entityTypeBehavior) {
                await item.ensureStorage();
                if (item.file) {
                    const entityTypeBehavior = await EntityTypeDefinition_1.default.ensureOnFile(item.file);
                    if (entityTypeBehavior) {
                        entityTypeBehavior.addChildItems(project, item);
                    }
                }
            }
            else if (item.itemType === IProjectItemData_1.ProjectItemType.entityTypeResource) {
                await item.ensureStorage();
                if (item.file) {
                    const entityTypeResource = await EntityTypeResourceDefinition_1.default.ensureOnFile(item.file);
                    if (entityTypeResource) {
                        entityTypeResource.addChildItems(project, item);
                    }
                }
            }
        }
    }
}
exports.default = ProjectItemRelations;

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