From e6b57ca757b4b13dc143c75da0fcc6ccc07789d7 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Thu, 18 Jun 2026 15:43:38 -0400 Subject: Reduce isSet usage to only asserts Signed-off-by: Andrew Opalach --- Plugin.cs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Plugin.cs b/Plugin.cs index 828d305..84269f5 100755 --- a/Plugin.cs +++ b/Plugin.cs @@ -5,6 +5,7 @@ using System.Numerics; using System.Globalization; +using System.Runtime.CompilerServices; #if ENABLE_ASSERTS using System.Diagnostics; #endif @@ -52,8 +53,14 @@ namespace WorldTuningTool public string Name => "World Tuning Tool"; public string Author => "Akon City Software"; - private static void Assert(bool condition) + private static bool loggedAssertFailed = false; + private static void Assert(bool condition, [CallerLineNumber] int line = 0) { + if (!condition && !loggedAssertFailed) + { + Log.Error($"Assert failed on line {line}."); + loggedAssertFailed = true; + } #if ENABLE_ASSERTS Trace.Assert(condition); #endif @@ -1164,10 +1171,10 @@ namespace WorldTuningTool public void Draw(bool forPreset, List? currentOverrides, List? stageOverrides, List? globalOverrides, bool superseded, float width) { + Assert(!superseded == isSet); bool fade = superseded; if (fade) { - Assert(!isSet); ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * 0.5f); } if (currentOverrides == null) @@ -1187,8 +1194,7 @@ namespace WorldTuningTool if (ImGui.Selectable(iterParam.Name, isSelected)) { BeginTransition(); - bool wasSet = isSet; - if (wasSet) + if (!superseded) { Unset(); if (Param != null) @@ -1244,6 +1250,7 @@ namespace WorldTuningTool selectedOrderChanged = true; } EndTransition(); + Assert(!superseded == isSet); } if (isSelected) ImGui.SetItemDefaultFocus(); } @@ -1260,7 +1267,7 @@ namespace WorldTuningTool ImGui.SameLine(); if (Param.DrawValue(ref valueV, ref valueInt, width, false)) { - if (isSet) + if (!superseded) { Param.OverrideValue(valueV, valueInt); } @@ -1268,14 +1275,14 @@ namespace WorldTuningTool (Vector4 v4, int i1) = Param.GetValue(); bool valueDiffers = (valueV, valueInt) != (v4, i1); bool valueNotSaved = (valueV, valueInt) != (sValueV, sValueInt); - if ((!Param.PendingUpdate() && valueDiffers && isSet) || valueNotSaved) + if ((!Param.PendingUpdate() && valueDiffers && !superseded) || valueNotSaved) { ImGui.SameLine(); if (ImGui.Button("⇄")) { valueV = sValueV; valueInt = sValueInt; - if (isSet) + if (!superseded) { Param.OverrideValue(valueV, valueInt); } -- cgit v1.2.3-101-g0448