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

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
using XFEEDToolBox.Controls;
using XFEEDToolBox.Core.Outfitting;
using XFEEDToolBox.Views;

namespace XFEEDToolBox;

public partial class App
{
    private static async Task<object> RunRefitWorkbenchProbeAsync(string reportPath)
    {
        AppShellPage.Current!.Navigate(typeof(RefitPage));
        await Task.Delay(200);
        ViewModel.RebuildRefitCommand.Execute(null);
        var page=AppShellPage.Current.CurrentPage!;
        var slotList=Descendants(page).OfType<ListView>().Single(v=>v.Name=="SlotList");
        var categoryList=Descendants(page).OfType<ListView>().Single(v=>v.Name=="RefitCategoryList");
        var inspector=Descendants(page).OfType<Border>().Single(v=>v.Name=="InspectorPanel");
        var tabs=Descendants(inspector).OfType<Pivot>().Single();
        var selected=ViewModel.RefitSlot?.Slot;
        var categories=new List<object>();
        foreach(var (index,category) in new[]{(0,"hardpoint"),(1,"utility"),(2,"standard"),(3,"internal")})
        {
            categoryList.SelectedIndex=index;await Task.Delay(60);
            categories.Add(new{index,count=ViewModel.RefitVisibleSlots.Count,bound=ViewModel.RefitCategoryIndex==index,filtered=ViewModel.RefitVisibleSlots.All(s=>s.Category==category),selectionVisible=ViewModel.RefitSlot is null||ViewModel.RefitVisibleSlots.Contains(ViewModel.RefitSlot)});
        }
        var unrequestedTargets=ViewModel.RefitDocument?.Slots.Count(s=>s.Target is not null)??0;
        ViewModel.RefitCategoryIndex=0;
        var sample=ViewModel.RefitSlots.FirstOrDefault(s=>s.Module?.Engineering?.Modifiers.Count>0)??ViewModel.RefitSlots.FirstOrDefault(s=>s.Module is not null);
        if(sample is not null){ViewModel.RefitCategoryIndex=Array.IndexOf(new[]{"hardpoint","utility","standard","internal"},sample.Category);slotList.SelectedItem=ViewModel.RefitVisibleSlots.FirstOrDefault(s=>s.Slot==sample.Slot);}
        await Task.Delay(80);
        var selectedNameBound=Descendants(inspector).OfType<BilingualText>().Any(t=>t.Text==sample?.Module?.DisplayName);
        var parameterRows=ViewModel.RefitModifiers.Count;
        var grade=Descendants(inspector).OfType<RatingControl>().Single();
        var originalGrade=grade.Value;
        grade.Value=4;await Task.Delay(60);
        var gradeBound=ViewModel.RefitGrade==4;
        var next=ViewModel.RefitVisibleSlots.FirstOrDefault(s=>s.Slot!=sample?.Slot&&s.Module is not null);
        if(next is not null)slotList.SelectedItem=next;
        var gradePersisted=sample is null||ViewModel.RefitDocument?.Slots.Single(s=>s.Slot==sample.Slot).Target?.Grade==4;
        if(sample is not null)slotList.SelectedItem=ViewModel.RefitVisibleSlots.First(s=>s.Slot==sample.Slot);
        await Task.Delay(60);
        var gradeRestored=ViewModel.RefitGrade==4&&grade.Value==4;
        var realizedNames=Descendants(slotList).OfType<BilingualText>().ToArray();
        var namesOnly=realizedNames.Length>0&&realizedNames.All(t=>ViewModel.RefitSlots.Any(s=>s.Caption==t.Text&&s.OriginalName==t.Original));
        ViewModel.RefitSlotSearch=sample?.Module?.OriginalName??"";
        await Task.Delay(60);
        var searchMatches=ViewModel.RefitVisibleSlots.All(s=>s.Caption.Contains(ViewModel.RefitSlotSearch,StringComparison.OrdinalIgnoreCase)||s.OriginalName.Contains(ViewModel.RefitSlotSearch,StringComparison.OrdinalIgnoreCase));
        ViewModel.RefitSlotSearch="";
        if(sample is not null)ViewModel.RefitSlot=ViewModel.RefitVisibleSlots.First(s=>s.Slot==sample.Slot);
        var module=ViewModel.RefitSlot?.Module;
        var installChoice=ViewModel.RefitAvailableModules.FirstOrDefault(c=>!c.Owned&&c.Module.Item!=module?.Item);
        var installationVerified=false;
        if(installChoice is not null&&sample is not null)
        {
            ViewModel.RefitInstallModule=installChoice;
            ViewModel.InstallRefitModuleCommand.Execute(null);
            installationVerified=ViewModel.RefitSlot?.Module?.Item==installChoice.Module.Item&&ViewModel.RefitSelectedName==installChoice.Module.DisplayName;
            ViewModel.UninstallRefitModuleCommand.Execute(null);
            var unloaded=ViewModel.RefitSlot?.Module is null&&ViewModel.RefitSelectedName=="空槽";
            var originalChoice=ViewModel.RefitAvailableModules.FirstOrDefault(c=>c.InstanceKey==sample.InstanceKey&&c.Module.Item==module?.Item);
            if(originalChoice is not null){ViewModel.RefitInstallModule=originalChoice;ViewModel.InstallRefitModuleCommand.Execute(null);}
            installationVerified&=unloaded&&ViewModel.RefitSlot?.Module?.Item==module?.Item;
        }
        var folder=Path.Combine(Path.GetDirectoryName(Path.GetFullPath(reportPath))!,"screenshots");
        for(var index=0;index<tabs.Items.Count;index++)
        {
            tabs.SelectedIndex=index;await Task.Delay(120);
            await CapturePageAsync(page,Path.Combine(folder,$"refit-inspector-{index}.png"));
        }
        tabs.SelectedIndex=0;
        var categoriesPanel=Descendants(page).OfType<Border>().Single(v=>v.Name=="CategoryPanel");
        var centre=Descendants(page).OfType<Border>().Single(v=>v.Name=="SlotPanel");
        var positions=new[]{categoriesPanel,centre,inspector}.Select(p=>new{p.Name,x=p.TransformToVisual(page).TransformPoint(new(0,0)).X,y=p.TransformToVisual(page).TransformPoint(new(0,0)).Y,width=p.ActualWidth,height=p.ActualHeight}).ToArray();
        ViewModel.RebuildRefitCommand.Execute(null);
        await ViewModel.ExportEdsyCommand.ExecuteAsync(null);
        var originalUrl=ViewModel.RefitEdsyLink;
        var actualExported=originalUrl.StartsWith("https://edsy.org/#/L=");
        var exportStatus=ViewModel.RefitEdsyStatus;
        var actualModulesBefore=ViewModel.RefitDocument?.Slots.Where(s=>s.Module is not null&&s.Category.Length>0).Select(s=>s.Module!.Item).Order().ToArray()??[];
        if(actualExported)await ViewModel.ImportEdsyCommand.ExecuteAsync(null);
        var actualModulesAfter=ViewModel.RefitDocument?.Slots.Where(s=>s.Module is not null&&s.Category.Length>0).Select(s=>s.Module!.Item).Order().ToArray()??[];
        var actualMissing=actualModulesBefore.Except(actualModulesAfter).ToArray();
        var actualAdded=actualModulesAfter.Except(actualModulesBefore).ToArray();
        var actualImportMatched=actualExported&&actualModulesBefore.SequenceEqual(actualModulesAfter);
        await ViewModel.ExportEdsyCommand.ExecuteAsync(null);
        var actualLinkRoundTrip=actualImportMatched&&ViewModel.RefitEdsyLink==originalUrl;
        await File.WriteAllTextAsync(Path.Combine(Path.GetDirectoryName(Path.GetFullPath(reportPath))!,"actual-edsy-exports.json"),System.Text.Json.JsonSerializer.Serialize(new[]{new{name="actual-current-ship",url=originalUrl}}));
        var panel=new EdsyLinkPanel{DataContext=ViewModel};
        var dialog=new ContentDialog{Title="EDSY 装配链接",Content=panel,CloseButtonText="关闭",XamlRoot=page.XamlRoot};
        var showing=dialog.ShowAsync();await Task.Delay(200);
        var linkBox=Descendants(panel).OfType<TextBox>().Single();
        var dialogBound=linkBox.Text==ViewModel.RefitEdsyLink&&Descendants(panel).OfType<Button>().Count(b=>b.Command is not null)==2;
        await CapturePageAsync(page,Path.Combine(folder,"edsy-links.png"));dialog.Hide();await showing;
        ViewModel.RebuildRefitCommand.Execute(null);
        if(selected is not null)ViewModel.RefitSlot=ViewModel.RefitVisibleSlots.FirstOrDefault(s=>s.Slot==selected);
        return new{categories,unrequestedTargets,noAllCategory=ViewModel.RefitCategories.Count==4&&ViewModel.RefitCategories.All(c=>c.Key.Length>0),noSelectorBar=!Descendants(page).OfType<SelectorBar>().Any(),positions,
            categorySelectionPreserved=categoryList.SelectedIndex==ViewModel.RefitCategoryIndex&&categoryList.SelectedIndex>=0,
            gradeBound,gradePersisted,gradeRestored,hexImages=grade.ItemInfo is RatingItemImageInfo,namesOnly,realizedNameRows=realizedNames.Length,selectedNameBound,parameterRows,searchMatches,installationVerified,
            edsy=new{actualExported,actualImportMatched,actualLinkRoundTrip,actualMissing,actualAdded,exportStatus,dialogBound},
            inspectorTabs=tabs.Items.Count,sourceUnchanged=sample is null||Runtime.Player.Ships.First(s=>s.ShipId==ViewModel.RefitSourceShip!.ShipId).Modules.FirstOrDefault(m=>m.Slot==sample.Slot)==module,gameEditsInvoked=false};
    }
}