UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

77 lines (76 loc) 3.32 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. Object.defineProperty(exports, "__esModule", { value: true }); exports.switchModeCommand = exports.SwitchModeCommand = void 0; const IToolCommand_1 = require("../IToolCommand"); const ICreatorToolsData_1 = require("../../ICreatorToolsData"); const MODE_CHOICES = ["focused", "full", "raw"]; const MODE_TO_PREFERENCE = { focused: ICreatorToolsData_1.CreatorToolsEditPreference.summarized, full: ICreatorToolsData_1.CreatorToolsEditPreference.editors, raw: ICreatorToolsData_1.CreatorToolsEditPreference.raw, }; const MODE_DESCRIPTIONS = { focused: "Focused mode — simplified, summary-first editing surface.", full: "Full mode — complete file access with visual form-based editors.", raw: "Raw mode — direct JSON / text editing of every file in the project.", }; class SwitchModeCommand extends IToolCommand_1.ToolCommandBase { metadata = { name: "mode", description: "Switch the editor mode (focused | full | raw)", aliases: ["setmode"], category: "General", arguments: [ { name: "mode", description: "Edit-preference mode to switch to", type: "choice", required: true, choices: [...MODE_CHOICES], }, ], isWriteCommand: false, examples: ["/mode focused", "/mode full", "/mode raw", "/setmode raw"], }; async execute(context, args, _flags) { const validationError = this.validateRequiredArgs(args); if (validationError) return validationError; if (!context.creatorTools) { context.output.error("No CreatorTools instance available — cannot change edit preference."); return this.error("NO_CREATOR_TOOLS", "No CreatorTools instance available."); } const requested = (args[0] || "").toLowerCase(); if (!MODE_CHOICES.includes(requested)) { const message = `Unknown mode '${args[0]}'. Choose one of: ${MODE_CHOICES.join(", ")}.`; context.output.error(message); return this.error("INVALID_MODE", message); } const preference = MODE_TO_PREFERENCE[requested]; try { context.creatorTools.editPreference = preference; await context.creatorTools.save(); context.output.success(`Edit mode set to '${requested}'.`); context.output.info(MODE_DESCRIPTIONS[requested]); return this.success(`Edit mode set to '${requested}'`, { mode: requested, preference, }); } catch (error) { const message = error instanceof Error ? error.message : String(error); context.output.error(`Failed to switch mode: ${message}`); return this.error("MODE_SWITCH_ERROR", `Failed to switch mode: ${message}`); } } async getCompletions(_context, _args, partialArg, argIndex) { if (argIndex !== 0) return []; const lower = partialArg.toLowerCase(); return MODE_CHOICES.filter((m) => m.startsWith(lower)); } } exports.SwitchModeCommand = SwitchModeCommand; exports.switchModeCommand = new SwitchModeCommand();