From 019b88cdadd8309148f5029d9ad1fa5b37219d43 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Wed, 20 May 2020 20:27:20 -0400 Subject: [PATCH] Fix breaking changes for API v1.0 and GC v2020.05.14.16.20 --- extracommands/ChainCommandEngine.cs | 69 ------------------- extracommands/CustomCommandAttribute.cs | 2 +- extracommands/ExampleCommandEngine.cs | 20 ++---- extracommands/ExitCommandEngine.cs | 17 ++--- extracommands/ExtraCommands.csproj | 12 +--- extracommands/MoveBlocksCommandEngine.cs | 36 ++++------ extracommands/RotateBlocksCommandEngine.cs | 28 +++----- extracommands/RotatePlayerCommandEngine.cs | 23 +++---- extracommands/SetFOVCommandEngine.cs | 18 ++--- .../SetTargetFramerateCommandEngine.cs | 16 ++--- .../TeleportWaypointCommandEngine.cs | 27 +++----- extracommands/WaitCommandEngine.cs | 41 ----------- 12 files changed, 66 insertions(+), 243 deletions(-) delete mode 100644 extracommands/ChainCommandEngine.cs delete mode 100644 extracommands/WaitCommandEngine.cs diff --git a/extracommands/ChainCommandEngine.cs b/extracommands/ChainCommandEngine.cs deleted file mode 100644 index 7cac7ee..0000000 --- a/extracommands/ChainCommandEngine.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.Collections.Generic; -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 Svelto.Tasks; -using Svelto.Tasks.ExtraLean; -using RobocraftX; -using RobocraftX.Schedulers; - -using GamecraftModdingAPI.Commands; -using GamecraftModdingAPI.Tasks; -using GamecraftModdingAPI.Utility; - -namespace ExtraCommands.Basics -{ - //[CustomCommand("Chain")] - class ChainCommandEngine : ICustomCommandEngine - { - public string Description => "Run two commands one after the other"; - - public string Name => "Chain"; - - public IEntitiesDB entitiesDB { set; private get; } - - public void Ready() - { - CommandRegistrationHelper.Register(Name, ChainCommand, Description); - } - - private void ChainCommand(string command1, string command2) - { - string command1a = decomma(command1); - string command2a = decomma(command2); - ScheduleCommands(command1a, command2a).RunOn(Scheduler.extraLeanRunner); - } - - private IEnumerator ScheduleCommands(string c1, string c2) - { - yield return Yield.It; - bool success1 = uREPL.Evaluator.Evaluate(c1).type == CompileResult.Type.Success; - if (!success1) - { - Logging.CommandLogError("First command was not executed successfully"); - } - bool success2 = uREPL.Evaluator.Evaluate(c2).type == CompileResult.Type.Success; - if (!success2) - { - Logging.CommandLogError("Second command was not executed successfully"); - } - } - - private string decomma(string strIn) - { - return strIn.Replace(", ", " "); - } - - public void Dispose() - { - CommandRegistrationHelper.Unregister("Chain"); - } - } -} diff --git a/extracommands/CustomCommandAttribute.cs b/extracommands/CustomCommandAttribute.cs index 6e3ddb4..f2a3c10 100644 --- a/extracommands/CustomCommandAttribute.cs +++ b/extracommands/CustomCommandAttribute.cs @@ -4,7 +4,7 @@ using GamecraftModdingAPI.Commands; namespace ExtraCommands { - [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public class CustomCommandAttribute: Attribute { public readonly string Name; diff --git a/extracommands/ExampleCommandEngine.cs b/extracommands/ExampleCommandEngine.cs index dfb57aa..fff5745 100644 --- a/extracommands/ExampleCommandEngine.cs +++ b/extracommands/ExampleCommandEngine.cs @@ -1,14 +1,4 @@ -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; using GamecraftModdingAPI.Commands; @@ -25,15 +15,17 @@ using GamecraftModdingAPI.Commands; namespace ExtraCommands.Example { - // !!! Uncomment the line below this !!! - // [CustomCommand("Example")] - class ExampleCommandEngine : ICustomCommandEngine + // !!! Uncomment the line below this !!! + // [CustomCommand("Example")] + class ExampleCommandEngine : ICustomCommandEngine { public string Description => "This is an example command which does nothing!"; public string Name => "Example"; - public IEntitiesDB entitiesDB { set; private get; } + public EntitiesDB entitiesDB { set; private get; } + + public bool isRemovable => true; // This class is a custom implementation of CustomCommandEngine specific to this command // You can use Svelto.ECS.IEntityDB entitiesDB to query game entities or one of the protected variables for other things diff --git a/extracommands/ExitCommandEngine.cs b/extracommands/ExitCommandEngine.cs index d21187f..f3f4d00 100644 --- a/extracommands/ExitCommandEngine.cs +++ b/extracommands/ExitCommandEngine.cs @@ -1,29 +1,22 @@ -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; using GamecraftModdingAPI.Commands; namespace ExtraCommands.Basics { - [CustomCommand("Exit")] + [CustomCommand("Exit")] class ExitCommandEngine : ICustomCommandEngine { public string Description => "Close Gamecraft without any prompts"; public string Name => "Exit"; - public IEntitiesDB entitiesDB { set; private get; } + public EntitiesDB entitiesDB { set; private get; } - public void Ready() + public bool isRemovable => true; + + public void Ready() { CommandRegistrationHelper.Register(Name, ExitCommand, Description); } diff --git a/extracommands/ExtraCommands.csproj b/extracommands/ExtraCommands.csproj index ac4b16f..f8af339 100644 --- a/extracommands/ExtraCommands.csproj +++ b/extracommands/ExtraCommands.csproj @@ -5,10 +5,6 @@ true - - - - ..\ref\Plugins\GamecraftModdingAPI.dll @@ -28,7 +24,7 @@ ..\ref\Gamecraft_Data\Managed\RobocraftX.Character.dll - + ..\ref\Gamecraft_Data\Managed\RobocraftX.Common.dll @@ -76,12 +72,6 @@ ..\ref\Gamecraft_Data\Managed\Unity.Entities.Hybrid.dll - - ..\ref\Gamecraft_Data\Managed\Unity.Entities.Properties.dll - - - ..\ref\Gamecraft_Data\Managed\Unity.Entities.StaticTypeRegistry.dll - ..\ref\Gamecraft_Data\Managed\Unity.Mathematics.dll diff --git a/extracommands/MoveBlocksCommandEngine.cs b/extracommands/MoveBlocksCommandEngine.cs index d5e2c4b..c4eeecd 100644 --- a/extracommands/MoveBlocksCommandEngine.cs +++ b/extracommands/MoveBlocksCommandEngine.cs @@ -1,46 +1,38 @@ -using System; -using System.Collections.Generic; -using RobocraftX.Multiplayer; -using RobocraftX.Common; -using RobocraftX.Blocks; -using RobocraftX.Blocks.Ghost; using Svelto.ECS; -using Svelto.ECS.EntityStructs; -using Unity.Entities; -using Svelto.Context; -using Svelto.Tasks; -using RobocraftX; -using RobocraftX.SimulationModeState; -using RobocraftX.UECS; -using Unity.Transforms; +//using Svelto.Context; using Unity.Mathematics; -using UnityEngine; - -using GamecraftModdingAPI.Blocks; using GamecraftModdingAPI.Commands; +using GamecraftModdingAPI; namespace ExtraCommands.Building { - //[CustomCommand("MoveBlocks", "Move all blocks (including ground) from their original position")] - [CustomCommand("MoveLastBlock", "Move last block from original position")] + [CustomCommand("MoveLastBlock", "Move last block from original position")] class MoveBlocksCommandEngine : ICustomCommandEngine { public string Description => "Move blocks"; public string Name => "MoveBlocks"; - public IEntitiesDB entitiesDB { set; private get; } + public EntitiesDB entitiesDB { set; private get; } + + public bool isRemovable => false; public void Ready() { //CustomCommandUtility.Register("MoveBlocks", MoveBlocksCommand, "Move all blocks (including ground) from their original position"); - CommandRegistrationHelper.Register("MoveLastBlock", MoveLastBlockCommand, "Move last block from original position"); + CommandRegistrationHelper.Register("MoveLastBlock", MoveLastBlockCommand, "Move last block, and connecting blocks, from their original position"); } private void MoveLastBlockCommand(float x, float y, float z) { float3 vector = new float3(x, y, z); - Movement.MoveConnectedBlocks(BlockIdentifiers.LatestBlockID, vector); + Block lastBlock = Block.GetLastPlacedBlock(); + Block[] besideBlocks = lastBlock.GetConnectedCubes(); + for (int i = 0; i < besideBlocks.Length; i++) + { + besideBlocks[i].Position += vector; + } + //lastBlock.Position += vector; } public void Dispose() diff --git a/extracommands/RotateBlocksCommandEngine.cs b/extracommands/RotateBlocksCommandEngine.cs index 65982dd..a3357ca 100644 --- a/extracommands/RotateBlocksCommandEngine.cs +++ b/extracommands/RotateBlocksCommandEngine.cs @@ -1,35 +1,24 @@ -using System; -using System.Collections.Generic; -using RobocraftX.Multiplayer; -using RobocraftX.Common; using Svelto.ECS; -using Svelto.ECS.EntityStructs; -using Unity.Entities; -using Svelto.Context; -using Svelto.Tasks; -using RobocraftX; -using RobocraftX.SimulationModeState; -using RobocraftX.UECS; -using Unity.Transforms; +//using Svelto.Context; using Unity.Mathematics; -using UnityEngine; using GamecraftModdingAPI.Commands; -using GamecraftModdingAPI.Blocks; +using GamecraftModdingAPI; namespace ExtraCommands.Building { - //[CustomCommand("RotateBlocks", "Rotate all blocks (including ground) from their original position")] - [CustomCommand("RotateLastBlock", "Rotate last block from original position")] + [CustomCommand("RotateLastBlock", "Rotate last block from original position")] class RotateBlocksCommandEngine : ICustomCommandEngine { public string Description => "Rotate last block from original position"; public string Name => "RotateLastBlock"; - public IEntitiesDB entitiesDB { set; private get; } + public EntitiesDB entitiesDB { set; private get; } - public void Ready() + public bool isRemovable => true; + + public void Ready() { CommandRegistrationHelper.Register(Name, RotateLastBlockCommand, Description); } @@ -38,7 +27,8 @@ namespace ExtraCommands.Building private void RotateLastBlockCommand(float x, float y, float z) { float3 eulerAngles = new float3(x, y, z); - GamecraftModdingAPI.Blocks.Rotation.RotateBlock(BlockIdentifiers.LatestBlockID, eulerAngles); + Block.GetLastPlacedBlock().Rotation += eulerAngles; + //GamecraftModdingAPI.Blocks.Rotation.RotateBlock(BlockIdentifiers.LatestBlockID, eulerAngles); } public void Dispose() diff --git a/extracommands/RotatePlayerCommandEngine.cs b/extracommands/RotatePlayerCommandEngine.cs index 3a0da6e..80538b7 100644 --- a/extracommands/RotatePlayerCommandEngine.cs +++ b/extracommands/RotatePlayerCommandEngine.cs @@ -1,15 +1,6 @@ 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; -using Svelto.ECS.EntityStructs; +//using Svelto.Context; using Unity.Mathematics; using RobocraftX.Character.Camera; using RobocraftX.Character.Factories; @@ -18,16 +9,18 @@ using GamecraftModdingAPI.Commands; namespace ExtraCommands.Basics { - [CustomCommand("Rotation")] + [CustomCommand("Rotation")] class RotatePlayerCommandEngine : ICustomCommandEngine { public string Description => "Rotation"; public string Name => "Rotation commands"; - public IEntitiesDB entitiesDB { set; private get; } + public EntitiesDB entitiesDB { set; private get; } - public void Ready() + public bool isRemovable => true; + + public void Ready() { CommandRegistrationHelper.Register("RotateAbsolute", RotateAbsoluteCommand, "Rotate the player camera to the entered rotation"); CommandRegistrationHelper.Register("RotateRelative", RotateRelativeCommand, "Rotate the player camera by the entered rotation"); @@ -37,7 +30,7 @@ namespace ExtraCommands.Basics private void RotateAbsoluteCommand(float vertical, float horizontal) { uint count; - CharacterCameraEntityStruct[] cameras = entitiesDB.QueryEntities(CameraExclusiveGroups.VisualCameraGroup, out count); + CharacterCameraEntityStruct[] cameras = entitiesDB.QueryEntities(CameraExclusiveGroups.VisualCameraGroup).ToFastAccess(out count); int num2 = 0; while ((long)num2 < (long)((ulong)count)) { @@ -61,7 +54,7 @@ namespace ExtraCommands.Basics { float2 angleDelta = new float2(vertical, horizontal); uint count; - ValueTuple tuple = this.entitiesDB.QueryEntities(CameraExclusiveGroups.VisualCameraGroup, out count); + ValueTuple tuple = this.entitiesDB.QueryEntities(CameraExclusiveGroups.VisualCameraGroup).ToFastAccess(out count); CharacterCameraSettingsEntityStruct[] settings = tuple.Item1; CharacterCameraEntityStruct[] cameras = tuple.Item2; int num2 = 0; diff --git a/extracommands/SetFOVCommandEngine.cs b/extracommands/SetFOVCommandEngine.cs index dce351e..7f94a9c 100644 --- a/extracommands/SetFOVCommandEngine.cs +++ b/extracommands/SetFOVCommandEngine.cs @@ -1,29 +1,23 @@ -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; +//using Svelto.Context; using GamecraftModdingAPI.Commands; namespace ExtraCommands.Basics { - [CustomCommand("SetFieldOfView")] + [CustomCommand("SetFieldOfView")] class SetFOVCommandEngine : ICustomCommandEngine { public string Description => "Set the camera's field of view"; public string Name => "SetFieldOfView"; - public IEntitiesDB entitiesDB { set; private get; } + public EntitiesDB entitiesDB { set; private get; } - public void Ready() + public bool isRemovable => true; + + public void Ready() { CommandRegistrationHelper.Register(Name, SetFieldOfViewCommand, Description); } diff --git a/extracommands/SetTargetFramerateCommandEngine.cs b/extracommands/SetTargetFramerateCommandEngine.cs index ef4930f..3aa1bd4 100644 --- a/extracommands/SetTargetFramerateCommandEngine.cs +++ b/extracommands/SetTargetFramerateCommandEngine.cs @@ -1,27 +1,21 @@ -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; +//using Svelto.Context; using GamecraftModdingAPI.Commands; namespace ExtraCommands.Basics { - [CustomCommand("SetTargetFPS")] + [CustomCommand("SetTargetFPS")] class SetTargetFramerateCommandEngine : ICustomCommandEngine { public string Description => "Set Gamecraft's target FPS'"; public string Name => "SetTargetFPS"; - public IEntitiesDB entitiesDB { set; private get; } + public EntitiesDB entitiesDB { set; private get; } + + public bool isRemovable => true; public void Ready() { diff --git a/extracommands/TeleportWaypointCommandEngine.cs b/extracommands/TeleportWaypointCommandEngine.cs index d1a96b8..4bd0fa4 100644 --- a/extracommands/TeleportWaypointCommandEngine.cs +++ b/extracommands/TeleportWaypointCommandEngine.cs @@ -1,21 +1,14 @@ -using System; -using System.Collections.Generic; -using RobocraftX.GUI.CommandLine; -using RobocraftX.Multiplayer; -using RobocraftX.StateSync; -using RobocraftX.Character; +using System.Collections.Generic; using Svelto.ECS; -using Unity.Entities; -using uREPL; -using Svelto.Context; -using RobocraftX; -using RobocraftX.Physics; +//using Svelto.Context; using GamecraftModdingAPI.Commands; +using GamecraftModdingAPI; +using GamecraftModdingAPI.Players; namespace ExtraCommands.Waypoints { - [CustomCommand("Waypoints")] + [CustomCommand("Waypoints")] class TeleportWaypointCommandEngine : ICustomCommandEngine { private Dictionary _waypoints = new Dictionary(); @@ -24,9 +17,11 @@ namespace ExtraCommands.Waypoints public string Name => "Waypoints"; - public IEntitiesDB entitiesDB { set; private get; } + public EntitiesDB entitiesDB { set; private get; } - public void Ready() + public bool isRemovable => true; + + public void Ready() { CommandRegistrationHelper.Register("CreateWaypoint", CreateWaypointCommand, "Create a waypoint in your current location"); CommandRegistrationHelper.Register("TeleportPlayerWaypoint", TeleportToWaypointCommand, "Teleport to a waypoint"); @@ -34,8 +29,8 @@ namespace ExtraCommands.Waypoints private void CreateWaypointCommand(object name) { - ref RigidBodyEntityStruct reference = ref entitiesDB.QueryEntity(0u, CharacterExclusiveGroups.CharacterGroup); - _waypoints[name] = new float[3] { reference.position.x, reference.position.y, reference.position.z }; + Player reference = new Player(PlayerType.Local); + _waypoints[name] = new float[3] { reference.Position.x, reference.Position.y, reference.Position.z }; uREPL.Log.Output("Saved " + name.ToString()); } diff --git a/extracommands/WaitCommandEngine.cs b/extracommands/WaitCommandEngine.cs deleted file mode 100644 index b61dc41..0000000 --- a/extracommands/WaitCommandEngine.cs +++ /dev/null @@ -1,41 +0,0 @@ -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; - -using GamecraftModdingAPI.Commands; - -namespace ExtraCommands.Basics -{ - [CustomCommand("Wait")] - class WaitCommandEngine : ICustomCommandEngine - { - public string Description => "Delay execution (freeze the game) for a length of time (ms)"; - - public string Name => "Wait"; - - public IEntitiesDB entitiesDB { set; private get; } - - public void Ready() - { - CommandRegistrationHelper.Register("Wait", WaitCommand, "Delay execution (freeze the game) for a length of time (ms)"); - } - - private void WaitCommand(int ms) - { - System.Threading.Thread.Sleep(ms); - } - - public void Dispose() - { - CommandRegistrationHelper.Unregister("Wait"); - } - } -}