mirror of
https://github.com/BotChain-Robots/ui.git
synced 2026-07-08 15:07:22 +02:00
Fix topology detection with MMMM hub
This commit is contained in:
@@ -91,23 +91,48 @@ public class TopologyBuilder : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
int connectionCount = config.ConnectionsLength;
|
int connectionCount = config.ConnectionsLength;
|
||||||
|
|
||||||
|
var rawConns = new List<Frontend.ModuleConnection>();
|
||||||
for (int i = 0; i < connectionCount; i++)
|
for (int i = 0; i < connectionCount; i++)
|
||||||
{
|
{
|
||||||
var n_connection = config.Connections(i);
|
var nc = config.Connections(i);
|
||||||
if (n_connection != null)
|
if (nc != null) rawConns.Add(nc.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
var processedPairs = new HashSet<string>();
|
||||||
|
|
||||||
|
// Pass 0: add connections where 'from' is a hub/splitter (named output ports).
|
||||||
|
// Pass 1: add any remaining connections not yet covered.
|
||||||
|
for (int pass = 0; pass < 2; pass++)
|
||||||
{
|
{
|
||||||
var connection = n_connection.Value;
|
foreach (var connection in rawConns)
|
||||||
if (connection.FromSocket == 0) { continue; }
|
{
|
||||||
|
if (!idToType.ContainsKey(connection.FromModuleId) || !idToType.ContainsKey(connection.ToModuleId))
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"[TopologyBuilder] Skipping connection with unknown module id: {connection.FromModuleId} -> {connection.ToModuleId}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fromIsHub =
|
||||||
|
idToType[connection.FromModuleId] == ModuleType.SPLITTER ||
|
||||||
|
idToType[connection.FromModuleId] == ModuleType.SPLITTER_2 ||
|
||||||
|
idToType[connection.FromModuleId] == ModuleType.SPLITTER_3 ||
|
||||||
|
idToType[connection.FromModuleId] == ModuleType.SPLITTER_4;
|
||||||
|
|
||||||
|
if (pass == 0 && !fromIsHub) continue;
|
||||||
|
|
||||||
|
byte lo = Math.Min(connection.FromModuleId, connection.ToModuleId);
|
||||||
|
byte hi = Math.Max(connection.FromModuleId, connection.ToModuleId);
|
||||||
|
string pairKey = lo + "-" + hi;
|
||||||
|
if (processedPairs.Contains(pairKey)) continue;
|
||||||
|
processedPairs.Add(pairKey);
|
||||||
|
|
||||||
Debug.Log("Connection: from (socket): " + connection.FromModuleId + " (" + connection.FromSocket + ")" + " to " + connection.ToModuleId + " (" + connection.ToSocket + ")" + " orientation: " + connection.Orientation);
|
Debug.Log("Connection: from (socket): " + connection.FromModuleId + " (" + connection.FromSocket + ")" + " to " + connection.ToModuleId + " (" + connection.ToSocket + ")" + " orientation: " + connection.Orientation);
|
||||||
graph.Connections.Add(new Connection
|
graph.Connections.Add(new Connection
|
||||||
{
|
{
|
||||||
FromModuleId = connection.FromModuleId,
|
FromModuleId = connection.FromModuleId,
|
||||||
FromSocket =
|
FromSocket = fromIsHub
|
||||||
idToType[connection.FromModuleId] == ModuleType.SPLITTER ||
|
? "MaleSocket" + (connection.FromSocket + 1).ToString()
|
||||||
idToType[connection.FromModuleId] == ModuleType.SPLITTER_2 ||
|
|
||||||
idToType[connection.FromModuleId] == ModuleType.SPLITTER_3 ||
|
|
||||||
idToType[connection.FromModuleId] == ModuleType.SPLITTER_4
|
|
||||||
? "MaleSocket" + (connection.FromSocket == 0 ? "" : connection.FromSocket)
|
|
||||||
: "MaleSocket",
|
: "MaleSocket",
|
||||||
ToModuleId = connection.ToModuleId,
|
ToModuleId = connection.ToModuleId,
|
||||||
ToSocket = "FemaleSocket",
|
ToSocket = "FemaleSocket",
|
||||||
@@ -191,22 +216,46 @@ public class TopologyBuilder : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
int connectionCount = config.ConnectionsLength;
|
int connectionCount = config.ConnectionsLength;
|
||||||
|
var rawConns = new List<Frontend.ModuleConnection>();
|
||||||
for (int i = 0; i < connectionCount; i++)
|
for (int i = 0; i < connectionCount; i++)
|
||||||
{
|
{
|
||||||
var n_connection = config.Connections(i);
|
var nc = config.Connections(i);
|
||||||
if (n_connection != null)
|
if (nc != null) rawConns.Add(nc.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
var processedPairs = new HashSet<string>();
|
||||||
|
|
||||||
|
// Pass 0: add connections where 'from' is a hub/splitter (named output ports).
|
||||||
|
// Pass 1: add any remaining connections not yet covered.
|
||||||
|
for (int pass = 0; pass < 2; pass++)
|
||||||
{
|
{
|
||||||
var connection = n_connection.Value;
|
foreach (var connection in rawConns)
|
||||||
if (connection.FromSocket == 0) continue;
|
|
||||||
graph.Connections.Add(new Connection
|
|
||||||
{
|
{
|
||||||
FromModuleId = connection.FromModuleId,
|
if (!idToType.ContainsKey(connection.FromModuleId) || !idToType.ContainsKey(connection.ToModuleId))
|
||||||
FromSocket =
|
{
|
||||||
|
Debug.LogWarning($"[TopologyBuilder] Skipping connection with unknown module id: {connection.FromModuleId} -> {connection.ToModuleId}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fromIsHub =
|
||||||
idToType[connection.FromModuleId] == ModuleType.SPLITTER ||
|
idToType[connection.FromModuleId] == ModuleType.SPLITTER ||
|
||||||
idToType[connection.FromModuleId] == ModuleType.SPLITTER_2 ||
|
idToType[connection.FromModuleId] == ModuleType.SPLITTER_2 ||
|
||||||
idToType[connection.FromModuleId] == ModuleType.SPLITTER_3 ||
|
idToType[connection.FromModuleId] == ModuleType.SPLITTER_3 ||
|
||||||
idToType[connection.FromModuleId] == ModuleType.SPLITTER_4
|
idToType[connection.FromModuleId] == ModuleType.SPLITTER_4;
|
||||||
? "MaleSocket" + (connection.FromSocket == 0 ? "" : connection.FromSocket)
|
|
||||||
|
if (pass == 0 && !fromIsHub) continue;
|
||||||
|
|
||||||
|
byte lo = Math.Min(connection.FromModuleId, connection.ToModuleId);
|
||||||
|
byte hi = Math.Max(connection.FromModuleId, connection.ToModuleId);
|
||||||
|
string pairKey = lo + "-" + hi;
|
||||||
|
if (processedPairs.Contains(pairKey)) continue;
|
||||||
|
processedPairs.Add(pairKey);
|
||||||
|
|
||||||
|
graph.Connections.Add(new Connection
|
||||||
|
{
|
||||||
|
FromModuleId = connection.FromModuleId,
|
||||||
|
FromSocket = fromIsHub
|
||||||
|
? "MaleSocket" + (connection.FromSocket + 1).ToString()
|
||||||
: "MaleSocket",
|
: "MaleSocket",
|
||||||
ToModuleId = connection.ToModuleId,
|
ToModuleId = connection.ToModuleId,
|
||||||
ToSocket = "FemaleSocket",
|
ToSocket = "FemaleSocket",
|
||||||
|
|||||||
Reference in New Issue
Block a user