parent
9787444372
commit
4978487e2e
@ -1,3 +1,6 @@
|
|||||||
CriticalPathAnalyzer.CriticalPathAnalyzer:
|
CriticalPathAnalyzer.CriticalPathAnalyzer:
|
||||||
|
InjectTriggersInto:
|
||||||
|
- MHG.BuildActions
|
||||||
Triggers:
|
Triggers:
|
||||||
- CriticalPathAnalyzer.AnalyzeCriticalPath
|
- CriticalPathAnalyzer.AnalyzePathStart
|
||||||
|
- CriticalPathAnalyzer.AnalyzePathEnd
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
MHG.SettingsMenu.Pages.Controls.Headings.CriticalPathAnalyzer: "Mod: Critical Path Analyzer"
|
MHG.SettingsMenu.Pages.Controls.Headings.CriticalPathAnalyzer: "Mod: Critical Path Analyzer"
|
||||||
|
|
||||||
FancyInput.Trigger.CriticalPathAnalyzer.AnalyzeCriticalPath: "Analyze Critical Path"
|
FancyInput.Trigger.CriticalPathAnalyzer.AnalyzePathStart: "Select start of path"
|
||||||
FancyInput.Trigger.CriticalPathAnalyzer.AnalyzeCriticalPath.Description : """
|
FancyInput.Trigger.CriticalPathAnalyzer.AnalyzePathStart.Description : """
|
||||||
Press once to select the start of the path and a second time to select the end.
|
Press to select the start of the path to be analyzed.
|
||||||
|
"""
|
||||||
|
|
||||||
|
FancyInput.Trigger.CriticalPathAnalyzer.AnalyzePathEnd: "Select end of path"
|
||||||
|
FancyInput.Trigger.CriticalPathAnalyzer.AnalyzePathEnd.Description : """
|
||||||
|
Press to select the end of the path to be analyzed.
|
||||||
"""
|
"""
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using CriticalPathAnalyzer.Client.Keybindings;
|
||||||
|
using CriticalPathAnalyzer.Client.tool;
|
||||||
|
using FancyInput;
|
||||||
|
using LogicUI;
|
||||||
|
using LogicWorld.GameStates;
|
||||||
|
|
||||||
|
namespace CriticalPathAnalyzer.Client {
|
||||||
|
public class CriticalPathAnalyzerGameState : GameState {
|
||||||
|
public const string Id = "CriticalPathAnalyzer.Analyzing";
|
||||||
|
|
||||||
|
public override bool MouseLocked => true;
|
||||||
|
public override string TextID => Id;
|
||||||
|
|
||||||
|
public override IEnumerable<InputTrigger> HelpScreenTriggers => new InputTrigger[] {
|
||||||
|
UITrigger.Back,
|
||||||
|
CriticalPathAnalyzerTrigger.AnalyzePathStart,
|
||||||
|
CriticalPathAnalyzerTrigger.AnalyzePathEnd,
|
||||||
|
};
|
||||||
|
|
||||||
|
public override void OnEnter() {
|
||||||
|
CriticalPathAnalyzerClient.LoggerInstance.Info("CPA enter");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnRun() {
|
||||||
|
if (CustomInput.DownThisFrame(UITrigger.Back)) {
|
||||||
|
GameStateManager.TransitionBackToBuildingState();
|
||||||
|
} else if (CustomInput.DownThisFrame(CriticalPathAnalyzerTrigger.AnalyzePathStart)) {
|
||||||
|
CriticalPathAnalyzerTool.SelectPathStart();
|
||||||
|
} else if (CustomInput.DownThisFrame(CriticalPathAnalyzerTrigger.AnalyzePathEnd)) {
|
||||||
|
CriticalPathAnalyzerTool.SelectPathEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnExit() {
|
||||||
|
CriticalPathAnalyzerClient.LoggerInstance.Info("CPA exit");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
using CriticalPathAnalyzer.Client.Keybindings;
|
||||||
|
using EccsLogicWorldAPI.Shared.AccessHelper;
|
||||||
|
using FancyInput;
|
||||||
|
using HarmonyLib;
|
||||||
|
using LogicWorld.Building;
|
||||||
|
using LogicWorld.GameStates;
|
||||||
|
|
||||||
|
namespace CriticalPathAnalyzer.Client {
|
||||||
|
public class KeybindingsInjector {
|
||||||
|
// Fairly generic hook into adding custom keybindings to the main building game state of LW.
|
||||||
|
// Allows to add keybindings to open new GUI elements or add new core building actions (which are not build-operations).
|
||||||
|
public static void Inject() {
|
||||||
|
var methodTarget = Methods.getPrivateStatic(typeof(StuffDeleter), "RunFirstPersonWireDeleting");
|
||||||
|
var methodHook = Methods.getPrivateStatic(typeof(KeybindingsInjector), nameof(Hook));
|
||||||
|
var harmony = new Harmony(nameof(CriticalPathAnalyzer));
|
||||||
|
harmony.Patch(methodTarget, prefix: new HarmonyMethod(methodHook));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool Hook(out bool deletedWire) {
|
||||||
|
if (CustomInput.DownThisFrame(CriticalPathAnalyzerTrigger.AnalyzePathStart)) {
|
||||||
|
GameStateManager.TransitionTo(CriticalPathAnalyzerGameState.Id);
|
||||||
|
|
||||||
|
deletedWire = true; // True = Cancel remaining keybinding handling.
|
||||||
|
return false; // Prevent execution of the original/further functionality.
|
||||||
|
}
|
||||||
|
|
||||||
|
deletedWire = false; // Default, might be overwritten. False = Do not cancel remaining keybinding handling.
|
||||||
|
return true; // Allow original/further functionality.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
namespace CriticalPathAnalyzer.Client.Keybindings {
|
namespace CriticalPathAnalyzer.Client.Keybindings {
|
||||||
public enum CriticalPathAnalyzerTrigger {
|
public enum CriticalPathAnalyzerTrigger {
|
||||||
None,
|
None,
|
||||||
AnalyzeCriticalPath
|
AnalyzePathStart,
|
||||||
|
AnalyzePathEnd,
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
using LogicAPI.Data;
|
||||||
|
using LogicWorld.Interfaces;
|
||||||
|
using LogicWorld.Physics;
|
||||||
|
using LogicWorld.Players;
|
||||||
|
|
||||||
|
namespace CriticalPathAnalyzer.Client.tool {
|
||||||
|
public class CriticalPathAnalyzerTool {
|
||||||
|
private static PegAddress _startPegAddress;
|
||||||
|
private static PegAddress _endPegAddress;
|
||||||
|
|
||||||
|
private static PegAddress? RayCastPeg() {
|
||||||
|
// Ray-cast into the world to find what the player is looking at
|
||||||
|
HitInfo hitInfo = PlayerCaster.CameraCast(Masks.Environment | Masks.Structure | Masks.Peg | Masks.Wire);
|
||||||
|
if (!hitInfo.HitSomething) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resolve hit target:
|
||||||
|
if (hitInfo.HitPeg) {
|
||||||
|
CriticalPathAnalyzerClient.LoggerInstance.Info("Hit peg");
|
||||||
|
return _startPegAddress = hitInfo.pAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hitInfo.HitWire) {
|
||||||
|
CriticalPathAnalyzerClient.LoggerInstance.Info("Hit wire");
|
||||||
|
WireAddress wireAddress = hitInfo.wAddress;
|
||||||
|
Wire wire = Instances.MainWorld.Data.Lookup(wireAddress);
|
||||||
|
// Assume that wire is never null, as we did just ray-casted it.
|
||||||
|
return wire.Point1.IsInputAddress() ? wire.Point1 : wire.Point2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SelectPathStart() {
|
||||||
|
CriticalPathAnalyzerClient.LoggerInstance.Info("Analyze Path Start");
|
||||||
|
PegAddress? pegAddress = RayCastPeg();
|
||||||
|
if (pegAddress != null) {
|
||||||
|
_startPegAddress = pegAddress.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SelectPathEnd() {
|
||||||
|
CriticalPathAnalyzerClient.LoggerInstance.Info("Analyze Path End");
|
||||||
|
PegAddress? pegAddress = RayCastPeg();
|
||||||
|
if (pegAddress != null) {
|
||||||
|
_endPegAddress = pegAddress.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue