Files
@ d6859ea7177f
Branch filter:
Location: ATITD-Tools/Desert-Paint-Codex/Services/ProfileManager.cs - annotation
d6859ea7177f
2.7 KiB
text/x-csharp
Add some sanity checks on min/max concentration and min/max reagents in recipe generation. Also, clear out the search queue when generation has finished so the queue isn't loaded next time. This fixes the start/resume button state when entering the recipe generator after a prior run had finished.
40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 a5faa82faf6a a5faa82faf6a a5faa82faf6a a5faa82faf6a a5faa82faf6a a5faa82faf6a 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 |
using System;
using DesertPaintCodex.Models;
using DesertPaintCodex.Util;
using System.Collections.Generic;
using System.IO;
namespace DesertPaintCodex.Services
{
internal static class ProfileManager
{
private static bool _areProfilesLoaded;
private static readonly List<string> _profileList = new();
public static PlayerProfile? CurrentProfile { get; private set; }
public static bool HasProfileLoaded => CurrentProfile != null;
public static List<string> GetProfileList()
{
// If it's already loaded, return the cached list.
if (_areProfilesLoaded)
{
return _profileList;
}
// Otherwise, load the list.
string appDataPath = FileUtils.AppDataPath;
if (!Directory.Exists(appDataPath))
{
Directory.CreateDirectory(appDataPath);
}
DirectoryInfo di = new(appDataPath);
DirectoryInfo[] dirs = di.GetDirectories();
foreach (DirectoryInfo dir in dirs)
{
if (dir.Name != "template")
{
_profileList.Add(dir.Name);
}
}
_areProfilesLoaded = true;
return _profileList;
}
public static PlayerProfile LoadProfile(string name)
{
CurrentProfile = new PlayerProfile(name, Path.Combine(FileUtils.AppDataPath, name));
CurrentProfile.Load();
return CurrentProfile;
}
public static void ReloadProfile()
{
if (CurrentProfile == null) return;
LoadProfile(CurrentProfile.Name);
}
public static PlayerProfile CreateNewProfile(string name)
{
CurrentProfile = new PlayerProfile(name, Path.Combine(FileUtils.AppDataPath, name));
CurrentProfile.Initialize();
// Invalidate profile list, so it will reload next time.
_profileList.Clear();
_areProfilesLoaded = false;
return CurrentProfile;
}
public static int GetProfileCount()
{
// This is a function instead of a property, because it may be slow.
List<string> profiles = GetProfileList();
return profiles.Count;
}
public static bool HasProfiles()
{
// This is a function instead of a property, because it may be slow.
List<string> profiles = GetProfileList();
return profiles.Count > 0;
}
public static void UnloadProfile()
{
CurrentProfile = null;
}
}
}
|