Create untested basic commands
This commit is contained in:
parent
3f0da89d01
commit
f19dc46010
8 changed files with 265 additions and 4 deletions
69
extracommands/ChainCommandEngine.cs
Normal file
69
extracommands/ChainCommandEngine.cs
Normal file
|
@ -0,0 +1,69 @@
|
|||
using System;
|
||||
using RobocraftX.GUI.CommandLine;
|
||||
using RobocraftX.Multiplayer;
|
||||
using RobocraftX.StateSync;
|
||||
using RobocraftX.Character;
|
||||
using Svelto.ECS;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
using uREPL;
|
||||
using Svelto.Context;
|
||||
using RobocraftX;
|
||||
|
||||
namespace ExtraCommands.Basics
|
||||
{
|
||||
[CustomCommand("Chain", "Run two commands, one after the other")]
|
||||
[CustomCommand("ChainNoFail", "Run two commands, one after the other even if the first one is invalid")]
|
||||
[CustomCommand("ChainQuiet", "Run two commands, one after the other quietly")]
|
||||
class ChainCommandEngine : CustomCommandEngine
|
||||
{
|
||||
public ChainCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Ready()
|
||||
{
|
||||
uREPL.RuntimeCommands.Register<string, string>("Chain", ChainCommand, "Run two commands, one after the other");
|
||||
uREPL.RuntimeCommands.Register<string, string>("ChainNoFail", ChainCommand, "Run two commands, one after the other even if the first one is invalid");
|
||||
uREPL.RuntimeCommands.Register<string, string>("ChainQuiet", ChainCommand, "Run two commands, one after the other quietly");
|
||||
}
|
||||
|
||||
private void ChainCommand(string command1, string command2)
|
||||
{
|
||||
bool success1 = uREPL.RuntimeCommands.ConvertIntoCodeIfCommand(command1);
|
||||
if (!success1) {
|
||||
uREPL.Log.Error("First command was not executed successfully");
|
||||
return;
|
||||
}
|
||||
bool success2 = uREPL.RuntimeCommands.ConvertIntoCodeIfCommand(command2);
|
||||
if (!success2) {
|
||||
uREPL.Log.Error("Second command was not executed successfully");
|
||||
}
|
||||
}
|
||||
|
||||
private void ChainNoFailCommand(string command1, string command2)
|
||||
{
|
||||
bool success1 = uREPL.RuntimeCommands.ConvertIntoCodeIfCommand(command1);
|
||||
if (!success1) {
|
||||
uREPL.Log.Error("First command was not executed successfully");
|
||||
}
|
||||
bool success2 = uREPL.RuntimeCommands.ConvertIntoCodeIfCommand(command2);
|
||||
if (!success2) {
|
||||
uREPL.Log.Error("Second command was not executed successfully");
|
||||
}
|
||||
}
|
||||
|
||||
private void ChainQuietCommand(string command1, string command2)
|
||||
{
|
||||
uREPL.RuntimeCommands.ConvertIntoCodeIfCommand(command1);
|
||||
uREPL.RuntimeCommands.ConvertIntoCodeIfCommand(command2);
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
uREPL.RuntimeCommands.Unregister("Chain");
|
||||
uREPL.RuntimeCommands.Unregister("ChainNoFail");
|
||||
uREPL.RuntimeCommands.Unregister("ChainQuiet");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@ using Svelto.Context;
|
|||
namespace ExtraCommands
|
||||
{
|
||||
[HarmonyPatch]
|
||||
class CommandLineCompositionRootPatch
|
||||
class CommandLineCompositionRootSaveCommandPatch
|
||||
{
|
||||
static void Postfix(UnityContext<FullGameCompositionRoot> contextHolder, EnginesRoot enginesRoot, World physicsWorld, Action reloadGame, MultiplayerInitParameters multiplayerParameters)
|
||||
{
|
||||
|
@ -38,7 +38,6 @@ namespace ExtraCommands
|
|||
}
|
||||
}
|
||||
}
|
||||
Debug.Log("Postfix");
|
||||
}
|
||||
|
||||
[HarmonyTargetMethod]
|
|
@ -0,0 +1,45 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using Harmony;
|
||||
using UnityEngine;
|
||||
using Unity.Entities;
|
||||
using RobocraftX;
|
||||
using RobocraftX.GUI.CommandLine;
|
||||
using RobocraftX.Multiplayer;
|
||||
using Svelto.ECS;
|
||||
using Svelto.Context;
|
||||
|
||||
namespace ExtraCommands
|
||||
{
|
||||
[HarmonyPatch]
|
||||
class CommandLineCompositionRootUnregisterCommandPatch
|
||||
{
|
||||
static void Prefix()
|
||||
{
|
||||
MethodInfo commandRemoveHelp = Harmony.AccessTools.Method(Harmony.AccessTools.TypeByName("RobocraftX.GUI.CommandLine.CommandLineUtility"), "SaveCommandHelp", new Type[] { typeof(string) });
|
||||
foreach (Type t in typeof(CustomCommandEngine).Assembly.GetTypes())
|
||||
{
|
||||
CustomCommandAttribute[] attributes = (CustomCommandAttribute[])t.GetCustomAttributes(typeof(CustomCommandAttribute), false);
|
||||
foreach (CustomCommandAttribute attr in attributes)
|
||||
{
|
||||
if (attr != null && t.IsSubclassOf(typeof(CustomCommandEngine)))
|
||||
{
|
||||
// remove Gamecraft help command
|
||||
commandRemoveHelp.Invoke(null, new string[] { attr.Name });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyTargetMethod]
|
||||
static MethodBase HTargetMethod(HarmonyInstance instance)
|
||||
{
|
||||
return _OnContextDestroyedMethodInfo((new CommandLineCompositionRoot()).OnContextDestroyed);
|
||||
}
|
||||
|
||||
private static MethodInfo _OnContextDestroyedMethodInfo(Action a)
|
||||
{
|
||||
return a.Method;
|
||||
}
|
||||
}
|
||||
}
|
37
extracommands/ExitCommandEngine.cs
Normal file
37
extracommands/ExitCommandEngine.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using RobocraftX.GUI.CommandLine;
|
||||
using RobocraftX.Multiplayer;
|
||||
using RobocraftX.StateSync;
|
||||
using RobocraftX.Character;
|
||||
using Svelto.ECS;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
using uREPL;
|
||||
using Svelto.Context;
|
||||
using RobocraftX;
|
||||
|
||||
namespace ExtraCommands.Basics
|
||||
{
|
||||
[CustomCommand("Exit", "Forcefully close Gamecraft")]
|
||||
class ExitCommandEngine : CustomCommandEngine
|
||||
{
|
||||
public ExitCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Ready()
|
||||
{
|
||||
uREPL.RuntimeCommands.Register("Exit", ExitCommand, "Forcefully close Gamecraft");
|
||||
}
|
||||
|
||||
private void ExitCommand()
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
uREPL.RuntimeCommands.Unregister("Exit");
|
||||
}
|
||||
}
|
||||
}
|
37
extracommands/SetFOVCommandEngine.cs
Normal file
37
extracommands/SetFOVCommandEngine.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using RobocraftX.GUI.CommandLine;
|
||||
using RobocraftX.Multiplayer;
|
||||
using RobocraftX.StateSync;
|
||||
using RobocraftX.Character;
|
||||
using Svelto.ECS;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
using uREPL;
|
||||
using Svelto.Context;
|
||||
using RobocraftX;
|
||||
|
||||
namespace ExtraCommands.Basics
|
||||
{
|
||||
[CustomCommand("SetFieldOfView", "Set the camera's field of view")]
|
||||
class SetFOVCommandEngine : CustomCommandEngine
|
||||
{
|
||||
public SetFOVCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Ready()
|
||||
{
|
||||
uREPL.RuntimeCommands.Register<float>("SetFieldOfView", SetFieldOfViewCommand, "Set the camera's field of view");
|
||||
}
|
||||
|
||||
private void SetFieldOfViewCommand(float newFoV)
|
||||
{
|
||||
Camera.main.fieldOfView = newFoV;
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
uREPL.RuntimeCommands.Unregister("SetFieldOfView");
|
||||
}
|
||||
}
|
||||
}
|
37
extracommands/SetTargetFramerateCommandEngine.cs
Normal file
37
extracommands/SetTargetFramerateCommandEngine.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using RobocraftX.GUI.CommandLine;
|
||||
using RobocraftX.Multiplayer;
|
||||
using RobocraftX.StateSync;
|
||||
using RobocraftX.Character;
|
||||
using Svelto.ECS;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
using uREPL;
|
||||
using Svelto.Context;
|
||||
using RobocraftX;
|
||||
|
||||
namespace ExtraCommands.Basics
|
||||
{
|
||||
[CustomCommand("SetTargetFPS", "Set Gamecraft's target FPS")]
|
||||
class SetTargetFramerateCommandEngine : CustomCommandEngine
|
||||
{
|
||||
public SetFOVCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Ready()
|
||||
{
|
||||
uREPL.RuntimeCommands.Register<float>("SetTargetFPS", SetFramerateCommand, "Set Gamecraft's target FPS");
|
||||
}
|
||||
|
||||
private void SetFramerateCommand(int newFoV)
|
||||
{
|
||||
Application.targetFrameRate = newFoV;
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
uREPL.RuntimeCommands.Unregister("SetTargetFPS");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,8 +23,8 @@ namespace ExtraCommands.Waypoints
|
|||
|
||||
public override void Ready()
|
||||
{
|
||||
uREPL.RuntimeCommands.Register<object>("CreateWaypoint", CreateWaypointCommand);
|
||||
uREPL.RuntimeCommands.Register<object>("TeleportPlayerWaypoint", TeleportToWaypointCommand);
|
||||
uREPL.RuntimeCommands.Register<object>("CreateWaypoint", CreateWaypointCommand, "Create a waypoint in your current location");
|
||||
uREPL.RuntimeCommands.Register<object>("TeleportPlayerWaypoint", TeleportToWaypointCommand, "Teleport to a waypoint");
|
||||
}
|
||||
|
||||
private void CreateWaypointCommand(object name)
|
37
extracommands/WaitCommandEngine.cs
Normal file
37
extracommands/WaitCommandEngine.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using RobocraftX.GUI.CommandLine;
|
||||
using RobocraftX.Multiplayer;
|
||||
using RobocraftX.StateSync;
|
||||
using RobocraftX.Character;
|
||||
using Svelto.ECS;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
using uREPL;
|
||||
using Svelto.Context;
|
||||
using RobocraftX;
|
||||
|
||||
namespace ExtraCommands.Basics
|
||||
{
|
||||
[CustomCommand("Wait", "Delay execution for a length of time (ms)")]
|
||||
class WaitCommandEngine : CustomCommandEngine
|
||||
{
|
||||
public WaitCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Ready()
|
||||
{
|
||||
uREPL.RuntimeCommands.Register<int>("Wait", WaitCommand, "Delay execution for a length of time (ms)");
|
||||
}
|
||||
|
||||
private void WaitCommand(int ms)
|
||||
{
|
||||
System.Threading.Thread.Sleep(ms);
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
uREPL.RuntimeCommands.Unregister("Wait");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue