Changeset - f419334a476f
[Not reviewed]
Tess Snider (Malkyne) - 3 years ago 2021-07-19 15:16:24
this@malkyne.org
Improved up behavior for clipped reactions and 3-way reactions, and fixed
related bugs.
6 files changed with 77 insertions and 27 deletions:
0 comments (0 inline, 0 general)
Models/PlayerProfile.cs
Show inline comments
...
 
@@ -30,3 +30,3 @@ namespace DesertPaintCodex.Models
 

	
 
        private Dictionary<string, Dictionary<string, ClipType>> Clippers { get; } = new();
 
        public Dictionary<string, Dictionary<string, ClipType>> Clippers { get; } = new();
 

	
...
 
@@ -311,3 +311,3 @@ namespace DesertPaintCodex.Models
 
            {
 
                using StreamReader reader = new StreamReader(_clipFile);
 
                using StreamReader reader = new(_clipFile);
 
                while ((line = reader.ReadLine()) != null)
...
 
@@ -356,3 +356,3 @@ namespace DesertPaintCodex.Models
 
            }
 
            using (StreamWriter writer = new StreamWriter(_clipFile, false))
 
            using (StreamWriter writer = new(_clipFile, false))
 
            {
...
 
@@ -362,2 +362,3 @@ namespace DesertPaintCodex.Models
 
                    {
 
                        if (item2.Value == ClipType.None) continue;
 
                        writer.WriteLine(item1.Key + " " + item2.Key + " " + (int)item2.Value);
...
 
@@ -368,7 +369,7 @@ namespace DesertPaintCodex.Models
 

	
 
        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))
 
                {
...
 
@@ -380,2 +381,21 @@ namespace DesertPaintCodex.Models
 

	
 
        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<string, ClipType>();
 
                Clippers.Add(reagent1.PracticalPaintName, item1);
 
            }
 

	
 
            item1[reagent2.PracticalPaintName] = clip;
 
            Save();
 
        }
 

	
 
        private void LoadRecipes(Dictionary<string, PaintRecipe> recipeDict, string filename, uint concentration)
Models/ReactionTest.cs
Show inline comments
...
 
@@ -47,4 +47,4 @@ namespace DesertPaintCodex.Models
 
                NotifyPropertyChanged(nameof(BufferReagent));
 
                NotifyPropertyChanged(nameof(HypotheticalColor));
 
                NotifyPropertyChanged(nameof(CanScan));
 
                UpdateHypotheticalColor();
 
            }
...
 
@@ -91,2 +91,3 @@ namespace DesertPaintCodex.Models
 
                NotifyPropertyChanged(nameof(NoLab));
 
                NotifyPropertyChanged(nameof(CanPickBuffer));
 
            }
...
 
@@ -97,4 +98,3 @@ namespace DesertPaintCodex.Models
 

	
 
        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));
 
        
...
 
@@ -102,3 +102,3 @@ namespace DesertPaintCodex.Models
 

	
 
        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);
 

	
...
 
@@ -111,5 +111,8 @@ namespace DesertPaintCodex.Models
 
        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)); } }
 

	
...
 
@@ -135,2 +138,3 @@ namespace DesertPaintCodex.Models
 
            IsStub = isStub;
 
            UpdateHypotheticalColor();
 
        }
...
 
@@ -175,3 +179,2 @@ namespace DesertPaintCodex.Models
 
                        Reaction = CalculateReaction();
 

	
 
                    }
...
 
@@ -182,2 +185,5 @@ namespace DesertPaintCodex.Models
 
                    }
 
                    
 
                    PlayerProfile? profile = ProfileManager.CurrentProfile;
 
                    profile?.SetPairClipStatus(Reagent1, Reagent2, Clipped);
 
                }
...
 
@@ -208,2 +214,3 @@ namespace DesertPaintCodex.Models
 
            profile.Reactions.Remove(Reagent1, Reagent2);
 
            profile.SetPairClipStatus(Reagent1, Reagent2, ClipType.None);
 
            if (State == TestState.Saved)
...
 
@@ -237,5 +244,4 @@ namespace DesertPaintCodex.Models
 

	
 
            if (Requires3Way)
 
            if (BufferReagent != null)
 
            {
 
                if (BufferReagent == null) return null;
 
                return ReactionScannerService.Calculate3WayReaction(ProfileManager.CurrentProfile, HypotheticalColor,
...
 
@@ -245,3 +251,9 @@ namespace DesertPaintCodex.Models
 
        }
 
        
 

	
 

	
 
        private void UpdateHypotheticalColor()
 
        {
 
            HypotheticalColor = null;
 
            HypotheticalColor = (IsAllCatalysts && (BufferReagent == null)) ? null : _recipe.BaseColor;
 
        }
 
        
Models/ReactionTestService.cs
Show inline comments
...
 
@@ -34,3 +34,3 @@ namespace DesertPaintCodex.Models
 
                    Reaction? reaction = profile.FindReaction(reagent1, reagent2);
 
                    ClipType clipType = profile.PairClipStatus(reagent1.Name, reagent2.Name);
 
                    ClipType clipType = profile.PairClipStatus(reagent1, reagent2);
 
                    
ViewModels/ReactionTestViewModel.cs
Show inline comments
...
 
@@ -12,3 +12,2 @@ using DesertPaintCodex.Util;
 
using ReactiveUI;
 
using DynamicData;
 

	
...
 
@@ -26,3 +25,4 @@ namespace DesertPaintCodex.ViewModels
 
        private readonly List<Reagent> _allPigmentList = new();
 
        public ObservableCollection<Reagent> BufferPigmentList { get; } = new();
 
        private readonly List<Reagent> _allReagentList = new();
 
        public ObservableCollection<Reagent> BufferList { get; } = new();
 

	
...
 
@@ -33,5 +33,9 @@ namespace DesertPaintCodex.ViewModels
 
            
 
            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);
 
            }
...
 
@@ -66,6 +70,19 @@ namespace DesertPaintCodex.ViewModels
 
            // 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<Reagent> 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));
 
        }
Views/MainWindow.axaml
Show inline comments
...
 
@@ -9,2 +9,3 @@
 
        MinWidth="600" MinHeight="500"
 
        Topmost="True"
 
        x:Class="DesertPaintCodex.Views.MainWindow"
Views/ReactionTestView.axaml
Show inline comments
...
 
@@ -41,5 +41,5 @@
 
                        <TextBlock Classes="ReagentLabel">Buffer:</TextBlock>
 
                        <TextBlock Classes="ReagentName" Text="{Binding ReactionTest.BufferReagent.Name, FallbackValue=[Unknown]}" IsVisible="{Binding !ReactionTest.CanScan}"/>
 
                        <ComboBox Items="{Binding BufferPigmentList}"
 
                                  IsVisible="{Binding ReactionTest.CanScan}"
 
                        <TextBlock Classes="ReagentName" Text="{Binding ReactionTest.BufferReagent.Name, FallbackValue=[Unknown]}" IsVisible="{Binding !ReactionTest.CanPickBuffer}"/>
 
                        <ComboBox Items="{Binding BufferList}"
 
                                  IsVisible="{Binding ReactionTest.CanPickBuffer}"
 
                                  SelectedItem="{Binding ReactionTest.BufferReagent}"
0 comments (0 inline, 0 general)