Changeset - 8ee5f618b07c
[Not reviewed]
Merge default
0 1 0
Tess Snider (Malkyne) - 3 years ago 2021-07-26 08:16:19
this@malkyne.org
Merge
1 file changed with 10 insertions and 9 deletions:
0 comments (0 inline, 0 general)
ViewModels/RecipeGeneratorViewModel.cs
Show inline comments
...
 
@@ -4,37 +4,37 @@ using System.Collections.Generic;
 
using System.Collections.ObjectModel;
 
using System.Diagnostics;
 
using System.Threading.Tasks;
 
using Avalonia.Threading;
 
using DesertPaintCodex.Models;
 
using DesertPaintCodex.Services;
 
using ReactiveUI;
 

	
 
namespace DesertPaintCodex.ViewModels
 
{
 
    public class RecipeGeneratorViewModel : ViewModelBase
 
    {
 
        private const long   UpdateInterval  = 2000;  // ms
 
        private const long   UpdateInterval  = 200;  // ms
 
        private const long   SaveInterval    = 30000; // ms
 
        private const string PaintStateFile  = "dp_generator_state";
 
        private const string RibbonStateFile = "dp_generator_ribbon_state";
 
        
 
        private int _selectedView = 0;
 
        public int SelectedView { get => _selectedView; private set => this.RaiseAndSetIfChanged(ref _selectedView, value); }
 
        
 
        private float _progress = 0;
 
        public float Progress { get => _progress; private set => this.RaiseAndSetIfChanged(ref _progress, value); }
 

	
 
        private int _permutationCount = 0;
 
        public int PermutationCount { get => _permutationCount; private set => this.RaiseAndSetIfChanged(ref _permutationCount, value); }
 
        private string _permutationCount = "0";
 
        public string PermutationCount { get => _permutationCount; private set => this.RaiseAndSetIfChanged(ref _permutationCount, value); }
 
        
 

	
 
        private DateTime _mostRecentTime;
 
        public DateTime MostRecentTime { get => _mostRecentTime; private set => this.RaiseAndSetIfChanged(ref _mostRecentTime, value); }
 

	
 
        private GeneratorRecipe? _mostRecentRecipe;
 
        public GeneratorRecipe? MostRecentRecipe { get => _mostRecentRecipe; private set => this.RaiseAndSetIfChanged(ref _mostRecentRecipe, value); }
 

	
 

	
 
        private int _productIndex = 0;
 
        public int ProductIndex { get => _productIndex; private set => this.RaiseAndSetIfChanged(ref _productIndex, value); }
 

	
...
 
@@ -234,34 +234,35 @@ namespace DesertPaintCodex.ViewModels
 
        }
 

	
 
        private void InitState(string mode, uint minConcentration, Dictionary<string, PaintRecipe> recipes, string stateFileName)
 
        {
 
            _minConcentration = minConcentration;
 
            _generator.InitRecipes(recipes);
 
            
 
            string stateFile = System.IO.Path.Combine(_profile.Directory, stateFileName);
 
            if (System.IO.File.Exists(stateFile))
 
            {
 
                _generator.LoadState(stateFile);
 
                
 
                // Always set these, or the values will be invalid
 
                MaxReagents = (int)_generator.MaxReagents;
 
                MaxConcentration = (int)_generator.MaxConcentration;
 
                FullQuantity = (int)_generator.FullQuantity;
 
                FullQuantityDepth = (int)_generator.FullQuantityDepth;
 

	
 
                if (_generator.CanResume)
 
                {
 
                    IsInProgress = true;
 
                    IsPaused = true;
 

	
 
                    MaxReagents       = (int) _generator.MaxReagents;
 
                    MaxConcentration  = (int) _generator.MaxConcentration;
 
                    FullQuantity      = (int) _generator.FullQuantity;
 
                    FullQuantityDepth = (int) _generator.FullQuantityDepth;
 
                    
 
                    SaveSettings(mode);
 
                }
 
                else
 
                {
 
                    IsInProgress = false;
 
                    IsPaused = false;
 
                    CanClear = true;
 
                }
 
            }
 
            else if (mode == "Paint")
 
            {
 
                LoadPaintSettings();
...
 
@@ -317,25 +318,25 @@ namespace DesertPaintCodex.ViewModels
 
        }
 

	
 
        private void Update(object? sender, EventArgs e)
 
        {
 
            if (!_updatesAvailable) return;
 
            if (_saving) return;
 

	
 
            _updatesAvailable = false;
 

	
 
            DateTime now = DateTime.Now;
 
            
 
            // Update test count.
 
            PermutationCount = _newRecipeCount;
 
            PermutationCount = $"{_newRecipeCount:n0}";
 
            
 
            // Pull in new recipes.
 
            if (!_pendingNewRecipes.IsEmpty)
 
            {
 
                GeneratorRecipe? lastRecipe = null;
 
                while (_pendingNewRecipes.TryDequeue(out PaintRecipe? newRecipe))
 
                {
 
                    string recipeColor = PaletteService.FindNearest(newRecipe.ReactedColor);
 
                    foreach (GeneratorRecipe recipe in AllRecipes)
 
                    {
 
                        if (recipe.Color.Name != recipeColor) continue;
 
                        recipe.DraftRecipe(newRecipe);
0 comments (0 inline, 0 general)