XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
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> RunGalaxyCellSelectionProbeAsync(string directory,IReadOnlyList<GalacticSystem> recorded)
    {
        static void Require(bool value,string message){if(!value)throw new InvalidOperationException(message);}
        var target=recorded.First(s=>s.SystemAddress is >0&&((ulong)s.SystemAddress.Value&7)==5);
        // This origin belongs only to the pinned recorded fixture. Live plans
        // receive their actual origin from the native catalogue input profile.
        var origin=new Coordinates(49985,40985,24105);
        var cell=GalaxyCellQueryPlan.CellAddress((ulong)target.SystemAddress!.Value);
        var box=GalaxyOriginalCatalogueLod.CellBounds(cell,origin);
        var sign=target.Position.Z-box.Minimum.Z>=box.Maximum.Z-target.Position.Z?1:-1;
        var focus=new Coordinates(target.Position.X,target.Position.Y,sign>0?box.Minimum.Z+.5:box.Maximum.Z-.5);
        var previous=MainWindow.Content;var host=new Grid();var map=new GalaxyMapView();host.Children.Add(map);MainWindow.Content=host;
        try
        {
            map.Filter=GalaxyMapFilter.Default with{Mode=GalaxyMapMode.Map,Values=null,ShowBackground=false,ShowGrid=false,ShowLabels=true,
                ShowLinks=false,ShowRoute=false,ShowConstellations=false,ShowCurrentTradeFlows=false,ShowHistoricalTradeFlows=false,
                ShowRegionNames=false,ShowNebulaNames=false,ShowGalacticZonesPlane=false,ShowGalacticZoneNames=false};
            await Task.Delay(180);map.SetCameraPoseForProbe(new(focus,sign>0?0:Math.PI,0,20));
            map.Systems=[target];map.CurrentSystem=target.Name;map.Selection=target;map.RenderNowForProbe();
            var baseCamera=map.RequestedViewportForProbe.Camera!;
            Require(baseCamera.Project(target.Position).IsVisible&&!baseCamera.ProjectForCatalogue(target.Position).IsVisible&&map.VisibleStars==0,
                "The actual recorded edge-cell star did not exercise the previous finite boundary.");
            var before=map.CapturePixelsForProbe();await SaveModelFrameAsync(new(before.Width,before.Height,before.Pixels,0),Path.Combine(directory,"cell-selection-before.png"));
            using(await map.FreezeForXamlProbeAsync())await CaptureRefinementElementAsync(host,Path.Combine(directory,"cell-selection-before-xaml.png"));
            var descriptor=GalaxyOriginalCatalogueLod.Create(focus,1,500,.001,1,0);
            Require(descriptor.IntersectsCell(cell,origin)&&target.Position.DistanceTo(focus)>descriptor.InnerRadius,
                "The recorded fixture does not distinguish whole-cell inclusion from point-distance clipping.");
            map.CatalogueSelection=new(descriptor,origin);map.RenderNowForProbe();
            Require(map.VisibleStars==1&&map.VisibleNameLabels==1,"Original whole-cell selection failed to retain its actual edge-cell star.");
            map.SelectAt(map.ProjectForProbe(target.Position));
            Require(map.Selection?.SystemAddress==target.SystemAddress,"Original whole-cell star could not be selected by its actual rendered position.");
            var after=map.CapturePixelsForProbe();await SaveModelFrameAsync(new(after.Width,after.Height,after.Pixels,0),Path.Combine(directory,"cell-selection-after.png"));
            using(await map.FreezeForXamlProbeAsync())await CaptureRefinementElementAsync(host,Path.Combine(directory,"cell-selection-after-xaml.png"));
            var expanded=map.RequestedViewportForProbe.Camera!;
            map.Filter=map.Filter with{Values=new HashSet<string>(),IncludeUnknown=false};map.RenderNowForProbe();
            Require(map.VisibleStars==0&&map.VisibleNameLabels==0&&!map.VisibleCurrentLocationMarker&&map.VisibleWorldMarkers==0,
                "An empty strict query retained a whole-cell model, label or current marker.");
            map.SelectAt(map.ProjectForProbe(target.Position));Require(map.Selection is null,"A hidden whole-cell target retained a click hit.");
            using(await map.FreezeForXamlProbeAsync())await CaptureRefinementElementAsync(host,Path.Combine(directory,"cell-selection-empty-xaml.png"));
            var result=new{recordedTarget=target.Name,systemAddress=target.SystemAddress,cellAddress=cell.ToString(),origin,
                cameraPoseExplicitFixture=true,descriptorInputsExplicitFixture=true,generatedCatalogueCoordinates=false,
                wholeCellRetained=true,pointSphereWouldExclude=true,oldQueryFar=baseCamera.QueryFar,newQueryFar=expanded.QueryFar,
                originalProjectionRemainsInfinite=double.IsPositiveInfinity(expanded.ProjectionFar),modelsBefore=0,modelsAfter=1,
                labelsAfter=1,actualStarSelectable=true,strictEmptyLeavesNoModelLabelMarkerOrHit=true,liveNativeCoverageConfirmed=false,gameAccess=false};
            await File.WriteAllTextAsync(Path.Combine(directory,"cell-selection-probe.json"),JsonSerializer.Serialize(result,new JsonSerializerOptions{WriteIndented=true}));
            return result;
        }
        finally{map.SuspendPage();MainWindow.Content=previous;}
    }
}