Correct highlighting and unhighlighting

master
D4VID 7 months ago
parent 585b2116c1
commit a64e1bb2b2

@ -34,20 +34,7 @@ namespace CriticalPathAnalyzer.Client {
public static void OnAnalyzePathResponse(AnalyzePathResponse response) {
LoggerInstance.Info($"Got response from server");
PathHighLighter.HighlightWires(response);
// if(!CurrentRequestID.HasValue || response.requestGuid != currentRequestID.Value)
// {
// //Not matching Guid, old or wrong request, discard.
// return;
// }
// currentRequestID = null; //Received response, clear GUID.
//
// //Clear up all data immediately:
// if(currentTracer != null)
// {
// currentTracer.stop();
// currentTracer = null;
// }
CriticalPathAnalyzerTool.Highlight(response);
}
}
}

@ -1,5 +1,6 @@
using System;
using CriticalPathAnalyzer.Shared.Packets.C2S;
using CriticalPathAnalyzer.Shared.Packets.S2C;
using LogicAPI.Data;
using LogicLog;
using LogicWorld.Interfaces;
@ -15,6 +16,8 @@ namespace CriticalPathAnalyzer.Client.Tool {
private static PegAddress? _startPegAddress;
private static PegAddress? _endPegAddress;
private static Guid _currentRequestGuid = Guid.NewGuid();
public static void Init(ILogicLogger logger) {
_logger = logger;
}
@ -77,11 +80,23 @@ namespace CriticalPathAnalyzer.Client.Tool {
return;
}
_currentRequestGuid = Guid.NewGuid();
Instances.SendData.Send(new AnalyzePathRequest {
RequestGuid = Guid.NewGuid(),
RequestGuid = _currentRequestGuid,
StartPegAddress = _startPegAddress.Value,
EndPegAddress = _endPegAddress.Value,
});
}
public static void Highlight(AnalyzePathResponse response) {
if (_currentRequestGuid != response.RequestGuid) {
// Not matching Guid, old or wrong request, discard.
_logger.Warn("Got response to wrong request, discarding");
return;
}
PathHighLighter.RemoveHighLighting();
PathHighLighter.HighlightWires(response);
}
}
}

@ -1,6 +1,6 @@
using System.Collections.Generic;
using CriticalPathAnalyzer.client.tool;
using CriticalPathAnalyzer.Shared.Packets.S2C;
using JimmysUnityUtilities;
using LogicAPI.Data;
using LogicAPI.Services;
using LogicWorld.Interfaces;
@ -8,20 +8,24 @@ using LogicWorld.Outlines;
namespace CriticalPathAnalyzer.Client.Tool {
public class PathHighLighter {
private static List<ClusterDetails> _clusters;
private static readonly OutlineData Color = new OutlineData(new Color24(0xff0000));
private static List<ClusterDetails> _clusters = new List<ClusterDetails>();
private static List<WireAddress> _highlightedWires = new List<WireAddress>();
public static void HighlightWires(AnalyzePathResponse response) {
_clusters = response.SelectedClusters;
IWorldData world = Instances.MainWorld.Data;
foreach (ClusterDetails clusterDetails in _clusters) {
foreach (ComponentAddress address in clusterDetails.ConnectingComponents) {
if (!world.Contains(address)) {
continue;
}
Outliner.Outline(address, WireTracerColors.primaryConnected);
Outliner.Outline(address, Color);
}
foreach (ComponentAddress address in clusterDetails.LinkingComponents) {
@ -29,23 +33,16 @@ namespace CriticalPathAnalyzer.Client.Tool {
continue;
}
Outliner.Outline(address, WireTracerColors.linking);
Outliner.Outline(address, Color);
}
clusterDetails.HighlightedWires = new List<WireAddress>();
clusterDetails.HighlightedOutputWires = new List<WireAddress>();
foreach (PegAddress pegAddress in clusterDetails.Pegs) {
if (!world.Contains(pegAddress.ComponentAddress)) {
CriticalPathAnalyzerClient.LoggerInstance.Warn("Peg's component doesn't exist in world");
continue;
}
if (!pegAddress.IsInputAddress()) {
Outliner.Outline(pegAddress, WireTracerColors.primaryOutput);
continue;
}
Outliner.Outline(pegAddress, WireTracerColors.primaryNormal);
Outliner.Outline(pegAddress, Color);
HashSet<WireAddress> wires = Instances.MainWorld.Data.LookupPegWires(pegAddress);
if (wires == null) {
@ -60,30 +57,29 @@ namespace CriticalPathAnalyzer.Client.Tool {
// We do not collect wires from output pegs. So if the first is an output peg, the other side must be an input -> collect.
if (wire.Point1 == pegAddress || !wire.Point1.IsInputAddress()) {
if (wire.Point1.IsInputAddress() && wire.Point2.IsInputAddress()) {
clusterDetails.HighlightedWires.Add(wireAddress);
} else {
clusterDetails.HighlightedOutputWires.Add(wireAddress);
_highlightedWires.Add(wireAddress);
Outliner.Outline(wireAddress, Color);
}
}
}
}
foreach (WireAddress address in clusterDetails.HighlightedWires) {
Outliner.Outline(address, WireTracerColors.primaryNormal);
}
foreach (WireAddress address in clusterDetails.HighlightedOutputWires) {
Outliner.Outline(address, WireTracerColors.primaryOutput);
}
}
}
public static void RemoveHighLighting() {
if (_clusters == null) return;
if (_clusters == null) {
CriticalPathAnalyzerClient.LoggerInstance.Warn("Ignoring remove highlighting, clusters is null");
return;
}
foreach (ClusterDetails cluster in _clusters) {
UnhighlightCluster(cluster);
}
foreach (WireAddress wireAddress in _highlightedWires) {
Outliner.RemoveOutline(wireAddress);
}
_clusters = null;
_highlightedWires.Clear();
}
private static void UnhighlightCluster(ClusterDetails cluster) {
@ -98,14 +94,6 @@ namespace CriticalPathAnalyzer.Client.Tool {
foreach (ComponentAddress address in cluster.LinkingComponents) {
Outliner.RemoveOutline(address);
}
foreach (WireAddress address in cluster.HighlightedWires) {
Outliner.RemoveOutline(address);
}
foreach (WireAddress address in cluster.HighlightedOutputWires) {
Outliner.RemoveOutline(address);
}
}
}
}

@ -1,34 +0,0 @@
using JimmysUnityUtilities;
using LogicWorld.Outlines;
namespace CriticalPathAnalyzer.client.tool
{
public static class WireTracerColors
{
//All clusters:
//Linking color is the intersection between clusters, it does not make sense to have this once per cluster type.
// The only change that could be done is to give linking separators between two non-primary clusters a different color.
// That is currently not supported nor detected.
public static readonly OutlineData linking = new OutlineData(new Color24(200, 200, 200));
//Primary cluster:
public static readonly OutlineData primaryNormal = new OutlineData(new Color24( 50, 255, 50));
public static readonly OutlineData primaryConnected = new OutlineData(new Color24( 20, 150, 20));
public static readonly OutlineData primaryOutput = new OutlineData(new Color24( 50, 50, 255));
//Sourcing cluster:
public static readonly OutlineData sourcingNormal = new OutlineData(new Color24(255, 50, 255));
public static readonly OutlineData sourcingConnected = new OutlineData(new Color24(150, 20, 150));
public static readonly OutlineData sourcingOutput = new OutlineData(new Color24( 80, 0, 255));
//Connected cluster:
public static readonly OutlineData connectedNormal = new OutlineData(new Color24(255, 255, 50));
public static readonly OutlineData connectedConnected = new OutlineData(new Color24(150, 150, 20));
public static readonly OutlineData connectedOutput = new OutlineData(new Color24( 80, 80, 255));
//Draining cluster:
public static readonly OutlineData drainingNormal = new OutlineData(new Color24( 50, 255, 255));
public static readonly OutlineData drainingConnected = new OutlineData(new Color24( 20, 150, 150));
public static readonly OutlineData drainingOutput = new OutlineData(new Color24( 0, 50, 150));
}
}

@ -21,12 +21,5 @@ namespace CriticalPathAnalyzer.Shared.Packets.S2C {
public List<ComponentAddress> ConnectingComponents;
[Key(2)]
public List<ComponentAddress> LinkingComponents;
// The following two entries are used on the client to temporary store wires until their outline is being removed again.
// This information is just not collected on the server, hence the client collects them.
[IgnoreMember]
public List<WireAddress> HighlightedWires;
[IgnoreMember]
public List<WireAddress> HighlightedOutputWires;
}
}
Loading…
Cancel
Save