Initial commit. Load list of cards via config (packs or single cards).
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using ArkhamPnP.Data;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ArkhamPnP
|
||||
{
|
||||
internal class ConfigLoader
|
||||
{
|
||||
private string path;
|
||||
|
||||
public ConfigLoader(string path)
|
||||
{
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public async Task<List<Card>> LoadCards()
|
||||
{
|
||||
var result = new List<Card>();
|
||||
var api = new ArkhamDBApi();
|
||||
var doc = LoadConfig(path);
|
||||
foreach (var item in doc.RootElement.EnumerateArray())
|
||||
{
|
||||
var type = item.GetProperty("type").GetString();
|
||||
if (type == "card")
|
||||
{
|
||||
result.Add(await api.GetCard(item.GetProperty("id").GetString()));
|
||||
}
|
||||
else if (type == "pack")
|
||||
{
|
||||
var pack = await api.GetPack(item.GetProperty("code").GetString());
|
||||
foreach (var c in pack)
|
||||
{
|
||||
if (c.IsPlayerCard) result.Add(c);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Unknown config item type: " + type);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
JsonDocument LoadConfig(string path)
|
||||
{
|
||||
string configStr = File.ReadAllText(path);
|
||||
return JsonDocument.Parse(configStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user