Highlight previous and next nodes of a selected node

master
D4VID 6 months ago
parent 295993f4e8
commit a8553ae2bf

@ -16,3 +16,9 @@ CriticalPathAnalyzer.AnalyzePathEnd:
DefaultBinding: DefaultBinding:
Options: Options:
- O - O
CriticalPathAnalyzer.SelectNode:
Heading: "CriticalPathAnalyzer"
DefaultBinding:
Options:
- T

@ -14,3 +14,9 @@ FancyInput.Trigger.CriticalPathAnalyzer.AnalyzePathEnd: "Select end of path"
FancyInput.Trigger.CriticalPathAnalyzer.AnalyzePathEnd.Description: """ FancyInput.Trigger.CriticalPathAnalyzer.AnalyzePathEnd.Description: """
Press to select the end of the path to be analyzed. Press to select the end of the path to be analyzed.
""" """
FancyInput.Trigger.CriticalPathAnalyzer.SelectNode: "Select node to be analyzed"
FancyInput.Trigger.CriticalPathAnalyzer.SelectNode.Description: """
Press to select a node to be analyzed.
Can only be used after obtaining circuit data from the server by analyzing a path.
"""

@ -1,7 +1,7 @@
ID: CriticalPathAnalyzer ID: CriticalPathAnalyzer
Name: CriticalPathAnalyzer Name: CriticalPathAnalyzer
Author: D4VID Author: D4VID
Version: 0.2.0 Version: 0.2.1
Priority: 0 Priority: 0
Dependencies: Dependencies:
- HarmonyForLogicWorld - HarmonyForLogicWorld

@ -24,6 +24,7 @@ namespace CriticalPathAnalyzer.Client {
UITrigger.Back, UITrigger.Back,
CriticalPathAnalyzerTrigger.AnalyzePathStart, CriticalPathAnalyzerTrigger.AnalyzePathStart,
CriticalPathAnalyzerTrigger.AnalyzePathEnd, CriticalPathAnalyzerTrigger.AnalyzePathEnd,
CriticalPathAnalyzerTrigger.SelectNode,
}; };
/// <summary> /// <summary>
@ -43,6 +44,8 @@ namespace CriticalPathAnalyzer.Client {
CriticalPathAnalyzerTool.SelectPathStart(); CriticalPathAnalyzerTool.SelectPathStart();
} else if (CustomInput.DownThisFrame(CriticalPathAnalyzerTrigger.AnalyzePathEnd)) { } else if (CustomInput.DownThisFrame(CriticalPathAnalyzerTrigger.AnalyzePathEnd)) {
CriticalPathAnalyzerTool.SelectPathEnd(); CriticalPathAnalyzerTool.SelectPathEnd();
} else if (CustomInput.DownThisFrame(CriticalPathAnalyzerTrigger.SelectNode)) {
CriticalPathAnalyzerTool.SelectNodeToAnalyze();
} }
} }

@ -5,5 +5,6 @@ namespace CriticalPathAnalyzer.Client.Keybindings {
OpenPathAnalyzer, OpenPathAnalyzer,
AnalyzePathStart, AnalyzePathStart,
AnalyzePathEnd, AnalyzePathEnd,
SelectNode,
} }
} }

@ -18,12 +18,14 @@ namespace CriticalPathAnalyzer.Client.Tool {
private static Guid _currentRequestGuid = Guid.NewGuid(); private static Guid _currentRequestGuid = Guid.NewGuid();
private static AnalyzePathResponse _response; private static AnalyzePathResponse _response;
private static Node _selectedNode;
private static readonly OutlineData StartOutline = new OutlineData(new Color24(0x00ff00)); private static readonly OutlineData StartOutline = new OutlineData(new Color24(0x00ff00));
private static readonly OutlineData EndOutline = new OutlineData(new Color24(0x00aaff)); private static readonly OutlineData EndOutline = new OutlineData(new Color24(0x00aaff));
public static void Init(ILogicLogger logger) { public static void Init(ILogicLogger logger) {
_logger = logger; _logger = logger;
PathHighlighter.Init(logger);
} }
/// <summary> /// <summary>
@ -80,6 +82,35 @@ namespace CriticalPathAnalyzer.Client.Tool {
} }
} }
} }
/// <summary>
/// Try to select the start of the path.
/// </summary>
public static void SelectNodeToAnalyze() {
if (_response == null) {
_logger.Info("No circuit data");
// Cannot do anything without data
return;
}
PegAddress pegAddress = RayCastPeg();
if (!pegAddress.IsEmpty()) {
Node node = _response.Nodes.Find(n => n.Pegs.Contains(pegAddress));
if (node != null) {
PathHighlighter.RemoveHighlighting();
_logger.Info("Highlighting selected node");
PathHighlighter.HighlightAnalyzedNode(node);
_selectedNode = node;
} else {
_logger.Info("Peg not found in circuit data");
}
} else {
// Deselect
_logger.Info("Didn't hit anything");
PathHighlighter.RemoveHighlighting();
_selectedNode = null;
}
}
/// <summary> /// <summary>
/// Try to select the end of the path. /// Try to select the end of the path.
@ -129,6 +160,7 @@ namespace CriticalPathAnalyzer.Client.Tool {
_response = response; _response = response;
PathHighlighter.RemoveHighlighting(); PathHighlighter.RemoveHighlighting();
PathHighlighter.SetNodes(_response.Nodes);
if (_response.LoopingNodes.Count > 0) { if (_response.LoopingNodes.Count > 0) {
PathHighlighter.HighlightClusterNodes(_response.LoopingNodes); PathHighlighter.HighlightClusterNodes(_response.LoopingNodes);

@ -4,29 +4,51 @@ using CriticalPathAnalyzer.Shared.Packets.S2C;
using JimmysUnityUtilities; using JimmysUnityUtilities;
using LogicAPI.Data; using LogicAPI.Data;
using LogicAPI.Services; using LogicAPI.Services;
using LogicLog;
using LogicWorld.Interfaces; using LogicWorld.Interfaces;
using LogicWorld.Outlines; using LogicWorld.Outlines;
namespace CriticalPathAnalyzer.Client.Tool { namespace CriticalPathAnalyzer.Client.Tool {
public class PathHighlighter { public class PathHighlighter {
private static ILogicLogger _logger;
private static List<Node> _nodes = new List<Node>(); private static List<Node> _nodes = new List<Node>();
private static List<WireAddress> _highlightedWires = new List<WireAddress>(); private static List<WireAddress> _highlightedWires = new List<WireAddress>();
public static void Init(ILogicLogger logger) {
_logger = logger;
}
public static void SetNodes(List<Node> nodes) {
_nodes = nodes;
}
public static void HighlightClusterNodes(List<Node> nodes) { public static void HighlightClusterNodes(List<Node> nodes) {
_nodes = nodes; foreach (Node node in nodes) {
HighlightNode(node, HsvToRgb(node.Time * 20, 1.0f, 1.0f));
}
}
foreach (Node node in _nodes) { public static void HighlightAnalyzedNode(Node node) {
HighlightNode(node); _logger.Info($"Selected node: {node}");
HighlightNode(node, 0x00ff00);
foreach (int prevNodeIndex in node.PrevNodeIndexes) {
_logger.Info($"Highlighting prev node index {prevNodeIndex}");
HighlightNode(_nodes[prevNodeIndex], 0xff0000);
}
foreach ((int nextNodeIndex, int delay) in node.NextNodes) {
_logger.Info($"Highlighting next node index {nextNodeIndex}");
HighlightNode(_nodes[nextNodeIndex], 0x0000ff);
} }
} }
/// <summary> /// <summary>
/// Highlight all pegs and wires of the given cluster. /// Highlight all pegs and wires of the given cluster.
/// </summary> /// </summary>
private static void HighlightNode(Node node) { private static void HighlightNode(Node node, int color) {
IWorldData world = Instances.MainWorld.Data; IWorldData world = Instances.MainWorld.Data;
var outline = new OutlineData(new Color24(HsvToRgb(node.Time * 20, 1.0f, 1.0f))); var outline = new OutlineData(new Color24(color));
foreach (ComponentAddress address in node.ConnectingComponents) { foreach (ComponentAddress address in node.ConnectingComponents) {
if (!world.Contains(address)) { if (!world.Contains(address)) {
@ -76,7 +98,6 @@ namespace CriticalPathAnalyzer.Client.Tool {
Outliner.RemoveOutline(wireAddress); Outliner.RemoveOutline(wireAddress);
} }
_nodes = null;
_highlightedWires.Clear(); _highlightedWires.Clear();
} }

Loading…
Cancel
Save