# HG changeset patch # User Tess Snider # Date 2021-07-19 15:16:24 # Node ID f419334a476f33b0b93cbd02eba7a44f08f89733 # Parent 7117d2e703c8a82874a8fcb191bfff1452d854c9 Improved up behavior for clipped reactions and 3-way reactions, and fixed related bugs. diff --git a/Models/PlayerProfile.cs b/Models/PlayerProfile.cs --- a/Models/PlayerProfile.cs +++ b/Models/PlayerProfile.cs @@ -28,7 +28,7 @@ namespace DesertPaintCodex.Models public ReactionSet Reactions { get; } = new(); - private Dictionary> Clippers { get; } = new(); + public Dictionary> Clippers { get; } = new(); public string ReagentFile { get; } @@ -309,7 +309,7 @@ namespace DesertPaintCodex.Models if (!File.Exists(_clipFile)) return true; { - using StreamReader reader = new StreamReader(_clipFile); + using StreamReader reader = new(_clipFile); while ((line = reader.ReadLine()) != null) { string[] tokens = line.Split(' '); @@ -354,23 +354,24 @@ namespace DesertPaintCodex.Models } } } - using (StreamWriter writer = new StreamWriter(_clipFile, false)) + using (StreamWriter writer = new(_clipFile, false)) { foreach (var item1 in Clippers) { foreach (var item2 in item1.Value) { + if (item2.Value == ClipType.None) continue; writer.WriteLine(item1.Key + " " + item2.Key + " " + (int)item2.Value); } } } } - public ClipType PairClipStatus(string reagent1, string reagent2) + public ClipType PairClipStatus(Reagent reagent1, Reagent reagent2) { - if (Clippers.TryGetValue(reagent1, out var item1)) + if (Clippers.TryGetValue(reagent1.PracticalPaintName, out var item1)) { - if (item1.TryGetValue(reagent2, out var clipType)) + if (item1.TryGetValue(reagent2.PracticalPaintName, out var clipType)) { return clipType; } @@ -378,6 +379,25 @@ namespace DesertPaintCodex.Models return ClipType.None; } + public void SetPairClipStatus(Reagent reagent1, Reagent reagent2, ClipType clip) + { + if (Clippers.TryGetValue(reagent1.PracticalPaintName, out var item1)) + { + if (item1.TryGetValue(reagent2.PracticalPaintName, out var clipType)) + { + if (clipType == clip) return; + } + } + else + { + item1 = new Dictionary(); + Clippers.Add(reagent1.PracticalPaintName, item1); + } + + item1[reagent2.PracticalPaintName] = clip; + Save(); + } + private void LoadRecipes(Dictionary recipeDict, string filename, uint concentration) { foreach (PaintRecipe recipe in recipeDict.Values) diff --git a/Models/ReactionTest.cs b/Models/ReactionTest.cs --- a/Models/ReactionTest.cs +++ b/Models/ReactionTest.cs @@ -45,8 +45,8 @@ namespace DesertPaintCodex.Models _recipe.AddReagent(Reagent2.Name); } NotifyPropertyChanged(nameof(BufferReagent)); - NotifyPropertyChanged(nameof(HypotheticalColor)); NotifyPropertyChanged(nameof(CanScan)); + UpdateHypotheticalColor(); } } @@ -89,18 +89,18 @@ namespace DesertPaintCodex.Models NotifyPropertyChanged(nameof(CanClear)); NotifyPropertyChanged(nameof(CanSave)); NotifyPropertyChanged(nameof(NoLab)); + NotifyPropertyChanged(nameof(CanPickBuffer)); } } public bool Requires3Way => (State == TestState.ClippedResult) || IsAllCatalysts; - public bool CanScan => (State == TestState.Untested) || (State == TestState.LabNotFound) || - ((State == TestState.ClippedResult) && (BufferReagent != null)); + public bool CanScan => (State is TestState.Untested or TestState.LabNotFound) || ((State == TestState.ClippedResult) && (BufferReagent != null)); public bool IsScanning => State == TestState.Scanning; - public bool HasResults => State is TestState.ClippedResult or TestState.GoodResult or TestState.LabNotFound; + public bool HasResults => (ObservedColor != null) && (State is TestState.ClippedResult or TestState.GoodResult or TestState.LabNotFound); public bool HasReaction => State is TestState.ClippedResult or TestState.GoodResult or TestState.Saved; @@ -109,9 +109,12 @@ namespace DesertPaintCodex.Models public bool CanSave => State == TestState.GoodResult; public bool NoLab => State == TestState.LabNotFound; - + + public bool CanPickBuffer => (State == TestState.ClippedResult) || IsAllCatalysts; - public PaintColor? HypotheticalColor => (IsAllCatalysts && (BufferReagent == null)) ? null : _recipe.BaseColor; + + private PaintColor? _hypotheticalColor; + public PaintColor? HypotheticalColor { get => _hypotheticalColor; set { _hypotheticalColor = value; NotifyPropertyChanged(nameof(HypotheticalColor)); } } private PaintColor? _observedColor; public PaintColor? ObservedColor { get => _observedColor; set { _observedColor = value; NotifyPropertyChanged(nameof(ObservedColor)); } } @@ -133,6 +136,7 @@ namespace DesertPaintCodex.Models _recipe.AddReagent(reagent1.Name); _recipe.AddReagent(reagent2.Name); IsStub = isStub; + UpdateHypotheticalColor(); } @@ -173,13 +177,15 @@ namespace DesertPaintCodex.Models { State = TestState.GoodResult; Reaction = CalculateReaction(); - } else { State = TestState.ClippedResult; BadReaction = CalculateReaction(); } + + PlayerProfile? profile = ProfileManager.CurrentProfile; + profile?.SetPairClipStatus(Reagent1, Reagent2, Clipped); } } else @@ -206,6 +212,7 @@ namespace DesertPaintCodex.Models PlayerProfile? profile = ProfileManager.CurrentProfile; if (profile == null) return; profile.Reactions.Remove(Reagent1, Reagent2); + profile.SetPairClipStatus(Reagent1, Reagent2, ClipType.None); if (State == TestState.Saved) { profile.Save(); @@ -235,15 +242,20 @@ namespace DesertPaintCodex.Models if (HypotheticalColor == null) return null; if (ObservedColor == null) return null; - if (Requires3Way) + if (BufferReagent != null) { - if (BufferReagent == null) return null; return ReactionScannerService.Calculate3WayReaction(ProfileManager.CurrentProfile, HypotheticalColor, ObservedColor, BufferReagent, Reagent1, Reagent2); } return ReactionScannerService.CalculateReaction(HypotheticalColor, ObservedColor); } - + + + private void UpdateHypotheticalColor() + { + HypotheticalColor = null; + HypotheticalColor = (IsAllCatalysts && (BufferReagent == null)) ? null : _recipe.BaseColor; + } #endregion diff --git a/Models/ReactionTestService.cs b/Models/ReactionTestService.cs --- a/Models/ReactionTestService.cs +++ b/Models/ReactionTestService.cs @@ -32,7 +32,7 @@ namespace DesertPaintCodex.Models if (reagent1 == reagent2) continue; Reaction? reaction = profile.FindReaction(reagent1, reagent2); - ClipType clipType = profile.PairClipStatus(reagent1.Name, reagent2.Name); + ClipType clipType = profile.PairClipStatus(reagent1, reagent2); ReactionTest test = new(reagent1, reagent2, reaction, clipType) { diff --git a/ViewModels/ReactionTestViewModel.cs b/ViewModels/ReactionTestViewModel.cs --- a/ViewModels/ReactionTestViewModel.cs +++ b/ViewModels/ReactionTestViewModel.cs @@ -10,7 +10,6 @@ using DesertPaintCodex.Models; using DesertPaintCodex.Services; using DesertPaintCodex.Util; using ReactiveUI; -using DynamicData; namespace DesertPaintCodex.ViewModels { @@ -24,16 +23,21 @@ namespace DesertPaintCodex.ViewModels } private readonly List _allPigmentList = new(); - public ObservableCollection BufferPigmentList { get; } = new(); + private readonly List _allReagentList = new(); + public ObservableCollection BufferList { get; } = new(); public ReactionTestViewModel() { List reagentNames = ReagentService.Names; - foreach (var reagent in reagentNames.Select(ReagentService.GetReagent).Where(x => !x.IsCatalyst)) + foreach (var reagent in reagentNames.Select(ReagentService.GetReagent)) { - _allPigmentList.Add(reagent); + if (!reagent.IsCatalyst) + { + _allPigmentList.Add(reagent); + } + _allReagentList.Add(reagent); } this.WhenAnyValue(x => x.ReactionTest) @@ -64,10 +68,23 @@ namespace DesertPaintCodex.ViewModels private void FilterBufferPigments() { // Avalonia doesn't really have proper filtering for listy controls yet. - BufferPigmentList.Clear(); + PlayerProfile? profile = ProfileManager.CurrentProfile; + if (profile == null) return; + ReactionSet reactions = profile.Reactions; + BufferList.Clear(); + List bufferList = ReactionTest.IsAllCatalysts ? _allPigmentList : _allReagentList; + foreach (Reagent pigment in bufferList) + { + if (pigment == ReactionTest.Reagent1) continue; + if (pigment == ReactionTest.Reagent2) continue; + if (reactions.Find(pigment, ReactionTest.Reagent1) == null) continue; + if (reactions.Find(pigment, ReactionTest.Reagent2) == null) continue; + + BufferList.Add(pigment); + } - BufferPigmentList.AddRange(_allPigmentList.Where(pigment => - pigment != ReactionTest.Reagent1 && pigment != ReactionTest.Reagent2)); + // BufferPigmentList.AddRange(_allPigmentList.Where(pigment => + // pigment != ReactionTest.Reagent1 && pigment != ReactionTest.Reagent2)); } public async void Analyze() diff --git a/Views/MainWindow.axaml b/Views/MainWindow.axaml --- a/Views/MainWindow.axaml +++ b/Views/MainWindow.axaml @@ -7,6 +7,7 @@ mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="800" Width="640" Height="800" MinWidth="600" MinHeight="500" + Topmost="True" x:Class="DesertPaintCodex.Views.MainWindow" Icon="/Assets/desert_paint_codex_icon.ico" Title="Desert Paint Codex"> diff --git a/Views/ReactionTestView.axaml b/Views/ReactionTestView.axaml --- a/Views/ReactionTestView.axaml +++ b/Views/ReactionTestView.axaml @@ -39,9 +39,9 @@ Buffer: - - +