using System; using System.IO; using UnityEngine; namespace ModTool.Shared { /// /// Class that stores a Mod's name, author, description, version, path and supported platforms. /// [Serializable] public class ModInfo { /// /// Name /// public string name { get { return _name; } } /// /// Supported platforms for this mod. /// public ModPlatform platforms { get { return _platforms; } } /// /// The Mod's available content types. /// public ModContent content { get { return _content; } } /// /// Mod author. /// public string author { get { return _author; } } /// /// Mod description. /// public string description { get { return _description; } } /// /// Mod version. /// public string version { get { return _version; } } /// /// The version of Unity that was used to export this mod. /// public string unityVersion { get { return _unityVersion; } } /// /// The version of Unity that was used to export this mod. /// public string creationDate { get { return _creationDate; } } /// /// Should this mod be enabled. /// public bool isEnabled { get { return _isEnabled; } set { _isEnabled = value; } } /// /// Location of mod /// public string path { get; private set; } [SerializeField] private string _name; [SerializeField] private string _author; [SerializeField] private string _description; [SerializeField] private string _version; [SerializeField] private string _unityVersion; [SerializeField] private string _creationDate; [SerializeField] private ModPlatform _platforms; [SerializeField] private ModContent _content; [SerializeField] private bool _isEnabled; /// /// Initialize a new ModInfo. /// /// The Mod's name. /// The Mod's author. /// The Mod's description. /// The Mod's supported platforms. /// The Mod's available content types. /// The Mod's version /// The version of Unity that the Mod was exported with. /// The date this was created. public ModInfo( string name, string author, string description, string version, string unityVersion, ModPlatform platforms, ModContent content) { _author = author; _description = description; _name = name; _platforms = platforms; _content = content; _version = version; _unityVersion = unityVersion; _creationDate = creationDate; isEnabled = false; } /// /// Save this ModInfo. /// public void Save() { if (!string.IsNullOrEmpty(path)) Save(path, this); } /// /// Save a ModInfo. /// /// The path to save the ModInfo to. /// The ModInfo to save. public static void Save(string path, ModInfo modInfo) { string json = JsonUtility.ToJson(modInfo, true); File.WriteAllText(path, json); } /// /// Load a ModInfo. /// /// The path to load the ModInfo from. /// The loaded Modinfo, if succeeded. Null otherwise. public static ModInfo Load(string path) { path = Path.GetFullPath(path); if (File.Exists(path)) { try { string json = File.ReadAllText(path); ModInfo modInfo = JsonUtility.FromJson(json); modInfo.path = path; return modInfo; } catch(Exception e) { LogUtility.LogWarning("There was an issue while loading the ModInfo from " + path + " - " + e.Message); } } return null; } } }