using System.Text.Json;
using XFEEDToolBox.Controls;
using XFEEDToolBox.Core.Galaxy;
using XFEEDToolBox.Core.Models;
namespace XFEEDToolBox;
public partial class App
{
private static async Task<object> RunGalaxyCurrentTradeProbeAsync(string directory)
{
static void Require(bool value,string message){if(!value)throw new InvalidOperationException(message);}
var path=GetArgument(Environment.GetCommandLineArgs(),"--galaxy-fixture")??throw new ArgumentException("--galaxy-fixture is required.");
using var document=JsonDocument.Parse(await File.ReadAllTextAsync(path));var root=document.RootElement;
var records=JsonSerializer.Deserialize<GalacticSystem[]>(root.ValueKind==JsonValueKind.Array?root:root.GetProperty("systems"),ToolboxSettings.JsonOptions)??[];
var from=records.First(s=>s.SystemAddress is >0&&s.Position.IsValid);
var to=records.First(s=>s.SystemAddress is >0&&s.SystemAddress!=from.SystemAddress&&s.Position.IsValid&&s.Position.DistanceTo(from.Position) is >3 and <20);
// Only source-cache amounts/time/category selection are synthetic. Both
// exact addresses and3D coordinates remain recorded catalogue entries.
var syntheticFlow=new GalaxyCurrentTradeFlow(from.SystemAddress!.Value,to.SystemAddress!.Value,1,"Gold",.6f,.2f,1000);
var snapshot=new GalaxyCurrentTradeFlowsSnapshot(true,1000,100,50,7,[syntheticFlow],0);
var routes=GalaxyCurrentTradeRoutes.Select(snapshot,GalaxyTradeFlowSource.Npc,null);
var systems=new[]{from,to}.ToDictionary(s=>s.SystemAddress!.Value);
var projection=GalaxyCurrentTradeRoutes.Project(routes,systems);
Require(projection.Flows.Count==1,"Actual endpoint projection failed.");
var previous=MainWindow.Content;var host=new Grid();var map=new GalaxyMapView();host.Children.Add(map);MainWindow.Content=host;
try
{
map.Systems=[from,to];map.CurrentTradeFlows=projection.Flows;
map.Filter=GalaxyMapFilter.Default with{Mode=GalaxyMapMode.Map,Category=GalaxyFilterCategory.None,ShowCurrentTradeFlows=false,ShowHistoricalTradeFlows=false,
ShowBackground=false,ShowGrid=false,ShowLabels=true,ShowMarkers=false,ShowConstellations=false,
ShowRegionNames=false,ShowNebulaNames=false,ShowGalacticZonesPlane=false,ShowGalacticZoneNames=false};
await Task.Delay(180);
map.Centre=new Coordinates((from.Position.X+to.Position.X)*.5,(from.Position.Y+to.Position.Y)*.5,(from.Position.Z+to.Position.Z)*.5);
map.ResetCamera();map.Zoom(4);map.AdvanceCameraMotionForProbe(256);map.RenderNowForProbe();
var stars=map.VisibleStars;var disabled=map.CapturePixelsForProbe();
Require(stars==2&&map.SubmittedCurrentTradeRoutesForProbe==0&&!map.HasOriginalCurrentTradeAnimationForProbe,"Disabled current layer changed stars or retained a route.");
map.Filter=map.Filter with{ShowCurrentTradeFlows=true};map.RenderNowForProbe();
Require(map.OriginalCurrentTradeGeometryRestoredForProbe&&map.SubmittedCurrentTradeRoutesForProbe==1&&map.SubmittedCurrentTradeHotspotsForProbe is >=2 and <=8,
"Original route/hotspot instances did not reach theGPU.");
var routeCount=map.SubmittedCurrentTradeRoutesForProbe;var hotspotCount=map.SubmittedCurrentTradeHotspotsForProbe;
var first=map.CapturePixelsForProbe();var firstFrame=map.FrameCount;await Task.Delay(600);var later=map.CapturePixelsForProbe();var laterFrame=map.FrameCount;
Require(map.HasOriginalCurrentTradeAnimationForProbe&&laterFrame>firstFrame&&!first.Pixels.SequenceEqual(later.Pixels),"Current trade animation stopped at its first frame.");
Require(map.VisibleStars==stars&&!disabled.Pixels.SequenceEqual(later.Pixels),"Current route activation changed stars or produced no pixels.");
using(await map.FreezeForXamlProbeAsync())await CaptureRefinementElementAsync(host,Path.Combine(directory,"synthetic-current-trade-amounts-real-endpoints.png"));
map.Filter=map.Filter with{ShowCurrentTradeFlows=false};map.RenderNowForProbe();await Task.Delay(150);var idle=map.FrameCount;await Task.Delay(250);
Require(map.SubmittedCurrentTradeRoutesForProbe==0&&map.SubmittedCurrentTradeHotspotsForProbe==0&&!map.HasOriginalCurrentTradeAnimationForProbe&&map.FrameCount==idle,
"Disabled current layer left instances or an idle rendering loop.");
// No invented endpoint: unresolved real address remains pending in
// the projection and cannot reach the original geometry buffer.
var missing=GalaxyCurrentTradeRoutes.Project(routes,new Dictionary<long,GalacticSystem>{{from.SystemAddress.Value,from}});
map.Systems=[from];map.CurrentTradeFlows=missing.Flows;map.Filter=map.Filter with{ShowCurrentTradeFlows=true};map.RenderNowForProbe();
Require(missing.MissingSystemAddresses.SequenceEqual(new[]{to.SystemAddress.Value})&&map.SubmittedCurrentTradeRoutesForProbe==0&&map.SubmittedCurrentTradeHotspotsForProbe==0&&!map.HasOriginalCurrentTradeAnimationForProbe,
"Unresolved actual endpoint produced a substitute trade route.");
var result=new{addressesAndCoordinatesFromRecordedCatalogue=true,amountsAndClockSynthetic=true,sourceClock=1000,sourceTimestamp=1000,
sourceAmount=.6,from=from.Name,to=to.Name,routeCount,hotspotCount,starsBeforeAndAfter=stars,continuousFrameDifference=laterFrame-firstFrame,
activationChangedPixels=true,animationChangedPixels=true,disabledClearsBothBuffers=true,disabledStopsIdleFrames=true,missingEndpointHidden=true,
original44ByteInstancesAndSrgbAtlases=true,fullOriginalRendering=false,gameAccess=false};
await File.WriteAllTextAsync(Path.Combine(directory,"current-trade-probe.json"),JsonSerializer.Serialize(result,new JsonSerializerOptions{WriteIndented=true}));return result;
}
finally{map.SuspendPage();MainWindow.Content=previous;}
}
}
using System.Text.Json;
using XFEEDToolBox.Controls;
using XFEEDToolBox.Core.Galaxy;
using XFEEDToolBox.Core.Models;
namespace XFEEDToolBox;
public partial class App
{
private static async Task<object> RunGalaxyCurrentTradeProbeAsync(string directory)
{
static void Require(bool value,string message){if(!value)throw new InvalidOperationException(message);}
var path=GetArgument(Environment.GetCommandLineArgs(),"--galaxy-fixture")??throw new ArgumentException("--galaxy-fixture is required.");
using var document=JsonDocument.Parse(await File.ReadAllTextAsync(path));var root=document.RootElement;
var records=JsonSerializer.Deserialize<GalacticSystem[]>(root.ValueKind==JsonValueKind.Array?root:root.GetProperty("systems"),ToolboxSettings.JsonOptions)??[];
var from=records.First(s=>s.SystemAddress is >0&&s.Position.IsValid);
var to=records.First(s=>s.SystemAddress is >0&&s.SystemAddress!=from.SystemAddress&&s.Position.IsValid&&s.Position.DistanceTo(from.Position) is >3 and <20);
// Only source-cache amounts/time/category selection are synthetic. Both
// exact addresses and3D coordinates remain recorded catalogue entries.
var syntheticFlow=new GalaxyCurrentTradeFlow(from.SystemAddress!.Value,to.SystemAddress!.Value,1,"Gold",.6f,.2f,1000);
var snapshot=new GalaxyCurrentTradeFlowsSnapshot(true,1000,100,50,7,[syntheticFlow],0);
var routes=GalaxyCurrentTradeRoutes.Select(snapshot,GalaxyTradeFlowSource.Npc,null);
var systems=new[]{from,to}.ToDictionary(s=>s.SystemAddress!.Value);
var projection=GalaxyCurrentTradeRoutes.Project(routes,systems);
Require(projection.Flows.Count==1,"Actual endpoint projection failed.");
var previous=MainWindow.Content;var host=new Grid();var map=new GalaxyMapView();host.Children.Add(map);MainWindow.Content=host;
try
{
map.Systems=[from,to];map.CurrentTradeFlows=projection.Flows;
map.Filter=GalaxyMapFilter.Default with{Mode=GalaxyMapMode.Map,Category=GalaxyFilterCategory.None,ShowCurrentTradeFlows=false,ShowHistoricalTradeFlows=false,
ShowBackground=false,ShowGrid=false,ShowLabels=true,ShowMarkers=false,ShowConstellations=false,
ShowRegionNames=false,ShowNebulaNames=false,ShowGalacticZonesPlane=false,ShowGalacticZoneNames=false};
await Task.Delay(180);
map.Centre=new Coordinates((from.Position.X+to.Position.X)*.5,(from.Position.Y+to.Position.Y)*.5,(from.Position.Z+to.Position.Z)*.5);
map.ResetCamera();map.Zoom(4);map.AdvanceCameraMotionForProbe(256);map.RenderNowForProbe();
var stars=map.VisibleStars;var disabled=map.CapturePixelsForProbe();
Require(stars==2&&map.SubmittedCurrentTradeRoutesForProbe==0&&!map.HasOriginalCurrentTradeAnimationForProbe,"Disabled current layer changed stars or retained a route.");
map.Filter=map.Filter with{ShowCurrentTradeFlows=true};map.RenderNowForProbe();
Require(map.OriginalCurrentTradeGeometryRestoredForProbe&&map.SubmittedCurrentTradeRoutesForProbe==1&&map.SubmittedCurrentTradeHotspotsForProbe is >=2 and <=8,
"Original route/hotspot instances did not reach theGPU.");
var routeCount=map.SubmittedCurrentTradeRoutesForProbe;var hotspotCount=map.SubmittedCurrentTradeHotspotsForProbe;
var first=map.CapturePixelsForProbe();var firstFrame=map.FrameCount;await Task.Delay(600);var later=map.CapturePixelsForProbe();var laterFrame=map.FrameCount;
Require(map.HasOriginalCurrentTradeAnimationForProbe&&laterFrame>firstFrame&&!first.Pixels.SequenceEqual(later.Pixels),"Current trade animation stopped at its first frame.");
Require(map.VisibleStars==stars&&!disabled.Pixels.SequenceEqual(later.Pixels),"Current route activation changed stars or produced no pixels.");
using(await map.FreezeForXamlProbeAsync())await CaptureRefinementElementAsync(host,Path.Combine(directory,"synthetic-current-trade-amounts-real-endpoints.png"));
map.Filter=map.Filter with{ShowCurrentTradeFlows=false};map.RenderNowForProbe();await Task.Delay(150);var idle=map.FrameCount;await Task.Delay(250);
Require(map.SubmittedCurrentTradeRoutesForProbe==0&&map.SubmittedCurrentTradeHotspotsForProbe==0&&!map.HasOriginalCurrentTradeAnimationForProbe&&map.FrameCount==idle,
"Disabled current layer left instances or an idle rendering loop.");
// No invented endpoint: unresolved real address remains pending in
// the projection and cannot reach the original geometry buffer.
var missing=GalaxyCurrentTradeRoutes.Project(routes,new Dictionary<long,GalacticSystem>{{from.SystemAddress.Value,from}});
map.Systems=[from];map.CurrentTradeFlows=missing.Flows;map.Filter=map.Filter with{ShowCurrentTradeFlows=true};map.RenderNowForProbe();
Require(missing.MissingSystemAddresses.SequenceEqual(new[]{to.SystemAddress.Value})&&map.SubmittedCurrentTradeRoutesForProbe==0&&map.SubmittedCurrentTradeHotspotsForProbe==0&&!map.HasOriginalCurrentTradeAnimationForProbe,
"Unresolved actual endpoint produced a substitute trade route.");
var result=new{addressesAndCoordinatesFromRecordedCatalogue=true,amountsAndClockSynthetic=true,sourceClock=1000,sourceTimestamp=1000,
sourceAmount=.6,from=from.Name,to=to.Name,routeCount,hotspotCount,starsBeforeAndAfter=stars,continuousFrameDifference=laterFrame-firstFrame,
activationChangedPixels=true,animationChangedPixels=true,disabledClearsBothBuffers=true,disabledStopsIdleFrames=true,missingEndpointHidden=true,
original44ByteInstancesAndSrgbAtlases=true,fullOriginalRendering=false,gameAccess=false};
await File.WriteAllTextAsync(Path.Combine(directory,"current-trade-probe.json"),JsonSerializer.Serialize(result,new JsonSerializerOptions{WriteIndented=true}));return result;
}
finally{map.SuspendPage();MainWindow.Content=previous;}
}
}