Ver código fonte

Create untested basic commands

tags/v0.0.2
NGnius (Graham) 4 anos atrás
pai
commit
f19dc46010
8 arquivos alterados com 265 adições e 4 exclusões
  1. +69
    -0
      extracommands/ChainCommandEngine.cs
  2. +1
    -2
      extracommands/CommandLineCompositionRootSaveCommandPatch.cs
  3. +45
    -0
      extracommands/CommandLineCompositionRootUnregisterCommandPatch.cs
  4. +37
    -0
      extracommands/ExitCommandEngine.cs
  5. +37
    -0
      extracommands/SetFOVCommandEngine.cs
  6. +37
    -0
      extracommands/SetTargetFramerateCommandEngine.cs
  7. +2
    -2
      extracommands/TeleportWaypointCommandEngine.cs
  8. +37
    -0
      extracommands/WaitCommandEngine.cs

+ 69
- 0
extracommands/ChainCommandEngine.cs Ver arquivo

@@ -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");
}
}
}

extracommands/CommandLineCompositionRootPatch.cs → extracommands/CommandLineCompositionRootSaveCommandPatch.cs Ver arquivo

@@ -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]

+ 45
- 0
extracommands/CommandLineCompositionRootUnregisterCommandPatch.cs Ver arquivo

@@ -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
- 0
extracommands/ExitCommandEngine.cs Ver arquivo

@@ -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
- 0
extracommands/SetFOVCommandEngine.cs Ver arquivo

@@ -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
- 0
extracommands/SetTargetFramerateCommandEngine.cs Ver arquivo

@@ -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");
}
}
}

extracommands/CreateWaypoint.cs → extracommands/TeleportWaypointCommandEngine.cs Ver arquivo

@@ -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
- 0
extracommands/WaitCommandEngine.cs Ver arquivo

@@ -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");
}
}
}

Carregando…
Cancelar
Salvar