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> RunGalaxyProjectionBoundaryProbeAsync(string directory)
    {
        static void Require(bool value,string message){if(!value)throw new InvalidOperationException(message);}
        var previous=MainWindow.Content;var host=new Grid();var map=new GalaxyMapView();host.Children.Add(map);MainWindow.Content=host;
        try
        {
            map.Centre=new(0,0,0);map.Filter=GalaxyMapFilter.Default with{Mode=GalaxyMapMode.Map,Values=new HashSet<string>{"g"},IncludeUnknown=false,ShowBackground=false,ShowGrid=false,
                ShowLinks=false,ShowRoute=false,ShowConstellations=false,ShowCurrentTradeFlows=false,ShowHistoricalTradeFlows=false,
                ShowRegionNames=false,ShowNebulaNames=false,ShowGalacticZonesPlane=false,ShowGalacticZoneNames=false};
            await Task.Delay(180);map.ResetCamera();map.RenderNowForProbe();
            var camera=map.RequestedViewportForProbe.Camera??throw new InvalidOperationException("Missing actual query camera.");
            var outsideDepth=camera.QueryFar+100;
            var outsidePosition=new Coordinates(camera.Eye.X+camera.Forward.X*outsideDepth,camera.Eye.Y+camera.Forward.Y*outsideDepth,camera.Eye.Z+camera.Forward.Z*outsideDepth);
            var insidePosition=new Coordinates(camera.Focus.X+camera.Right.X*camera.Distance*.2,camera.Focus.Y+camera.Right.Y*camera.Distance*.2,camera.Focus.Z+camera.Right.Z*camera.Distance*.2);
            // Explicit mathematical fixture only. These synthetic positions
            // are never inserted into a real catalogue/provider/cache.
            var inside=new GalacticSystem("inside-query-fixture",insidePosition,StarClass:"G",Source:"Synthetic projection-boundary fixture");
            var outside=new GalacticSystem("outside-query-fixture",outsidePosition,StarClass:"G",Source:"Synthetic projection-boundary fixture"){Data=new(){Markers=["engineer"]}};
            map.PointsOfInterest=[new("inside-place",inside.Name,inside.Position,null,0,"Synthetic projection-boundary fixture"),
                new("outside-place",outside.Name,outside.Position,null,0,"Synthetic projection-boundary fixture")];
            Require(double.IsPositiveInfinity(camera.ProjectionFar)&&camera.Project(outsidePosition).IsVisible&&!camera.ProjectForCatalogue(outsidePosition).IsVisible,
                "Infinite geometry projection and finite catalogue boundary remained coupled.");
            map.Systems=[inside,outside];map.CurrentSystem=outside.Name;map.Selection=outside;map.RenderNowForProbe();
            Require(map.VisibleStars==1&&map.VisibleNameLabels==1&&map.VisibleSupplementalPlaceLabelsForProbe==1&&map.VisibleWorldMarkers==0&&!map.VisibleCurrentLocationMarker,
                "A cached star outside the finite query boundary retained a model, label or original marker.");
            map.SelectAt(map.ProjectForProbe(outsidePosition));
            Require(map.Selection is null,"Infinite geometry projection made an outside-query star selectable.");
            map.Filter=map.Filter with{Values=new HashSet<string>()};map.RenderNowForProbe();
            Require(map.VisibleStars==0&&map.VisibleNameLabels==0&&map.VisibleSupplementalPlaceLabelsForProbe==0,
                "Empty strict query retained a supplemental place name.");
            var result=new{fixtureCoordinatesSynthetic=true,generatedCatalogueCoordinates=false,infiniteProjection=true,
                queryFar=camera.QueryFar,outsideDepth,boundedModels=1,boundedLabels=1,outsideMarkerHidden=true,outsideCurrentMarkerHidden=true,
                outsideSelectionCannotBypassBoundary=true,outsideHitCannotBypassBoundary=true,supplementalPlaceLabelsRespectQuery=true,gameAccess=false};
            await File.WriteAllTextAsync(Path.Combine(directory,"projection-query-boundary-probe.json"),JsonSerializer.Serialize(result,new JsonSerializerOptions{WriteIndented=true}));
            return result;
        }
        finally{map.SuspendPage();MainWindow.Content=previous;}
    }
}