From 220eb02a1996c38d3c2924ce9f13b692e520e0ed Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Tue, 25 May 2021 01:20:46 +0200 Subject: [PATCH] Return descriptions with command names, selected block/color fix --- TechbloxModdingAPI/Commands/ExistingCommands.cs | 15 ++++++--------- TechbloxModdingAPI/FlyCam.cs | 13 +++++++++++++ TechbloxModdingAPI/Player.cs | 4 ++-- TechbloxModdingAPI/Players/FlyCamEngine.cs | 12 ++++++++++++ 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/TechbloxModdingAPI/Commands/ExistingCommands.cs b/TechbloxModdingAPI/Commands/ExistingCommands.cs index 35dd199..dfd3921 100644 --- a/TechbloxModdingAPI/Commands/ExistingCommands.cs +++ b/TechbloxModdingAPI/Commands/ExistingCommands.cs @@ -1,4 +1,4 @@ -using System; +using System.Linq; using uREPL; @@ -27,16 +27,13 @@ namespace TechbloxModdingAPI.Commands } public static bool Exists(string commandName) - { + { return RuntimeCommands.HasRegistered(commandName); } - public static string[] GetCommandNames() - { - var keys = RuntimeCommands.table.Keys; - string[] res = new string[keys.Count]; - keys.CopyTo(res, 0); - return res; - } + public static (string Name, string Description)[] GetCommandNamesAndDescriptions() + { + return RuntimeCommands.table.Values.Select(command => (command.name, command.description)).ToArray(); + } } } diff --git a/TechbloxModdingAPI/FlyCam.cs b/TechbloxModdingAPI/FlyCam.cs index 201fd0a..edf0691 100644 --- a/TechbloxModdingAPI/FlyCam.cs +++ b/TechbloxModdingAPI/FlyCam.cs @@ -2,6 +2,7 @@ using RobocraftX.Physics; using Svelto.ECS; using Svelto.ECS.EntityStructs; using Techblox.FlyCam; +using TechbloxModdingAPI.Blocks; using TechbloxModdingAPI.Players; using TechbloxModdingAPI.Utility; using Unity.Mathematics; @@ -111,6 +112,18 @@ namespace TechbloxModdingAPI set => Engine.GetComponent(this).angularVelocity = value; } + /// + /// The player's selected block ID in their hand. + /// + /// The selected block. + public BlockIDs SelectedBlock => (BlockIDs)Engine.GetSelectedBlock(this); + + /// + /// The player's selected block color in their hand. + /// + /// The selected block's color. + public BlockColor SelectedColor => new BlockColor(Engine.GetSelectedColor(this)); + public static void Init() { GameEngineManager.AddGameEngine(Engine); diff --git a/TechbloxModdingAPI/Player.cs b/TechbloxModdingAPI/Player.cs index a5e5dc5..7d37f9b 100644 --- a/TechbloxModdingAPI/Player.cs +++ b/TechbloxModdingAPI/Player.cs @@ -313,7 +313,7 @@ namespace TechbloxModdingAPI { get { - return (BlockIDs)playerEngine.GetSelectedBlock(Id); + return BuildCamera.SelectedBlock; } } @@ -325,7 +325,7 @@ namespace TechbloxModdingAPI { get { - return new BlockColor(playerEngine.GetSelectedColor(Id)); + return BuildCamera.SelectedColor; } } diff --git a/TechbloxModdingAPI/Players/FlyCamEngine.cs b/TechbloxModdingAPI/Players/FlyCamEngine.cs index 2db12e5..7cad252 100644 --- a/TechbloxModdingAPI/Players/FlyCamEngine.cs +++ b/TechbloxModdingAPI/Players/FlyCamEngine.cs @@ -23,5 +23,17 @@ namespace TechbloxModdingAPI.Players { return ref entitiesDB.QueryEntityOrDefault(cam); } + + public ushort GetSelectedBlock(FlyCam cam) + { + var oc = entitiesDB.QueryEntityOptional(cam); + return oc ? (ushort) oc.Get().SelectedDBPartID : ushort.MaxValue; + } + + public byte GetSelectedColor(FlyCam cam) + { + var oc = entitiesDB.QueryEntityOptional(cam); + return oc ? oc.Get().indexInPalette : (byte) 255; + } } } \ No newline at end of file