From 72a447cc0ea85a9ffb6b4c5241c91b7c634b259f Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 12 Aug 2021 03:30:39 +0200 Subject: [PATCH] Add wire info --- BuildingTools/BuildingTools.cs | 20 +++++++++++++++++++- BuildingTools/NoGarageCommand.cs | 17 ++++++----------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/BuildingTools/BuildingTools.cs b/BuildingTools/BuildingTools.cs index aac6bce..618261e 100644 --- a/BuildingTools/BuildingTools.cs +++ b/BuildingTools/BuildingTools.cs @@ -262,7 +262,7 @@ namespace BuildingTools private static string GetBlockInfoInBuildMode() { var block = Player.LocalPlayer.GetBlockLookedAt(); - if (block == null) return ""; + if (block == null) return GetWireInfoInBuildMode(); float3 pos = block.Position; float3 rot = block.Rotation; float3 scale = block.Scale; @@ -275,6 +275,24 @@ namespace BuildingTools $"- Group: {block.BlockGroup.Id}"; } + private static string GetWireInfoInBuildMode() + { + var wire = Player.LocalPlayer.GetWireLookedAt(); + if (wire == null) return ""; + var startPos = wire.Start.Position; + var endPos = wire.End.Position; + Console.WriteLine("Start port: " + wire.StartPort + " End port: " + wire.EndPort); + Console.WriteLine("Start block: " + wire.Start); + Console.WriteLine("End block: " + wire.End); + string startName = wire.StartPort != byte.MaxValue ? wire.Start.OutputPortName(wire.StartPort) : "no port"; + string endName = wire.EndPort != byte.MaxValue ? wire.End.InputPortName(wire.EndPort) : "no port"; + return $"Wire with {wire.Id}\n" + + $"- From block {wire.Start.Type} at {startPos.x:F} {startPos.y:F} {startPos.z:F}\n" + + $"- at port {startName}\n" + + $"- To block {wire.End.Type} at {endPos.x:F} {endPos.y:F} {endPos.z:F}\n" + + $"- at port {endName}"; + } + private static string GetBodyInfoInSimMode() { var body = Player.LocalPlayer.GetSimBodyLookedAt(); diff --git a/BuildingTools/NoGarageCommand.cs b/BuildingTools/NoGarageCommand.cs index a0bd29e..3c9bbff 100644 --- a/BuildingTools/NoGarageCommand.cs +++ b/BuildingTools/NoGarageCommand.cs @@ -1,6 +1,7 @@ using System; using System.Reflection; using HarmonyLib; +using TechbloxModdingAPI.Utility; using UnityEngine; namespace BuildingTools @@ -11,10 +12,11 @@ namespace BuildingTools public void Toggle() { - Console.WriteLine("Toggling no garage"); + Logging.CommandLog("Toggling no garage"); + // ReSharper disable once AssignmentInConditionalExpression if(_enabled = !_enabled) Enable(); - Console.WriteLine($"{(_enabled ? "Enabled" : "Disabled")} no garage"); + Logging.CommandLog($"{(_enabled ? "Enabled" : "Disabled")} no garage"); } private void Enable() @@ -23,13 +25,7 @@ namespace BuildingTools var simObj = (GameObject)AccessTools.Field(type, "THIS_IS_TEMPORARY_CODE_IT_IS_GOING_TO_BE_DELETED_ONCE_WE_HAVE_THE_FINAL_WORLD_SWITCHING_sim_go") .GetValue(null); - /*var buildObjField = AccessTools.Field(type, - "THIS_IS_TEMPORARY_CODE_IT_IS_GOING_TO_BE_DELETED_ONCE_WE_HAVE_THE_FINAL_WORLD_SWITCHING_build_go"); - var buildObj = (GameObject) buildObjField.GetValue(null); - Console.WriteLine($"obj: {simObj}");*/ var componentType = AccessTools.TypeByName("Techblox.Garage.GarageMachineBoundaryImplementor"); - //var component = buildObj.GetComponent(componentType); - //var newBuildObj = Object.Instantiate(simObj); simObj.AddComponent(componentType); var component = simObj.GetComponent(componentType); AccessTools.Field(componentType, "_bounds") @@ -38,7 +34,6 @@ namespace BuildingTools .SetValue(component, 1f); AccessTools.Field(componentType, "_cameraLookPointDistance") .SetValue(component, 1f); - //buildObjField.SetValue(null, newBuildObj); } [HarmonyPatch] @@ -47,10 +42,10 @@ namespace BuildingTools public static bool Prefix(object __instance) { if (!_enabled) return true; - Console.WriteLine("Got a time stopped init event"); + Logging.MetaDebugLog("Got a time stopped init event"); AccessTools.Method("Techblox.Environment.Temporary.EnvironmentSwitchEngine:OnTimeRunningInitializationComplete") .Invoke(__instance, Array.Empty()); - Console.WriteLine("Successfully called time running init event"); + Logging.MetaDebugLog("Successfully called time running init event"); return false; }