38 lines
No EOL
1.1 KiB
C#
38 lines
No EOL
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
public static class ItemLoader
|
|
{
|
|
public static List<Item> LoadAllItems(string path)
|
|
{
|
|
//Check to see if the file exists. If not, just create a blank List.
|
|
if (!File.Exists(path))
|
|
{
|
|
return new List<Item>();
|
|
}
|
|
|
|
//Dump the entirely of the file into a string.
|
|
string json = File.ReadAllText(path);
|
|
|
|
//Create a new variable with our custom JSON serializer settings that allows us to make mixed Lists.
|
|
var settings = new JsonSerializerSettings
|
|
{
|
|
Converters = { new ItemConverter() }
|
|
};
|
|
|
|
//Return a list with different Items mixed in, or return a blank list.
|
|
return JsonConvert.DeserializeObject<List<Item>>(json, settings) ?? new List<Item>();
|
|
}
|
|
|
|
//Returns all the HealingItems in a list.
|
|
public static List<HealingItem> LoadHealingItemsFromList(List<Item> input)
|
|
{
|
|
List<HealingItem> healingitems = input
|
|
.OfType<HealingItem>()
|
|
.ToList();
|
|
return healingitems;
|
|
}
|
|
} |