Update compatibility to Gamecraft v2019.10.23.16.11

This commit is contained in:
NGnius 2019-10-24 11:09:37 -04:00
parent 9071fccf76
commit a9957f922c
12 changed files with 90 additions and 42 deletions

View file

@ -12,9 +12,7 @@ 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")]
[CustomCommand]
class ChainCommandEngine : CustomCommandEngine
{
public ChainCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
@ -23,9 +21,9 @@ namespace ExtraCommands.Basics
public override void Ready()
{
uREPL.RuntimeCommands.Register<string, string>("Chain", ChainCommand, "Run two commands, one after the other");
uREPL.RuntimeCommands.Register<string, string>("ChainNoFail", ChainNoFailCommand, "Run two commands, one after the other even if the first one is invalid");
uREPL.RuntimeCommands.Register<string, string>("ChainQuiet", ChainQuietCommand, "Run two commands, one after the other quietly");
CustomCommandUtility.Register<string, string>("Chain", ChainCommand, "Run two commands, one after the other");
CustomCommandUtility.Register<string, string>("ChainNoFail", ChainNoFailCommand, "Run two commands, one after the other even if the first one is invalid");
CustomCommandUtility.Register<string, string>("ChainQuiet", ChainQuietCommand, "Run two commands, one after the other quietly");
}
private void ChainCommand(string command1, string command2)
@ -90,9 +88,9 @@ namespace ExtraCommands.Basics
public override void Dispose()
{
uREPL.RuntimeCommands.Unregister("Chain");
uREPL.RuntimeCommands.Unregister("ChainNoFail");
uREPL.RuntimeCommands.Unregister("ChainQuiet");
CustomCommandUtility.Unregister("Chain");
CustomCommandUtility.Unregister("ChainNoFail");
CustomCommandUtility.Unregister("ChainQuiet");
}
}
}

View file

@ -16,7 +16,6 @@ namespace ExtraCommands
{
static void Postfix(UnityContext<FullGameCompositionRoot> contextHolder, EnginesRoot enginesRoot, World physicsWorld, Action reloadGame, MultiplayerInitParameters multiplayerParameters)
{
int commandCount = 0;
int engineCount = 0;
MethodInfo commandHelp = Harmony.AccessTools.Method(Harmony.AccessTools.TypeByName("RobocraftX.GUI.CommandLine.CommandLineUtility"), "SaveCommandHelp", new Type[] { typeof(string), typeof(string) });
foreach (Type t in typeof(CustomCommandEngine).Assembly.GetTypes())
@ -36,22 +35,19 @@ namespace ExtraCommands
enginesRoot.AddEngine(inst);
engineCount++;
}
// add to Gamecraft help command
commandHelp.Invoke(null, new string[] { attr.Name, attr.Description });
commandCount++;
}
}
}
enginesRoot.AddEngine(new UnregisterCommandEngine(contextHolder, enginesRoot, physicsWorld, reloadGame, multiplayerParameters));
Debug.Log($"Added {commandCount} custom commands in {engineCount} engines");
// enginesRoot.AddEngine(new UnregisterCommandEngine(contextHolder, enginesRoot, physicsWorld, reloadGame, multiplayerParameters));
Debug.Log($"Added {engineCount} custom command engines");
}
static MethodBase TargetMethod(HarmonyInstance instance)
{
return _ComposeMethodInfo(CommandLineCompositionRoot.Compose<CommandLineContext>);
return _ComposeMethodInfo(CommandLineCompositionRoot.Compose<UnityContext<FullGameCompositionRoot>>);
}
private static MethodInfo _ComposeMethodInfo(Action<CommandLineContext, EnginesRoot, World, Action, MultiplayerInitParameters> a)
private static MethodInfo _ComposeMethodInfo(Action<UnityContext<FullGameCompositionRoot>, EnginesRoot, World, Action, MultiplayerInitParameters> a)
{
return a.Method;
}

View file

@ -7,11 +7,9 @@ namespace ExtraCommands
{
public string Name { get; protected set; }
public string Description { get; protected set; }
public CustomCommandAttribute(string name, string description = "")
public CustomCommandAttribute(string name = "")
{
this.Name = name;
this.Description = description;
}
}
}

View file

@ -33,7 +33,7 @@ namespace ExtraCommands
virtual public void Dispose() { }
// NOTE: Ready() should call uREPL.RuntimeCommands.Register to add the command to the command line
// NOTE: Ready() should call CustomCommandUtility.Register to add the command to the command line
virtual public void Ready() { }
}
}

View file

@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using uREPL;
using RobocraftX.CommandLine.Custom;
namespace ExtraCommands
{
static class CustomCommandUtility
{
public static void Register(string name, Action action, string desc)
{
RuntimeCommands.Register(name, action, desc);
ConsoleCommands.Register(name, action, desc);
}
public static void Register(string name, Action<object> action, string desc)
{
RuntimeCommands.Register<object>(name, action, desc);
}
public static void Register<Param0>(string name, Action<Param0> action, string desc)
{
RuntimeCommands.Register<Param0>(name, action, desc);
ConsoleCommands.Register<Param0>(name, action, desc);
}
public static void Register<Param0, Param1>(string name, Action<Param0, Param1> action, string desc)
{
RuntimeCommands.Register<Param0, Param1>(name, action, desc);
ConsoleCommands.Register<Param0, Param1>(name, action, desc);
}
public static void Register(string name, Action<object, object, object> action, string desc)
{
RuntimeCommands.Register<object, object, object>(name, action, desc);
ConsoleCommands.Register<object, object, object>(name, action, desc);
}
public static void Register<Param0, Param1, Param2>(string name, Action<Param0, Param1, Param2> action, string desc)
{
RuntimeCommands.Register<Param0, Param1, Param2>(name, action, desc);
ConsoleCommands.Register<Param0, Param1, Param2>(name, action, desc);
}
public static void Unregister(string name)
{
RuntimeCommands.Unregister(name);
ConsoleCommands.Unregister(name);
}
}
}

View file

@ -12,7 +12,7 @@ using RobocraftX;
namespace ExtraCommands.Basics
{
[CustomCommand("Exit", "Forcefully close Gamecraft")]
[CustomCommand("Exit")]
class ExitCommandEngine : CustomCommandEngine
{
public ExitCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
@ -21,7 +21,7 @@ namespace ExtraCommands.Basics
public override void Ready()
{
uREPL.RuntimeCommands.Register("Exit", ExitCommand, "Forcefully close Gamecraft");
CustomCommandUtility.Register("Exit", ExitCommand, "Forcefully close Gamecraft");
}
private void ExitCommand()
@ -31,7 +31,7 @@ namespace ExtraCommands.Basics
public override void Dispose()
{
uREPL.RuntimeCommands.Unregister("Exit");
CustomCommandUtility.Unregister("Exit");
}
}
}

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net45</TargetFramework>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
@ -12,6 +12,9 @@
<Reference Include="CommandLine">
<HintPath>..\ref\CommandLine.dll</HintPath>
</Reference>
<Reference Include="Facepunch.Steamworks.Win64">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Gamecraft\Gamecraft_Data\Managed\Facepunch.Steamworks.Win64.dll</HintPath>
</Reference>
<Reference Include="FullGame">
<HintPath>..\ref\FullGame.dll</HintPath>
</Reference>

View file

@ -23,7 +23,7 @@ namespace ExtraCommands.Building
public override void Ready()
{
uREPL.RuntimeCommands.Register<float, float, float>("MoveBlocks", MoveBlocksCommand, "Move blocks from their original position");
CustomCommandUtility.Register<float, float, float>("MoveBlocks", MoveBlocksCommand, "Move blocks from their original position");
}
private void MoveBlocksCommand(float x, float y, float z)
@ -45,7 +45,7 @@ namespace ExtraCommands.Building
public override void Dispose()
{
uREPL.RuntimeCommands.Unregister("MoveBlocks");
CustomCommandUtility.Unregister("MoveBlocks");
}
}
}

View file

@ -12,7 +12,7 @@ using RobocraftX;
namespace ExtraCommands.Basics
{
[CustomCommand("SetFieldOfView", "Set the camera's field of view")]
[CustomCommand("SetFieldOfView")]
class SetFOVCommandEngine : CustomCommandEngine
{
public SetFOVCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
@ -21,7 +21,7 @@ namespace ExtraCommands.Basics
public override void Ready()
{
uREPL.RuntimeCommands.Register<float>("SetFieldOfView", SetFieldOfViewCommand, "Set the camera's field of view");
CustomCommandUtility.Register<float>("SetFieldOfView", SetFieldOfViewCommand, "Set the camera's field of view");
}
private void SetFieldOfViewCommand(float newFoV)
@ -31,7 +31,7 @@ namespace ExtraCommands.Basics
public override void Dispose()
{
uREPL.RuntimeCommands.Unregister("SetFieldOfView");
CustomCommandUtility.Unregister("SetFieldOfView");
}
}
}

View file

@ -12,7 +12,7 @@ using RobocraftX;
namespace ExtraCommands.Basics
{
[CustomCommand("SetTargetFPS", "Set Gamecraft's target FPS")]
[CustomCommand("SetTargetFPS")]
class SetTargetFramerateCommandEngine : CustomCommandEngine
{
public SetTargetFramerateCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
@ -21,7 +21,7 @@ namespace ExtraCommands.Basics
public override void Ready()
{
uREPL.RuntimeCommands.Register<int>("SetTargetFPS", SetFramerateCommand, "Set Gamecraft's target FPS");
CustomCommandUtility.Register<int>("SetTargetFPS", SetFramerateCommand, "Set Gamecraft's target FPS");
}
private void SetFramerateCommand(int newFoV)
@ -31,7 +31,7 @@ namespace ExtraCommands.Basics
public override void Dispose()
{
uREPL.RuntimeCommands.Unregister("SetTargetFPS");
CustomCommandUtility.Unregister("SetTargetFPS");
}
}
}

View file

@ -12,8 +12,7 @@ using RobocraftX;
namespace ExtraCommands.Waypoints
{
[CustomCommand("CreateWaypoint", "Create a waypoint in your current location")]
[CustomCommand("TeleportPlayerWaypoint", "Teleport to a waypoint")]
[CustomCommand]
class TeleportWaypointCommandEngine : CustomCommandEngine
{
private Dictionary<object, float[]> _waypoints = new Dictionary<object, float[]>();
@ -23,8 +22,8 @@ namespace ExtraCommands.Waypoints
public override void Ready()
{
uREPL.RuntimeCommands.Register<object>("CreateWaypoint", CreateWaypointCommand, "Create a waypoint in your current location");
uREPL.RuntimeCommands.Register<object>("TeleportPlayerWaypoint", TeleportToWaypointCommand, "Teleport to a waypoint");
CustomCommandUtility.Register<object>("CreateWaypoint", CreateWaypointCommand, "Create a waypoint in your current location");
CustomCommandUtility.Register<object>("TeleportPlayerWaypoint", TeleportToWaypointCommand, "Teleport to a waypoint");
}
private void CreateWaypointCommand(object name)
@ -47,8 +46,8 @@ namespace ExtraCommands.Waypoints
public override void Dispose()
{
uREPL.RuntimeCommands.Unregister("CreateWaypoint");
uREPL.RuntimeCommands.Unregister("TeleportPlayerWaypoint");
CustomCommandUtility.Unregister("CreateWaypoint");
CustomCommandUtility.Unregister("TeleportPlayerWaypoint");
}
}
}

View file

@ -12,7 +12,7 @@ using RobocraftX;
namespace ExtraCommands.Basics
{
[CustomCommand("Wait", "Delay execution for a length of time (ms)")]
[CustomCommand("Wait")]
class WaitCommandEngine : CustomCommandEngine
{
public WaitCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
@ -21,7 +21,7 @@ namespace ExtraCommands.Basics
public override void Ready()
{
uREPL.RuntimeCommands.Register<int>("Wait", WaitCommand, "Delay execution for a length of time (ms)");
CustomCommandUtility.Register<int>("Wait", WaitCommand, "Delay execution for a length of time (ms)");
}
private void WaitCommand(int ms)
@ -31,7 +31,7 @@ namespace ExtraCommands.Basics
public override void Dispose()
{
uREPL.RuntimeCommands.Unregister("Wait");
CustomCommandUtility.Unregister("Wait");
}
}
}