"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
const ITool_1 = require("./ITool");
const IProjectItemData_1 = require("./IProjectItemData");
const CommandRunner_1 = require("./CommandRunner");
class ProjectTools {
    static async addGlobalTools(tools) {
        tools.push({
            title: "Reload",
            type: ITool_1.ToolType.reload,
            scope: ITool_1.ToolScope.global,
        });
        tools.push({
            title: "Hello World",
            type: ITool_1.ToolType.say,
            parameter1: "Hello from Minecraft Creator Tools.",
            scope: ITool_1.ToolScope.global,
        });
    }
    static generateTools(carto, project) {
        const tools = [];
        ProjectTools.addGlobalTools(tools);
        for (let i = 0; i < 10; i++) {
            const ctool = carto.getCustomTool(i);
            if (ctool.text && ctool.text.length > 3) {
                let title = ctool.name;
                if (!title || title.length < 1) {
                    title = "Tool " + (i + 1).toString();
                }
                tools.push({
                    title: title,
                    type: ITool_1.ToolType.customTool,
                    scope: ITool_1.ToolScope.global,
                    parameter1: i.toString(),
                });
            }
        }
        if (project) {
            for (let i = 0; i < project.items.length; i++) {
                const pi = project.items[i];
                if (pi.itemType === IProjectItemData_1.ProjectItemType.structure && pi.projectPath !== null) {
                    let structureName = pi.name;
                    structureName = structureName.replace(".mcstructure", "");
                    const tool = {
                        title: "Push " + structureName + " to Minecraft",
                        type: ITool_1.ToolType.pushStructure,
                        scope: ITool_1.ToolScope.project,
                        parameter1: pi.projectPath,
                    };
                    tools.push(tool);
                }
            }
        }
        return tools;
    }
    static async executeTool(tool, carto, project) {
        switch (tool.type) {
            case ITool_1.ToolType.customTool:
                if (tool.parameter1) {
                    CommandRunner_1.default.runCustomTool(carto, parseInt(tool.parameter1) + 1);
                }
                break;
            case ITool_1.ToolType.reload:
                ProjectTools.reload(carto);
                break;
            case ITool_1.ToolType.say:
                if (tool.parameter1 && tool.parameter1.length > 0) {
                    ProjectTools.say(carto, tool.parameter1);
                }
                break;
        }
    }
    static async reload(carto) {
        await carto.runMinecraftCommand("reload");
    }
    static async say(carto, message) {
        await carto.runMinecraftCommand("say " + message);
    }
}
exports.default = ProjectTools;

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