Files
@ 11d11a57837d
Branch filter:
Location: ATITD-Tools/Desert-Paint-Codex/ViewModels/ReactionTestViewModel.cs
11d11a57837d
5.6 KiB
text/x-csharp
Reorganizing the white-reaction clip extrapolation to see if it works better.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using System.Threading.Tasks;
using DesertPaintCodex.Models;
using DesertPaintCodex.Services;
using DesertPaintCodex.Util;
using ReactiveUI;
namespace DesertPaintCodex.ViewModels
{
public class ReactionTestViewModel : ViewModelBase
{
private ReactionTest _reactionTest = Constants.StubReactionTest;
public ReactionTest ReactionTest
{
get => _reactionTest;
set => this.RaiseAndSetIfChanged(ref _reactionTest, value);
}
private readonly List<Reagent> _allPigmentList = new();
private readonly List<Reagent> _allReagentList = new();
public ObservableCollection<Reagent> FirstBufferList { get; } = new();
public ObservableCollection<Reagent> LastBufferList { get; } = new();
public ReactionTestViewModel()
{
List<string> reagentNames = ReagentService.Names;
foreach (var reagent in reagentNames.Select(ReagentService.GetReagent))
{
if (!reagent.IsCatalyst)
{
_allPigmentList.Add(reagent);
}
_allReagentList.Add(reagent);
}
this.WhenAnyValue(x => x.ReactionTest)
.Subscribe(_ => UpdateDerivedState());
ShowScreenSettingsDialog = new Interaction<ScreenSettingsViewModel, Unit>();
SaveReaction = ReactiveCommand.Create(() => ReactionTest.SaveReaction());
ClearReaction = ReactiveCommand.Create(() => ReactionTest.ClearReaction());
FinalizeTestResults = ReactiveCommand.Create(Test);
}
private void UpdateDerivedState()
{
// There are more "reactive" ways to pull this off, but I don't have time to figure out all those recipes
// right now.
SetupTest();
}
private void SetupTest()
{
if (ReactionTest.Requires3Way)
{
FilterBufferPigments();
}
}
private void FilterBufferPigments()
{
// Avalonia doesn't really have proper filtering for listy controls yet.
PlayerProfile? profile = ProfileManager.CurrentProfile;
if (profile == null) return;
ReactionSet reactions = profile.Reactions;
List<Reagent> bufferList = ReactionTest.IsAllCatalysts ? _allPigmentList : _allReagentList;
foreach (Reagent buffer in bufferList)
{
if (buffer == ReactionTest.Reagent1) continue;
if (buffer == ReactionTest.Reagent2) continue;
if ((reactions.Find(buffer, ReactionTest.Reagent1) != null)
&& (reactions.Find(buffer, ReactionTest.Reagent2) != null))
{
FirstBufferList.Add(buffer);
}
if ((reactions.Find(ReactionTest.Reagent1, buffer) != null)
&& (reactions.Find(ReactionTest.Reagent2, buffer) != null))
{
LastBufferList.Add(buffer);
}
}
// BufferPigmentList.AddRange(_allPigmentList.Where(pigment =>
// pigment != ReactionTest.Reagent1 && pigment != ReactionTest.Reagent2));
}
public async void Analyze()
{
Debug.WriteLine("Analyze");
try
{
await ReactionTest.StartScan();
await FinalizeTestResults.Execute();
}
catch (OperationCanceledException)
{
Debug.WriteLine("Scan canceled.");
}
}
public void MarkInert()
{
ReactionTest.MarkInert();
}
public void CancelScan()
{
ReactionTest.CancelScan();
}
public async Task OpenScreenSettings()
{
await ShowScreenSettingsDialog.Handle(new ScreenSettingsViewModel());
}
public async Task ShowClipInfo()
{
await ShowInfoBox("Clipped Reactions", "The Pigment Lab is only capable of displaying color channel values in the 0-255 range. However, sometimes, your reactions will push one or more channels outside of that range. When that happens, the value will be clamped either to 0 or 255. In this case, we say that the reaction was \"Clipped.\"\n\nThis is nothing to panic about, though. We solve this issue by using a third (buffer) reagent to offset the extreme value, so that it falls within measurable range, similar to how we test Catalyst+Catalyst reactions. Desert Paint Codex will automatically do the math for this, but it does move clipped reactions towards the end of your test list, because you'll want any reactions between the buffer reagent and your two test reagents already known, prior to running your buffered test.");
}
public void UseFirstBuffer()
{
ReactionTest.UseFirstBuffer = true;
}
public void UseLastBuffer()
{
ReactionTest.UseFirstBuffer = false;
}
private void Test()
{
Debug.WriteLine("Test complete");
}
public Interaction<ScreenSettingsViewModel, Unit> ShowScreenSettingsDialog { get; }
public ReactiveCommand<Unit, Unit> ClearReaction { get; }
public ReactiveCommand<Unit, Unit> SaveReaction { get; }
public ReactiveCommand<Unit, Unit> FinalizeTestResults { get; }
}
}
|