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:
Options:
- 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: """
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
Name: CriticalPathAnalyzer
Author: D4VID
Version: 0.2.0
Version: 0.2.1
Priority: 0
Dependencies:
- HarmonyForLogicWorld

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

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

@ -18,12 +18,14 @@ namespace CriticalPathAnalyzer.Client.Tool {
private static Guid _currentRequestGuid = Guid.NewGuid();
private static AnalyzePathResponse _response;
private static Node _selectedNode;
private static readonly OutlineData StartOutline = new OutlineData(new Color24(0x00ff00));
private static readonly OutlineData EndOutline = new OutlineData(new Color24(0x00aaff));
public static void Init(ILogicLogger logger) {
_logger = logger;
PathHighlighter.Init(logger);
}
/// <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>
/// Try to select the end of the path.
@ -129,6 +160,7 @@ namespace CriticalPathAnalyzer.Client.Tool {
_response = response;
PathHighlighter.RemoveHighlighting();
PathHighlighter.SetNodes(_response.Nodes);
if (_response.LoopingNodes.Count > 0) {
PathHighlighter.HighlightClusterNodes(_response.LoopingNodes);

@ -4,29 +4,51 @@ using CriticalPathAnalyzer.Shared.Packets.S2C;
using JimmysUnityUtilities;
using LogicAPI.Data;
using LogicAPI.Services;
using LogicLog;
using LogicWorld.Interfaces;
using LogicWorld.Outlines;
namespace CriticalPathAnalyzer.Client.Tool {
public class PathHighlighter {
private static ILogicLogger _logger;
private static List<Node> _nodes = new List<Node>();
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) {
_nodes = nodes;
foreach (Node node in nodes) {
HighlightNode(node, HsvToRgb(node.Time * 20, 1.0f, 1.0f));
}
}
foreach (Node node in _nodes) {
HighlightNode(node);
public static void HighlightAnalyzedNode(Node 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>
/// Highlight all pegs and wires of the given cluster.
/// </summary>
private static void HighlightNode(Node node) {
private static void HighlightNode(Node node, int color) {
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) {
if (!world.Contains(address)) {
@ -76,7 +98,6 @@ namespace CriticalPathAnalyzer.Client.Tool {
Outliner.RemoveOutline(wireAddress);
}
_nodes = null;
_highlightedWires.Clear();
}

Loading…
Cancel
Save