< Summary

Class:SwarmStatusDialog
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/UI/Dialogs/SwarmStatusDialog.cs
Covered lines:0
Uncovered lines:128
Coverable lines:128
Total lines:159
Line coverage:0% (0 of 128)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:16
Method coverage:0% (0 of 16)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SwarmStatusDialog()0%2100%
Awake()0%2100%
Start()0%2100%
InitDialog()0%30500%
RedrawFullDialog()0%2100%
CreateParentEntries()0%2100%
OnClickSwarmEntry(...)0%6200%
CreateInterceptorSwarmEntries(...)0%12300%
CreateSubmunitionsSwarmEntries(...)0%12300%
CreateThreatSwarmEntries(...)0%12300%
RegisterInterceptorSwarmChanged(...)0%6200%
RegisterSubmunitionsSwarmChanged(...)0%6200%
RegisterThreatSwarmChanged(...)0%6200%
RegisterSimulationEnded()0%6200%
OnEnable()0%6200%
Update()0%2100%

File(s)

/github/workspace/Assets/Scripts/UI/Dialogs/SwarmStatusDialog.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using UnityEngine;
 4using System.Linq;
 5using UnityEngine.AI;
 6public class SwarmStatusDialog : UIDialog {
 07  private List<List<(Agent, bool)>> interceptorSwarms = new List<List<(Agent, bool)>>();
 08  private List<List<(Agent, bool)>> submunitionsSwarms = new List<List<(Agent, bool)>>();
 09  private List<List<(Agent, bool)>> threatsSwarms = new List<List<(Agent, bool)>>();
 010  protected void Awake() {}
 11
 012  public override void Start() {
 013    base.Start();
 14
 015    InitDialog();
 016  }
 17
 018  public void InitDialog() {
 019    SimManager.Instance.OnInterceptorSwarmChanged += RegisterInterceptorSwarmChanged;
 020    SimManager.Instance.OnSubmunitionsSwarmChanged += RegisterSubmunitionsSwarmChanged;
 021    SimManager.Instance.OnThreatSwarmChanged += RegisterThreatSwarmChanged;
 022    SimManager.Instance.OnSimulationEnded += RegisterSimulationEnded;
 023    RedrawFullDialog();
 24
 025    AddDialogTab("All", () => {});
 026    AddDialogTab("Interceptors", () => {});
 027    AddDialogTab("Submunitions", () => {});
 028    AddDialogTab("Threats", () => {});
 029  }
 30
 031  private void RedrawFullDialog() {
 032    ClearDialogEntries();
 033    List<UISelectableEntry> parents = CreateParentEntries();
 034    List<UISelectableEntry> interceptorChildren = CreateInterceptorSwarmEntries(interceptorSwarms);
 035    List<UISelectableEntry> submunitionsChildren =
 36        CreateSubmunitionsSwarmEntries(submunitionsSwarms);
 037    List<UISelectableEntry> threatsChildren = CreateThreatSwarmEntries(threatsSwarms);
 038    parents[1].SetChildEntries(interceptorChildren);
 039    parents[2].SetChildEntries(submunitionsChildren);
 040    parents[3].SetChildEntries(threatsChildren);
 041    SetDialogEntries(parents);
 042  }
 43
 044  private List<UISelectableEntry> CreateParentEntries() {
 045    List<UISelectableEntry> children = new List<UISelectableEntry>();
 46
 047    UISelectableEntry masterTitleBar = CreateSelectableEntry();
 048    masterTitleBar.SetTextContent(new List<string>(new string[] { "Swarm Name", "Active Agents" }));
 049    masterTitleBar.SetIsSelectable(false);
 50
 051    UISelectableEntry interceptorParentEntry = CreateSelectableEntry();
 052    interceptorParentEntry.SetTextContent(new List<string>(new string[] { "Interceptor Swarms" }));
 053    interceptorParentEntry.SetIsSelectable(false);
 54
 055    UISelectableEntry submunitionsParentEntry = CreateSelectableEntry();
 056    submunitionsParentEntry.SetTextContent(
 57        new List<string>(new string[] { "Submunitions Swarms" }));
 058    submunitionsParentEntry.SetIsSelectable(false);
 59
 060    UISelectableEntry threatsParentEntry = CreateSelectableEntry();
 061    threatsParentEntry.SetTextContent(new List<string>(new string[] { "Threat Swarms" }));
 062    threatsParentEntry.SetIsSelectable(false);
 63
 064    children.Add(masterTitleBar);
 065    children.Add(interceptorParentEntry);
 066    children.Add(submunitionsParentEntry);
 067    children.Add(threatsParentEntry);
 068    return children;
 069  }
 70
 071  private void OnClickSwarmEntry(object swarm) {
 072    List<(Agent, bool)> swarmTuple = (List<(Agent, bool)>)swarm;
 073    List<Agent> swarmAgents = swarmTuple.ConvertAll(agent => agent.Item1);
 074    CameraController.Instance.SnapToSwarm(swarmAgents, false);
 075  }
 76
 077  private List<UISelectableEntry> CreateInterceptorSwarmEntries(List<List<(Agent, bool)>> swarms) {
 078    List<UISelectableEntry> children = new List<UISelectableEntry>();
 079    foreach (var swarm in swarms) {
 080      string swarmTitle = SimManager.Instance.GenerateInterceptorSwarmTitle(swarm);
 081      int activeCount = swarm.Count(agent => agent.Item2);
 082      UISelectableEntry entry = CreateSelectableEntry();
 083      entry.SetTextContent(new List<string>(new string[] { swarmTitle, activeCount.ToString() }));
 084      entry.SetParent(this);
 085      entry.SetClickCallback(OnClickSwarmEntry, swarm);
 086      children.Add(entry);
 087    }
 088    return children;
 089  }
 90
 091  private List<UISelectableEntry> CreateSubmunitionsSwarmEntries(List<List<(Agent, bool)>> swarms) {
 092    List<UISelectableEntry> children = new List<UISelectableEntry>();
 093    foreach (var swarm in swarms) {
 094      int interceptorSwarmIndex =
 95          SimManager.Instance.LookupSubmunitionSwarmIndexInInterceptorSwarm(swarm);
 096      string swarmTitle = SimManager.Instance.GenerateSubmunitionsSwarmTitle(swarm);
 097      int activeCount = swarm.Count(agent => agent.Item2);
 098      UISelectableEntry entry = CreateSelectableEntry();
 099      entry.SetTextContent(new List<string>(new string[] { swarmTitle, activeCount.ToString() }));
 0100      entry.SetParent(this);
 0101      entry.SetClickCallback(OnClickSwarmEntry, swarm);
 0102      children.Add(entry);
 0103    }
 0104    return children;
 0105  }
 106
 0107  private List<UISelectableEntry> CreateThreatSwarmEntries(List<List<(Agent, bool)>> swarms) {
 0108    List<UISelectableEntry> children = new List<UISelectableEntry>();
 0109    foreach (var swarm in swarms) {
 0110      string swarmTitle = SimManager.Instance.GenerateThreatSwarmTitle(swarm);
 0111      int activeCount = swarm.Count(agent => agent.Item2);
 0112      UISelectableEntry entry = CreateSelectableEntry();
 0113      entry.SetTextContent(new List<string>(new string[] { swarmTitle, activeCount.ToString() }));
 0114      entry.SetParent(this);
 0115      entry.SetClickCallback(OnClickSwarmEntry, swarm);
 0116      children.Add(entry);
 0117    }
 0118    return children;
 0119  }
 120
 0121  private void RegisterInterceptorSwarmChanged(List<List<(Agent, bool)>> swarms) {
 0122    if (isActiveAndEnabled) {
 0123      interceptorSwarms = swarms;
 0124      RedrawFullDialog();
 0125    }
 0126  }
 127
 0128  private void RegisterSubmunitionsSwarmChanged(List<List<(Agent, bool)>> swarms) {
 0129    if (isActiveAndEnabled) {
 0130      submunitionsSwarms = swarms;
 0131      RedrawFullDialog();
 0132    }
 0133  }
 134
 0135  private void RegisterThreatSwarmChanged(List<List<(Agent, bool)>> swarms) {
 0136    if (isActiveAndEnabled) {
 0137      threatsSwarms = swarms;
 0138      RedrawFullDialog();
 0139    }
 0140  }
 141
 0142  private void RegisterSimulationEnded() {
 0143    if (isActiveAndEnabled) {
 0144      ClearDialogEntries();
 0145    }
 0146  }
 147
 0148  protected override void OnEnable() {
 0149    base.OnEnable();
 0150    if (SimManager.Instance != null) {
 0151      interceptorSwarms = SimManager.Instance.GetInterceptorSwarms();
 0152      submunitionsSwarms = SimManager.Instance.GetSubmunitionsSwarms();
 0153      threatsSwarms = SimManager.Instance.GetThreatSwarms();
 0154      RedrawFullDialog();
 0155    }
 0156  }
 157
 0158  void Update() {}
 159}