PalacePal/Pal.Client/Configuration/ConfigurationV7.cs

60 lines
1.9 KiB
C#
Raw Normal View History

2023-02-15 01:38:04 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
2023-02-15 22:17:19 +00:00
using Pal.Client.Net;
2023-02-15 01:38:04 +00:00
2023-02-15 22:51:35 +00:00
namespace Pal.Client.Configuration
2023-02-15 01:38:04 +00:00
{
2023-02-15 22:51:35 +00:00
public sealed class ConfigurationV7 : IPalacePalConfiguration, IConfigurationInConfigDirectory
2023-02-15 01:38:04 +00:00
{
2023-02-15 22:51:35 +00:00
public int Version { get; set; } = 7;
public bool FirstUse { get; set; } = true;
public EMode Mode { get; set; }
public string BetaKey { get; init; } = "";
public DeepDungeonConfiguration DeepDungeons { get; set; } = new();
public RendererConfiguration Renderer { get; set; } = new();
public List<AccountConfigurationV7> Accounts { get; set; } = new();
[JsonIgnore]
[Obsolete]
public List<ConfigurationV1.ImportHistoryEntry> ImportHistory { get; set; } = new();
public IAccountConfiguration CreateAccount(string server, Guid accountId)
{
var account = new AccountConfigurationV7(server, accountId);
Accounts.Add(account);
return account;
}
[Obsolete("for V1 import")]
internal IAccountConfiguration CreateAccount(string server, string accountId)
{
var account = new AccountConfigurationV7(server, accountId);
Accounts.Add(account);
return account;
}
public IAccountConfiguration? FindAccount(string server)
{
return Accounts.FirstOrDefault(a => a.Server == server && a.IsUsable);
}
public void RemoveAccount(string server)
{
Accounts.RemoveAll(a => a.Server == server && a.IsUsable);
}
public bool HasRoleOnCurrentServer(string role)
{
if (Mode != EMode.Online)
return false;
var account = FindAccount(RemoteApi.RemoteUrl);
return account == null || account.CachedRoles.Contains(role);
}
2023-02-15 22:17:19 +00:00
}
2023-02-15 01:38:04 +00:00
}