Added logging, reload config on OFF toggle

This commit is contained in:
2026-08-29 11:09:55 +02:00
parent b7b692fd08
commit d1d655769d
+58 -4
View File
@@ -4,6 +4,14 @@ using UnityEngine;
namespace AutoRefillFires namespace AutoRefillFires
{ {
public enum ModLogLevel
{
None = 0,
Error = 1,
Warning = 2,
Info = 3,
Debug = 4
}
public enum FuelSourcePriority public enum FuelSourcePriority
{ {
PlayerFirst, PlayerFirst,
@@ -40,6 +48,7 @@ namespace AutoRefillFires
private ConfigEntry<FuelSourcePriority> _fuelSourcePriority; private ConfigEntry<FuelSourcePriority> _fuelSourcePriority;
private ConfigEntry<bool> _onlyRefillOwnPieces; private ConfigEntry<bool> _onlyRefillOwnPieces;
private ConfigEntry<KeyboardShortcut> _toggleHotkey; private ConfigEntry<KeyboardShortcut> _toggleHotkey;
private ConfigEntry<ModLogLevel> _logLevel;
private bool _modEnabled = true; private bool _modEnabled = true;
private float _nextCheckTime; private float _nextCheckTime;
@@ -165,6 +174,13 @@ namespace AutoRefillFires
"If enabled, only refill fireplaces and torches built by the local player." "If enabled, only refill fireplaces and torches built by the local player."
); );
_logLevel = Config.Bind(
"Logging",
"LogLevel",
ModLogLevel.Info,
"Logging verbosity. Available values: None, Error, Warning, Info, Debug."
);
Logger.LogInfo("Auto Refill Fires loaded!"); Logger.LogInfo("Auto Refill Fires loaded!");
} }
@@ -174,6 +190,20 @@ namespace AutoRefillFires
{ {
_modEnabled = !_modEnabled; _modEnabled = !_modEnabled;
// Reload config when turning the mod OFF
if (!_modEnabled)
{
try
{
Config.Reload();
LogInfo("Configuration reloaded.");
}
catch (System.Exception ex)
{
LogError($"Failed to reload configuration: {ex}");
}
}
string status = _modEnabled string status = _modEnabled
? "Auto Refill Fires: ENABLED" ? "Auto Refill Fires: ENABLED"
: "Auto Refill Fires: DISABLED"; : "Auto Refill Fires: DISABLED";
@@ -188,7 +218,7 @@ namespace AutoRefillFires
); );
} }
Logger.LogInfo(status); LogInfo(status);
} }
if (!_modEnabled) if (!_modEnabled)
@@ -366,7 +396,7 @@ namespace AutoRefillFires
if (fuelAdded > 0) if (fuelAdded > 0)
{ {
Logger.LogInfo( LogInfo(
$"Refilled {fireplace.name}: " + $"Refilled {fireplace.name}: " +
$"{currentFuel:0.0}/{maxFuel:0.0}, " + $"{currentFuel:0.0}/{maxFuel:0.0}, " +
$"fuel={fuelName}, " + $"fuel={fuelName}, " +
@@ -394,7 +424,7 @@ namespace AutoRefillFires
1 1
); );
Logger.LogDebug( LogDebug(
$"Fuel {fuelName} taken from player inventory. " + $"Fuel {fuelName} taken from player inventory. " +
$"Remaining: {availableFuel - 1}" $"Remaining: {availableFuel - 1}"
); );
@@ -508,7 +538,7 @@ namespace AutoRefillFires
1 1
); );
Logger.LogDebug( LogDebug(
$"Fuel {fuelName} taken from container " + $"Fuel {fuelName} taken from container " +
$"{closestContainer.name} " + $"{closestContainer.name} " +
$"({closestDistance:0.0}m). " + $"({closestDistance:0.0}m). " +
@@ -517,5 +547,29 @@ namespace AutoRefillFires
return true; return true;
} }
private void LogDebug(string message)
{
if (_logLevel.Value >= ModLogLevel.Debug)
Logger.LogDebug(message);
}
private void LogInfo(string message)
{
if (_logLevel.Value >= ModLogLevel.Info)
Logger.LogInfo(message);
}
private void LogWarning(string message)
{
if (_logLevel.Value >= ModLogLevel.Warning)
Logger.LogWarning(message);
}
private void LogError(string message)
{
if (_logLevel.Value >= ModLogLevel.Error)
Logger.LogError(message);
}
} }
} }