49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text.Json;
|
|
|
|
namespace MarketPriceLookup.Common.Helpers
|
|
{
|
|
public static class HandbookHelper
|
|
{
|
|
private static Handbook _handbook;
|
|
|
|
public static Handbook Items
|
|
{
|
|
get
|
|
{
|
|
if (_handbook == null)
|
|
{
|
|
var itemsFilePath = $"{Directory.GetCurrentDirectory()}\\Assets\\handbook.json";
|
|
if (!File.Exists(itemsFilePath))
|
|
{
|
|
throw new Exception($"Missing handbook.json under assets ({itemsFilePath})");
|
|
}
|
|
|
|
var handbookJson = File.ReadAllText(itemsFilePath);
|
|
_handbook = JsonSerializer.Deserialize<Handbook>(handbookJson);
|
|
}
|
|
|
|
return _handbook;
|
|
}
|
|
}
|
|
|
|
public static HandbookItem GetItem(string id)
|
|
{
|
|
return Items.Items.FirstOrDefault(x => x.Id == id);
|
|
}
|
|
|
|
public static HandbookCategory GetCategory(string id)
|
|
{
|
|
return Items.Categories.FirstOrDefault(x => x.Id == id);
|
|
}
|
|
}
|
|
|
|
public class Handbook
|
|
{
|
|
public HandbookCategory[] Categories { get; set; }
|
|
public HandbookItem[] Items { get; set; }
|
|
}
|
|
}
|