Editor/Tools/WorkflowTools.MacrosAndPrefabs.cs

Editor MCP assistant tool methods. Exposes CLI-style tools for recording/playing action macros, managing game mode state via reflection, spawning prefabs or procedural hazards, and running UI layout tests by delegating to MacrosAndPrefabsDriver and serializing results.

ReflectionFile Access
#nullable enable
using System;
using System.ComponentModel;

namespace Editor.Mcp
{
	public static partial class SboxMcpAssistant
	{
		/// <summary>
		/// Records, manages, and deterministically executes timed action macros and combat combos
		/// (e.g. punch combos, grab-and-throw, dodge-punish), with support for replay export and regression testing.
		/// </summary>
		[McpTool( "pocketknife_action_macro" )]
		public static string ActionMacro(
			[Description( "Action: 'list', 'play', 'save', 'get'" )] string action = "list",
			[Description( "Macro name or preset identifier (e.g. 'brawler_light_combo', 'brawler_grab_and_throw')" )] string? name = null,
			[Description( "Macro JSON definition string (for save)" )] string? macroJson = null,
			[Description( "Built-in preset to play" )] string? preset = null,
			[Description( "Number of physics simulation ticks to step (default 30)" )] int stepTicks = 30 )
		{
			try
			{
				var result = MacrosAndPrefabsDriver.ManageActionMacro(
					action,
					name,
					macroJson,
					preset,
					stepTicks
				);
				return McpJson.Write( result );
			}
			catch ( Exception ex )
			{
				return McpJson.Write( ToolOutcome<object>.Failure( null, ToolStatus.Failed, "macro.manage_failed", "Action macro operation failed.", ex ) );
			}
		}

		/// <summary>
		/// Universally inspects and manipulates game mode and round state machines across ANY s&amp;box project:
		/// discovers game state managers, inspects round timers and scores, and invokes transition methods
		/// (e.g. StartRound, TriggerSuddenDeath, RestartMatch).
		/// </summary>
		[McpTool( "pocketknife_gamemode_manage" )]
		public static string GameModeManage(
			[Description( "Action: 'discover', 'invoke_method'" )] string action = "discover",
			[Description( "Target game manager component type name (optional)" )] string? componentName = null,
			[Description( "Property name to inspect or override" )] string? propertyName = null,
			[Description( "Property value to assign" )] string? propertyValue = null,
			[Description( "Method name to invoke (e.g. 'StartRound', 'RestartMatch')" )] string? methodName = null )
		{
			try
			{
				var result = MacrosAndPrefabsDriver.ManageGameMode(
					action,
					componentName,
					propertyName,
					propertyValue,
					methodName
				);
				return McpJson.Write( result );
			}
			catch ( Exception ex )
			{
				return McpJson.Write( ToolOutcome<object>.Failure( null, ToolStatus.Failed, "gamemode.manage_failed", "Game mode management failed.", ex ) );
			}
		}

		/// <summary>
		/// Dynamically spawns project prefabs or procedural physics hazards (spinning beams, spring pads,
		/// explosive barrels) at specified coordinates to test map interactions and player collisions.
		/// </summary>
		[McpTool( "pocketknife_prefab_spawner" )]
		public static string PrefabSpawner(
			[Description( "Spawn type: 'prefab' or 'procedural'" )] string type = "procedural",
			[Description( "Path to .prefab file (for prefab mode)" )] string? prefabPath = null,
			[Description( "Procedural hazard: 'spinning_beam', 'spring_pad', 'explosive_barrel'" )] string proceduralHazard = "spinning_beam",
			[Description( "Spawn world position X" )] float posX = 0f,
			[Description( "Spawn world position Y" )] float posY = 0f,
			[Description( "Spawn world position Z (default 100)" )] float posZ = 100f,
			[Description( "Scale multiplier (default 1.0)" )] float scale = 1.0f )
		{
			try
			{
				var result = MacrosAndPrefabsDriver.SpawnPrefabOrHazard(
					type,
					prefabPath,
					proceduralHazard,
					posX, posY, posZ,
					scale
				);
				return McpJson.Write( result );
			}
			catch ( Exception ex )
			{
				return McpJson.Write( ToolOutcome<object>.Failure( null, ToolStatus.Failed, "spawner.failed", "Prefab/hazard spawning failed.", ex ) );
			}
		}

		/// <summary>
		/// Validates Razor UI panels across standard display resolution profiles: 16:9 Desktop (1080p),
		/// 16:10 Steam Deck (1280x800), 21:9 Ultrawide, and 4:3 Tablet to detect clipping, overlap, and CSS breakages.
		/// </summary>
		[McpTool( "pocketknife_ui_matrix_test" )]
		public static string UiMatrixTest()
		{
			try
			{
				var result = MacrosAndPrefabsDriver.TestUiMatrix();
				return McpJson.Write( result );
			}
			catch ( Exception ex )
			{
				return McpJson.Write( ToolOutcome<object>.Failure( null, ToolStatus.Failed, "ui_matrix.failed", "UI layout matrix test failed.", ex ) );
			}
		}
	}
}