74 lines
1.8 KiB
C#
74 lines
1.8 KiB
C#
using Enigmos.Modules.ProgrammableModules;
|
|
using Godot;
|
|
using Nocturnis;
|
|
using Nocturnis.Enigmos.ModuleManuals;
|
|
using Nocturnis.Enigmos.Modules;
|
|
using Nocturnis.Enigmos.Ports;
|
|
|
|
namespace Enigmos.Manual;
|
|
|
|
public abstract partial class PortMaintenanceTab : Panel, IModuleManualTab, ISceneConcept
|
|
{
|
|
private bool InitFlag { get; set; }
|
|
|
|
public void Init(IBaseModule module)
|
|
{
|
|
Module = module;
|
|
InitFlag = true;
|
|
}
|
|
|
|
public string FullName() => "Maintenance";
|
|
|
|
protected abstract PortFixer PortFixerInstantiate();
|
|
|
|
|
|
/// <summary>
|
|
/// Should Be Assigned Before This Tab Been Added As Child To Tab Container
|
|
/// </summary>
|
|
public IBaseModule? Module { get; set; }
|
|
private VBoxContainer? Ports { get; set; }
|
|
public override void _Ready()
|
|
{
|
|
if (!InitFlag)
|
|
throw new Exception("TODO - NEED INIT");
|
|
Ports = GetNode<VBoxContainer>("ScrolledItems/Ports");
|
|
foreach (IBasePort port in Module!.Ports)
|
|
{
|
|
PortFixer fixer = PortFixerInstantiate();
|
|
fixer.Init(port);
|
|
Ports.AddChild(fixer);
|
|
}
|
|
|
|
if (Module is ProgrammableModule programmableModule)
|
|
{
|
|
HashSet<string> used = new HashSet<string>();
|
|
foreach (IBasePort port in programmableModule.Ports)
|
|
{
|
|
int i = 0;
|
|
while (used.Contains("Exterior" + port.Name + $"#{i}"))
|
|
i++;
|
|
used.Add("Exterior" + port.Name + $"#{i}");
|
|
port.Name = "Exterior" + port.Name + $"#{i}";
|
|
PortFixer fixer = PortFixerInstantiate();
|
|
fixer.Init(port);
|
|
Ports.AddChild(fixer);
|
|
}
|
|
foreach (IBasePort port in programmableModule.Board!.OnBoardPorts)
|
|
{
|
|
string baseName = port.Name.ToString().Replace("Empty", "Interior");
|
|
int i = 0;
|
|
while (used.Contains(baseName + $"#{i}"))
|
|
i++;
|
|
used.Add(baseName + $"#{i}");
|
|
port.Name = baseName + $"#{i}";
|
|
PortFixer fixer = PortFixerInstantiate();
|
|
fixer.Init(port);
|
|
Ports.AddChild(fixer);
|
|
}
|
|
}
|
|
|
|
Name = "Main";
|
|
base._Ready();
|
|
}
|
|
}
|