45 lines
1.3 KiB
C#
Raw Normal View History

2021-09-07 17:45:49 +01:00
using QuestValidator.Common.Helpers;
using QuestValidator.Common.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
namespace QuestValidator.Common
{
public static class LiveQuestHelper
{
private static Dictionary<string, Item> _itemCache;
public static Dictionary<string, Item> Items
{
get
{
2022-01-09 20:35:43 +00:00
if (_itemCache is null)
2021-09-07 17:45:49 +01:00
{
var itemsFilePath = $"{Directory.GetCurrentDirectory()}\\Assets\\items.json";
if (!File.Exists(itemsFilePath))
{
throw new Exception($"Missing items.json under assets ({itemsFilePath})");
}
var itemsJson = File.ReadAllText(itemsFilePath);
_itemCache = JsonSerializer.Deserialize<Dictionary<string, Item>>(itemsJson);
}
return _itemCache;
}
}
public static Item GetTemplateById(string templateId)
{
if (Items.ContainsKey(templateId))
{
return Items[templateId];
}
LoggingHelpers.LogToConsole($"Could not locate item template with id {templateId}", ConsoleColor.Red);
return null;
}
}
}