Skip to content

Commit

Permalink
Add command /dev
Browse files Browse the repository at this point in the history
  • Loading branch information
starfi5h committed Apr 5, 2024
1 parent 1b5ef60 commit 8942c9b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions NebulaWorld/Chat/ChatCommandRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static ChatCommandRegistry()
RegisterCommand("reconnect", new ReconnectCommandHandler(), "r");
RegisterCommand("server", new ServerCommandHandler());
RegisterCommand("playerdata", new PlayerDataCommandHandler());
RegisterCommand("dev", new DevCommandHandler());
}

private static void RegisterCommand(string commandName, IChatCommandHandler commandHandlerHandler, params string[] aliases)
Expand Down
57 changes: 57 additions & 0 deletions NebulaWorld/Chat/Commands/DevCommandHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#region

using NebulaWorld.MonoBehaviours.Local.Chat;
using NebulaModel.DataStructures.Chat;
using HarmonyLib;

#endregion

namespace NebulaWorld.Chat.Commands;

public class DevCommandHandler : IChatCommandHandler
{
public void Execute(ChatWindow window, string[] parameters)
{
if (parameters.Length < 1)
{
throw new ChatCommandUsageException("Not enough arguments!".Translate());
}

switch (parameters[0])
{
case "sandbox":
{
GameMain.sandboxToolsEnabled = !GameMain.sandboxToolsEnabled;
GameMain.data.gameDesc.isSandboxMode = GameMain.sandboxToolsEnabled;
window.SendLocalChatMessage("SandboxTool enable: " + GameMain.sandboxToolsEnabled, ChatMessageType.CommandOutputMessage);
return;
}
case "load-cfg":
{
window.SendLocalChatMessage("Overwrite settings from nebulaGameDescSettings.cfg", ChatMessageType.CommandOutputMessage);
AccessTools.Method(AccessTools.TypeByName("NebulaPatcher.NebulaPlugin"), "SetGameDescFromConfigFile").Invoke(null, [GameMain.data.gameDesc]);
return;
}

case "self-destruct":
{
GameMain.mainPlayer.Kill();
return;
}

default:
window.SendLocalChatMessage("Unknown command: " + parameters[0], ChatMessageType.CommandOutputMessage);
return;
}
}

public string GetDescription()
{
return "Developer/Sandbox tool commands".Translate();
}

public string[] GetUsage()
{
return ["sandbox", "load-cfg", "self-destruct"];
}
}

0 comments on commit 8942c9b

Please sign in to comment.