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> RunGalaxyPowerRingProbeAsync(string directory,IReadOnlyList<GalacticSystem> recorded)
    {
        static void Require(bool value,string message){if(!value)throw new InvalidOperationException(message);}
        var actual=recorded.First(s=>s.SystemAddress is >0&&s.Position.IsValid);
        var other=recorded.First(s=>s.SystemAddress is >0&&s.SystemAddress!=actual.SystemAddress&&s.Position.IsValid);
        const float radius=5.775f;
        GalacticSystem Fixture(GalacticSystem row,string fid,bool visible=true)=>row with{Data=row.Data with{
            AccountFid=fid,NativeFilterFacts=new GalaxyNativeSystemFacts(fid,Environment.ProcessId,actual.SystemAddress!.Value)
            {PowerOuter=new(visible,row.SystemAddress,row.Position,radius)}}};
        var target=Fixture(actual,"explicit-synthetic-power-ring");
        var previous=MainWindow.Content;var host=new Grid();var map=new GalaxyMapView();host.Children.Add(map);MainWindow.Content=host;
        var observations=new Dictionary<string,object>();
        async Task Save(string name)
        {
            map.RenderNowForProbe();var frame=map.CapturePixelsForProbe();var peak=0;var nonBlack=0;
            for(var i=0;i<frame.Pixels.Length;i+=4)
            {var rgb=Math.Max(frame.Pixels[i],Math.Max(frame.Pixels[i+1],frame.Pixels[i+2]));peak=Math.Max(peak,rgb);if(rgb>0)nonBlack++;}
            observations[name]=new{frame.Width,frame.Height,prepared=map.PreparedPowerActivityRingsForProbe,submitted=map.SubmittedPowerActivityRingsForProbe,
                sourceUnknown=map.PowerActivityRingSourceUnknownForProbe,exposureState=map.OriginalExposureStateForProbe,
                type2Emissive=map.OriginalType2ExposureForProbe,exposureDispatches=map.OriginalExposureDispatchesForProbe,
                usesToolComputedExposure=map.PowerActivityRingUsesToolExposureForProbe,gpuPeakRgb=peak,gpuNonBlackPixels=nonBlack,
                submittedBillboards=map.SubmittedPowerActivityBillboardsForProbe,
                submissionIsNotPixelVisibility=true};
            using(await map.FreezeForXamlProbeAsync())await CaptureRefinementElementAsync(host,Path.Combine(directory,name+".png"));
        }
        try
        {
            var activities=GalaxyMapFilter.Default with{Mode=GalaxyMapMode.Powerplay,PowerplayView=GalaxyPowerplayView.Activities,
                Category=GalaxyFilterCategory.Power,Values=null,IncludeUnknown=false,ShowBackground=false,ShowGrid=false,ShowLinks=false,
                ShowRoute=false,ShowMarkers=false,ShowConstellations=false,ShowCurrentTradeFlows=false,ShowHistoricalTradeFlows=false,
                ShowRegionNames=false,ShowNebulaNames=false,ShowGalacticZonesPlane=false,ShowGalacticZoneNames=false};
            map.Filter=activities;map.Systems=[target];await Task.Delay(180);
            map.SetCameraPoseForProbe(new(actual.Position,0,.9,24));map.RenderNowForProbe();
            Require(map.PreparedPowerActivityRingsForProbe==1&&map.SubmittedPowerActivityRingsForProbe==1&&
                !map.PowerActivityRingSourceUnknownForProbe&&map.PowerActivityRingUsesToolExposureForProbe&&
                map.OriginalExposureStateForProbe=="ManualComputed"&&map.OriginalType2ExposureForProbe is{} exposure&&MathF.Abs(exposure-.53827727f)<.000001f,
                "The coherent synthetic PowerOuter facts did not reach Main's ring buffer with this view's original manual exposure result.");
            var dispatches=map.OriginalExposureDispatchesForProbe;map.RenderNowForProbe();map.RenderNowForProbe();
            Require(dispatches>0&&map.OriginalExposureDispatchesForProbe==dispatches,"Unchanged manual controls dispatched the original exposure compute again.");
            await Save("range-ring");

            GalacticSystem WithExtent(float? extent)=>target with{Data=target.Data with{NativeFilterFacts=target.Data.NativeFilterFacts! with{
                PowerOuter=target.Data.NativeFilterFacts!.PowerOuter! with{Extent=extent}}}};
            map.Systems=[WithExtent(4)];map.RenderNowForProbe();
            Require(map.SubmittedPowerActivityBillboardsForProbe==1&&map.SubmittedPowerActivityRingsForProbe==1,"A known independent extent did not submit its camera-facing outline.");
            await Save("activity-outline-near");
            foreach(var extent in new float?[]{null,0,30})
            {map.Systems=[WithExtent(extent)];map.RenderNowForProbe();Require(map.SubmittedPowerActivityBillboardsForProbe==0,"Missing/zero extent or an eye inside it retained a billboard.");}
            var otherExtent=other with{Data=target.Data};
            otherExtent=otherExtent with{Data=otherExtent.Data with{NativeFilterFacts=otherExtent.Data.NativeFilterFacts! with{
                PowerOuter=otherExtent.Data.NativeFilterFacts!.PowerOuter! with{Extent=5}}}};
            map.Systems=[WithExtent(4),otherExtent];map.RenderNowForProbe();
            Require(map.FilteredModels==2&&map.SubmittedPowerActivityRingsForProbe==1&&map.SubmittedPowerActivityBillboardsForProbe==0,"Conflicting extents selected an arbitrary outline or erased the coherent range ring.");
            map.Systems=[target];

            map.Filter=activities with{Mode=GalaxyMapMode.Realistic};map.RenderNowForProbe();
            Require(map.PreparedPowerActivityRingsForProbe==0&&map.SubmittedPowerActivityRingsForProbe==0,"The default realistic view retained the Activities range ring.");
            // This is the ordinary default view comparison, not an assertion
            // that the exposure resource remained in DefaultCreated state.
            await Save("range-ring-default");
            map.Filter=activities with{PowerplayView=GalaxyPowerplayView.Territory};map.RenderNowForProbe();
            Require(map.PreparedPowerActivityRingsForProbe==0&&map.SubmittedPowerActivityRingsForProbe==0,"Switching Activities off retained its range ring.");
            map.Filter=activities;map.Systems=[];map.RenderNowForProbe();
            Require(map.PreparedPowerActivityRingsForProbe==0&&map.SubmittedPowerActivityRingsForProbe==0,"An empty result set retained a range ring.");
            map.Systems=[Fixture(actual,"explicit-synthetic-power-ring",false)];map.RenderNowForProbe();
            Require(map.PreparedPowerActivityRingsForProbe==0&&map.SubmittedPowerActivityRingsForProbe==0,"A non-matching original outer Visible=false row retained a range ring.");
            await Save("range-ring-hidden");
            map.Systems=[target,Fixture(other,"explicit-synthetic-conflicting-source")];map.RenderNowForProbe();
            Require(map.PreparedPowerActivityRingsForProbe==0&&map.SubmittedPowerActivityRingsForProbe==0,
                "Incoherent source identities and different recorded centres selected an arbitrary range ring.");
            var result=new{actual.Name,actual.SystemAddress,actual.Position,conflictingRecordedCentre=new{other.Name,other.SystemAddress,other.Position},
                radiusExplicitSyntheticFixture=radius,outerVisibilityAndAccountFactsExplicitSynthetic=true,processIdExplicitOwnFixture=Environment.ProcessId,
                fixtureDoesNotEstablishObservedPowerGeometry=true,generatedCatalogueCoordinates=false,
                coherentActivitiesPreparedOneSubmittedOne=true,ownManualExposureComputed=true,type2EmissiveExpected=.53827727f,
                unchangedManualControlsDoNotRedispatch=true,defaultScreenshotIsOrdinaryRealisticView=true,
                independentExtentExplicitSyntheticFixture=4,knownExtentSubmitsBillboard=true,missingZeroOrInsideExtentSuppressBillboard=true,inconsistentExtentsDoNotChooseOne=true,
                activitiesOffNoRing=true,emptySystemsNoRing=true,nonMatchingVisibleFalseNoRing=true,incoherentSourceNoArbitraryCentre=true,
                submissionCountDoesNotEstablishPixelVisibility=true,observations,gameAccess=false};
            await File.WriteAllTextAsync(Path.Combine(directory,"power-ring-probe.json"),JsonSerializer.Serialize(result,new JsonSerializerOptions{WriteIndented=true}));
            return result;
        }
        finally{map.SuspendPage();MainWindow.Content=previous;}
    }
}