Files
Enigmos/Manual/PortMaintenanceTab.cs
2024-07-03 12:20:08 +08:00

71 lines
2.0 KiB
C#

using Enigmos.Modules.ProgrammableModules;
using Godot;
using Nocturnis.Enigmos.ModuleManuals;
using Nocturnis.Enigmos.Modules;
using Nocturnis.Enigmos.Ports;
using Nocturnis.GlobalManagement.Providers;
namespace Enigmos.Manual;
public partial class PortMaintenanceTab : Panel, IModuleManualTab
{
private bool InitFlag { get; set; }
public void Init(IBaseModule module)
{
Module = module;
InitFlag = true;
}
public string FullName() => "Maintenance";
private static readonly PackedScene PortFixerScene = GlobalProvider.SceneProvider!.AssetMapper<PortFixer>();
/// <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 = PortFixerScene.Instantiate<PortFixer>();
fixer.Init(port);
Ports.AddChild(fixer);
}
if (Module is ProgrammableModule programmableModule)
{
HashSet<string> used = new HashSet<string>();
foreach (IBasePort port in programmableModule.ExplicitPorts)
{
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 = PortFixerScene.Instantiate<PortFixer>();
fixer.Init(port);
Ports.AddChild(fixer);
}
foreach (IBasePort port in programmableModule.ImplicitPorts)
{
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 = PortFixerScene.Instantiate<PortFixer>();
fixer.Init(port);
Ports.AddChild(fixer);
}
}
Name = "Main";
base._Ready();
}
}