using System.Collections.Frozen; using XFEEDToolBox.Core.Models; namespace XFEEDToolBox.Core.Galaxy; /// An actual published D50 object. MinimumExtra floors style offset1C, never its independent main size at offset0. public sealed record GalaxyOriginalPointOverride(long SystemAddress,float MinimumExtra,bool FarFade,bool Pending, Coordinates Position,string? Name,string StarClass,GalaxyOriginalStellarAppearance? OriginalAppearance) { /// No generated name or invented catalogue row is supplied for an unnamed loaded compact. public GalacticSystem? System=>Name is{Length:>0}?new(Name,Position,SystemAddress,StarClass,"游戏银河目录"){OriginalAppearance=OriginalAppearance}:null; } /// One profile request's fresh owner-thread copy. Completeness refers to the currently published tables only. public sealed class GalaxyOriginalPointOverrides { public int ProcessId {get;} public long SourceGeneration {get;} /// Capture time in the native process monotonic tick domain; never a route revision or a wall-clock time. public ulong CapturedAtTick {get;} public int? NavRouteViewMode {get;} public int? NavRouteMembershipMode=>NavRouteViewMode is{} view?view==1?1:0:null; public bool D50Complete {get;} public bool NavRouteComplete {get;} public IReadOnlyDictionary Overrides {get;} public IReadOnlySet NavRouteMembers {get;} public GalaxyOriginalPointOverrides(int processId,long sourceGeneration,ulong capturedAtTick,int? navRouteViewMode, bool d50Complete,bool navRouteComplete,IEnumerable overrides,IEnumerable navRouteMembers) { if(processId<=0||sourceGeneration<=0)throw new ArgumentOutOfRangeException(nameof(sourceGeneration)); var rows=overrides.ToArray();var members=navRouteMembers.ToArray(); static bool Address(long id)=>id>0&&id<1L<<55; if(rows.Any(r=>!Address(r.SystemAddress)||!float.IsFinite(r.MinimumExtra)||r.MinimumExtra<0||!r.Position.IsValid||r.Name is{Length:>159})|| rows.Select(r=>r.SystemAddress).Distinct().Count()!=rows.Length||members.Any(id=>!Address(id))||members.Distinct().Count()!=members.Length|| navRouteComplete&&navRouteViewMode is null)throw new ArgumentException("原星点覆写上下文无效。"); ProcessId=processId;SourceGeneration=sourceGeneration;CapturedAtTick=capturedAtTick;NavRouteViewMode=navRouteViewMode; D50Complete=d50Complete;NavRouteComplete=navRouteComplete; Overrides=rows.ToFrozenDictionary(r=>r.SystemAddress);NavRouteMembers=members.ToFrozenSet(); } public bool? Membership(long address)=>address<=0||address>=1L<<55?null:NavRouteMembers.Contains(address)?true:NavRouteComplete?false:null; public bool? OverridePresence(long address)=>address<=0||address>=1L<<55?null:Overrides.ContainsKey(address)?true:D50Complete?false:null; public bool TryGetOverride(long address,out GalaxyOriginalPointOverride? value)=>Overrides.TryGetValue(address,out value); }