Added Options For Debugging

This commit is contained in:
Ben C 2022-02-24 17:37:43 -05:00
parent 9b0d90ca9a
commit 0bd11129b2
3 changed files with 99 additions and 3 deletions

View File

@ -18,9 +18,11 @@ using OWML.Common;
using OWML.ModHelper; using OWML.ModHelper;
using OWML.Utils; using OWML.Utils;
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using OWML.Common.Menus;
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using Logger = NewHorizons.Utility.Logger; using Logger = NewHorizons.Utility.Logger;
@ -32,10 +34,14 @@ namespace NewHorizons
public static AssetBundle ShaderBundle; public static AssetBundle ShaderBundle;
public static Main Instance { get; private set; } public static Main Instance { get; private set; }
public static bool Debug;
private static IModButton _reloadButton;
public static Dictionary<string, NewHorizonsSystem> SystemDict = new Dictionary<string, NewHorizonsSystem>(); public static Dictionary<string, NewHorizonsSystem> SystemDict = new Dictionary<string, NewHorizonsSystem>();
public static Dictionary<string, List<NewHorizonsBody>> BodyDict = new Dictionary<string, List<NewHorizonsBody>>(); public static Dictionary<string, List<NewHorizonsBody>> BodyDict = new Dictionary<string, List<NewHorizonsBody>>();
public static List<NewHorizonsBody> NextPassBodies = new List<NewHorizonsBody>(); public static List<NewHorizonsBody> NextPassBodies = new List<NewHorizonsBody>();
public static Dictionary<string, AssetBundle> AssetBundles = new Dictionary<string, AssetBundle>(); public static Dictionary<string, AssetBundle> AssetBundles = new Dictionary<string, AssetBundle>();
public static List<IModBehaviour> MountedAddons = new List<IModBehaviour>();
public static float FurthestOrbit { get; set; } = 50000f; public static float FurthestOrbit { get; set; } = 50000f;
public StarLightController StarLightController { get; private set; } public StarLightController StarLightController { get; private set; }
@ -45,6 +51,7 @@ namespace NewHorizons
public string CurrentStarSystem { get { return Instance._currentStarSystem; } } public string CurrentStarSystem { get { return Instance._currentStarSystem; } }
private bool _isChangingStarSystem = false; private bool _isChangingStarSystem = false;
private bool _firstLoad = true;
public bool IsWarping { get; private set; } = false; public bool IsWarping { get; private set; } = false;
public bool WearingSuit { get; private set; } = false; public bool WearingSuit { get; private set; } = false;
@ -57,10 +64,35 @@ namespace NewHorizons
return new NewHorizonsApi(); return new NewHorizonsApi();
} }
public override void Configure(IModConfig config)
{
Debug = config.GetSettingsValue<bool>("Debug");
UpdateReloadButton();
string logLevel = config.GetSettingsValue<string>("LogLevel");
Logger.LogType logType;
switch (logLevel)
{
case "Info":
logType = Logger.LogType.Log;
break;
case "Warning":
logType = Logger.LogType.Warning;
break;
case "Critical":
logType = Logger.LogType.Error;
break;
default:
logType = Logger.LogType.Error;
break;
}
Logger.UpdateLogLevel(logType);
}
public void Start() public void Start()
{ {
SceneManager.sceneLoaded += OnSceneLoaded; SceneManager.sceneLoaded += OnSceneLoaded;
Instance = this; Instance = this;
Logger.LogWarning(MountedAddons.ToString());
GlobalMessenger<DeathType>.AddListener("PlayerDeath", OnDeath); GlobalMessenger<DeathType>.AddListener("PlayerDeath", OnDeath);
ShaderBundle = Main.Instance.ModHelper.Assets.LoadBundle("AssetBundle/shader"); ShaderBundle = Main.Instance.ModHelper.Assets.LoadBundle("AssetBundle/shader");
BodyDict["SolarSystem"] = new List<NewHorizonsBody>(); BodyDict["SolarSystem"] = new List<NewHorizonsBody>();
@ -83,7 +115,49 @@ namespace NewHorizons
} }
Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => OnSceneLoaded(SceneManager.GetActiveScene(), LoadSceneMode.Single)); Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => OnSceneLoaded(SceneManager.GetActiveScene(), LoadSceneMode.Single));
Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => _firstLoad = false);
Instance.ModHelper.Menus.PauseMenu.OnInit += InitializePauseMenu;
} }
#region Reloading
private void InitializePauseMenu()
{
_reloadButton = ModHelper.Menus.PauseMenu.OptionsButton.Duplicate("RELOAD CONFIGS");
_reloadButton.OnClick += ReloadConfigs;
UpdateReloadButton();
}
private void UpdateReloadButton()
{
if (_reloadButton != null)
{
if (Debug) _reloadButton.Show();
else _reloadButton.Hide();
}
}
private void ReloadConfigs()
{
BodyDict["SolarSystem"] = new List<NewHorizonsBody>();
SystemDict["SolarSystem"] = new NewHorizonsSystem("SolarSystem", new StarSystemConfig(null), this);
Logger.Log("Begin reload of config files...", Logger.LogType.Log);
try
{
foreach (IModBehaviour mountedAddon in MountedAddons)
{
LoadConfigs(mountedAddon);
}
}
catch (Exception)
{
Logger.LogWarning("Error While Reloading");
}
ChangeCurrentStarSystem(_currentStarSystem);
}
#endregion
public void OnDestroy() public void OnDestroy()
{ {
@ -350,6 +424,10 @@ namespace NewHorizons
#region Load #region Load
public void LoadConfigs(IModBehaviour mod) public void LoadConfigs(IModBehaviour mod)
{ {
if (_firstLoad)
{
MountedAddons.Add(mod);
}
var folder = mod.ModHelper.Manifest.ModFolderPath; var folder = mod.ModHelper.Manifest.ModFolderPath;
if(Directory.Exists(folder + "planets")) if(Directory.Exists(folder + "planets"))
{ {

View File

@ -7,6 +7,14 @@ namespace NewHorizons.Utility
{ {
public static class Logger public static class Logger
{ {
private static LogType _logLevel = LogType.Error;
public static void UpdateLogLevel(LogType newLevel)
{
_logLevel = newLevel;
}
public static void LogProperties(UnityEngine.Object obj) public static void LogProperties(UnityEngine.Object obj)
{ {
foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(obj)) foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(obj))
@ -34,6 +42,7 @@ namespace NewHorizons.Utility
public static void Log(string text, LogType type) public static void Log(string text, LogType type)
{ {
if ((int) type < (int) _logLevel) return;
Main.Instance.ModHelper.Console.WriteLine(Enum.GetName(typeof(LogType), type) + " : " + text, LogTypeToMessageType(type)); Main.Instance.ModHelper.Console.WriteLine(Enum.GetName(typeof(LogType), type) + " : " + text, LogTypeToMessageType(type));
} }
@ -51,10 +60,10 @@ namespace NewHorizons.Utility
} }
public enum LogType public enum LogType
{ {
Todo,
Log, Log,
Error,
Warning, Warning,
Todo Error,
} }
private static MessageType LogTypeToMessageType(LogType t) private static MessageType LogTypeToMessageType(LogType t)
{ {

View File

@ -1,3 +1,12 @@
{ {
"enabled": true "enabled": true,
"settings": {
"Debug": false,
"LogLevel": {
"type": "selector",
"value": "Critical",
"options": ["Info", "Warning", "Critical"],
"title": "Log Type"
}
}
} }