78 lines
2.3 KiB
C#
Raw Normal View History

2021-09-10 17:57:24 +01:00
using AssortValidator.Common.Helpers;
using AssortValidator.Common.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
namespace AssortValidator.Common
{
public static class ItemTemplateHelper
{
private static Dictionary<string, ItemLookup> _itemCache;
public static Dictionary<string, ItemLookup> Items
{
get
{
if (_itemCache == null)
{
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, ItemLookup>>(itemsJson);
}
return _itemCache;
}
}
public static ItemLookup GetTemplateById(string templateId)
{
if (templateId == "5449016a4bdc2d6f028b456f")
{
return new ItemLookup
{
_id = templateId,
_name = "Roubles",
_parent = "543be5dd4bdc2deb348b4569",
_type = ""
};
}
if (templateId == "569668774bdc2da2298b4568")
{
return new ItemLookup
{
_id = templateId,
_name = "Euros",
_parent = "543be5dd4bdc2deb348b4569",
_type = ""
};
}
if (templateId == "5696686a4bdc2da3298b456a")
{
return new ItemLookup
{
_id = templateId,
_name = "Dollars",
_parent = "543be5dd4bdc2deb348b4569",
_type = ""
};
}
if (Items.ContainsKey(templateId))
{
return Items[templateId];
}
LoggingHelpers.LogToConsole($"Could not locate item template with id {templateId}", ConsoleColor.Red);
return null;
}
}
}