Files
flowframes/Code/Data/ModelCollection.cs

64 lines
1.9 KiB
C#
Raw Normal View History

2021-05-17 11:46:49 +02:00
using Flowframes.IO;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
namespace Flowframes.Data
{
public class ModelCollection
2021-05-17 11:46:49 +02:00
{
public AI ai;
public List<ModelInfo> models;
public class ModelInfo
{
public AI ai;
public string name;
public string desc;
public string dir;
2021-06-15 16:16:44 +02:00
public bool supportsAlpha;
2021-05-17 11:46:49 +02:00
public bool isDefault;
2021-06-15 16:16:44 +02:00
public ModelInfo(AI ai, string name, string desc, string dir, bool supportsAlpha, bool isDefault)
2021-05-17 11:46:49 +02:00
{
this.ai = ai;
this.name = name;
this.desc = desc;
this.dir = dir;
2021-06-15 16:16:44 +02:00
this.supportsAlpha = supportsAlpha;
2021-05-17 11:46:49 +02:00
this.isDefault = isDefault;
}
public string GetUiString()
{
return $"{name} - {desc}{(isDefault ? " (Recommended)" : "")}";
}
public override string ToString()
{
return $"{name} - {desc} ({dir}){(isDefault ? " (Recommended)" : "")}";
}
}
public ModelCollection(AI ai, string jsonContentOrPath)
{
if (IOUtils.IsPathValid(jsonContentOrPath) && File.Exists(jsonContentOrPath))
jsonContentOrPath = File.ReadAllText(jsonContentOrPath);
models = new List<ModelInfo>();
dynamic data = JsonConvert.DeserializeObject(jsonContentOrPath);
foreach (var item in data)
{
2021-06-15 16:16:44 +02:00
bool alpha = false;
bool.TryParse((string)item.supportsAlpha, out alpha);
2021-05-17 11:46:49 +02:00
bool def = false;
bool.TryParse((string)item.isDefault, out def);
2021-06-15 16:16:44 +02:00
models.Add(new ModelInfo(ai, (string)item.name, (string)item.desc, (string)item.dir, alpha, def));
2021-05-17 11:46:49 +02:00
}
}
}
}