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 regResources; [ExportCategory("UI 绑定")] [Export] private Array progressBars; [Export] private RichTextLabel logLabel; private readonly Queue _progressQueue = new(); private ProgressBar _currentProgressBar; private void Register() { BIT4Log.Log("开始自动注册中..."); var seeds = new List(); 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(seeds.Select(x => new KeyValuePair(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; } } }