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

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Text.Json;
using XFEEDToolBox.Core.Galaxy;
using XFEEDToolBox.Core.Models;

namespace XFEEDToolBox.ViewModels;

// Link the actual production partial, with only unrelated VM dependencies
// stubbed. This executes its real cache mutation and PID/blend/mode guards.
public partial class ToolboxViewModel
{
    private readonly Dictionary<string,GalacticSystem> galaxyCache=new(StringComparer.OrdinalIgnoreCase);
    private readonly ClearCounter galaxyStreaming=new(),galaxyCellStreaming=new();
    private sealed class ClearCounter {internal int Count;internal void Clear()=>Count++;}
    public static int Main(string[] args)
    {
        var passed=new List<string>();
        static void Require(bool value,string message){if(!value)throw new Exception(message);}
        var vm=new ToolboxViewModel();
        var raw=new GalaxyOriginalStellarAppearance(0xFF332211,0xFF998877,.25f,123,4,1.25f,.075f,false);
        var star=new GalacticSystem("Actual VM cache fixture",new(1,2,3),1234,"G","游戏银河目录"){OriginalAppearance=raw};
        vm.galaxyCache[star.Name]=star;vm.BindGalaxyAppearance(100,.1f,false);
        var cleared=vm.galaxyCache[star.Name];
        Require(cleared.Position==star.Position&&cleared.SystemAddress==star.SystemAddress&&cleared.OriginalAppearance is
            {TypeRgba:0xFF332211,RawScale:123,Classification:4,Size:1.25f,SmallSize:.075f,RealisticRgba:null,ColourBlend:null},"Initial binding must clear mixed colours and preserve real geometry/type/both raw sizes");
        Require(vm.galaxyStreaming.Count==1&&vm.galaxyCellStreaming.Count==1,"Both streaming colour captures must be invalidated");passed.Add("initial-real-geometry-preserved");

        var fresh=star with{OriginalAppearance=raw with{ColourBlend=.1f}};
        var accepted=vm.ApplyGalaxyAppearanceBinding(fresh,100,100,false);
        Require(accepted.OriginalAppearance!.RealisticRgba==raw.RealisticRgba,"0.1 float wire round trip must match the current blend");
        vm.galaxyCache[star.Name]=accepted;passed.Add("float-precision-current-colour");
        var old=vm.ApplyGalaxyAppearanceBinding(star,100,100,false);
        Require(old.OriginalAppearance!.RealisticRgba is null&&old.OriginalAppearance.ColourBlend is null&&old.OriginalAppearance.TypeRgba==raw.TypeRgba,"An old async blend may retain raw facts but cannot restore old mixed colours");passed.Add("late-old-blend-rejected");
        var wrongPid=vm.ApplyGalaxyAppearanceBinding(fresh,99,100,false);
        Require(wrongPid.OriginalAppearance!.RealisticRgba is null,"Equal blend does not make another process current");passed.Add("wrong-process-rejected");

        vm.BindGalaxyAppearance(100,.1f,true);var small=vm.galaxyCache[star.Name];
        Require(vm.galaxyStreaming.Count==1&&vm.galaxyCellStreaming.Count==1,"Changing only size mode must not reload cell geometry");
        Require(small.OriginalAppearance is{SmallSizeActive:true,RealisticRgba:not null}&&small.OriginalAppearance.ActiveSize==raw.SmallSize,"Existing cached stars must use the current small-size mode");
        Require(vm.ApplyGalaxyAppearanceBinding(fresh,100,100,false).OriginalAppearance!.SmallSizeActive==true,"A matching old row must not reinstate its old active-size flag");passed.Add("size-switch-no-geometry-reload");
        vm.BindGalaxyAppearance(100,.1f,null);
        Require(vm.galaxyCache[star.Name].OriginalAppearance!.SmallSizeActive is null&&vm.ApplyGalaxyAppearanceBinding(fresh,100,100,false).OriginalAppearance!.SmallSizeActive is null,"Unknown current size mode must remain null");passed.Add("unknown-size-mode-preserved");
        vm.BindGalaxyAppearance(100,.75f,false);
        Require(vm.galaxyStreaming.Count==2&&vm.galaxyCellStreaming.Count==2&&vm.galaxyCache[star.Name].OriginalAppearance!.RealisticRgba is null,"Changed blend must reload only derived colour captures");passed.Add("changed-blend-invalidates-streams");
        vm.ResetGalaxyAppearanceBinding();var reset=vm.galaxyCache[star.Name].OriginalAppearance!;
        Require(reset.RealisticRgba is null&&reset.ColourBlend is null&&reset.SmallSizeActive is null&&reset.Size==raw.Size&&reset.SmallSize==raw.SmallSize,"Source reset must clear active option facts without destroying raw sizes");
        Require(vm.ApplyGalaxyAppearanceBinding(fresh,100,100,false).OriginalAppearance!.RealisticRgba is null,"Unbound data cannot claim current mixed colour");passed.Add("source-reset-unbinds-options");
        Require(ReferenceEquals(fresh,vm.ApplyGalaxyAppearanceBinding(fresh,null,null,true)),"Explicit offline recorded appearance remains a fixture rather than a live-profile claim");passed.Add("recorded-probe-remains-explicit");
        vm.BindGalaxyAppearance(101,.1f,false);vm.galaxyCache[star.Name]=vm.ApplyGalaxyAppearanceBinding(fresh,101,101,false);
        var local=vm.galaxyCache[star.Name];Require(ReferenceEquals(local,vm.ApplyGalaxyAppearanceBinding(local,null,101,false)),"Already bound local cache objects keep their valid colours");passed.Add("bound-local-reuse");
        var report=new{passed=passed.Count,failed=0,checks=passed,productionSource="XFEEDToolBox/ViewModels/GalaxyViewModel.Appearance.cs",gameProcessAccess=false,gameCalls=0};
        var json=JsonSerializer.Serialize(report,new JsonSerializerOptions{WriteIndented=true});
        if(args.Length>0){Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(args[0]))!);File.WriteAllText(args[0],json);}Console.WriteLine(json);return 0;
    }
}