iFactory.Godot/Mods/工业数据采集与分析应用分享/Scripts/IDIS_AutoRegister.cs

87 lines
2.1 KiB
C#
Raw Normal View History

2023-09-15 23:02:46 +08:00
#if deprecated
2023-07-17 04:10:14 +08:00
using Godot;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BITFactory;
using BITKit;
using Godot.Collections;
namespace BITFactory;
public partial class IDIS_AutoRegister : Node
{
[Export] private Array<IDIS_AutoRegResource> regResources;
[ExportCategory("UI 绑定")]
[Export] private Array<ProgressBar> progressBars;
[Export] private RichTextLabel logLabel;
private readonly Queue<ProgressBar> _progressQueue = new();
private ProgressBar _currentProgressBar;
private void Register()
{
BIT4Log.Log<IDIS_AutoRegister>("开始自动注册中...");
var seeds = new List<string>();
foreach (var x in regResources)
{
seeds.Add(x.HandleSeed);
if (string.IsNullOrEmpty(x.RefHandleSeed) is false)
{
seeds.Add(x.RefHandleSeed);
}
}
seeds = seeds.Distinct().ToList();
var handles =
new System.Collections.Generic.Dictionary<string, string>(seeds.Select(x =>
new KeyValuePair<string, string>(x, IDIS_Service.GenerateHandle())));
try
{
foreach (var x in regResources)
{
var handle = handles[x.HandleSeed];
IDIS_Service.Singleton.Register(handle, x.Name, x.Format, x.Value, x.Category);
if (string.IsNullOrEmpty(x.RefHandleSeed) is false && handles.TryGetValue(x.RefHandleSeed, out var refHandle))
{
IDIS_Service.Singleton.RegisterReference(handle, refHandle);
}
logLabel.Text+=$"\n[{DateTime.Now}]{x.Name} 已注册,使用标识: {handle}";
}
}
catch (Exception e)
{
logLabel.Text += $"\n[color=red]错误:\n{e.Message}[/color]";
}
foreach (var x in progressBars)
{
x.Value = x.MinValue;
_progressQueue.Enqueue(x);
}
}
public override void _Process(double delta)
{
switch (_currentProgressBar)
{
case null when _progressQueue.Count == 0:
return;
case null:
_progressQueue.TryDequeue(out _currentProgressBar);
return;
case (var x) when x.Value >= x.MaxValue:
_progressQueue.TryDequeue(out _currentProgressBar);
return;
default:
_currentProgressBar.Value +=
Mathf.Lerp(_currentProgressBar.MinValue, _currentProgressBar.MaxValue, delta);
break;
}
}
}
2023-09-15 23:02:46 +08:00
#endif