diff options
| author | 2026-06-18 15:43:38 -0400 | |
|---|---|---|
| committer | 2026-06-18 15:43:38 -0400 | |
| commit | e6b57ca757b4b13dc143c75da0fcc6ccc07789d7 (patch) | |
| tree | 1251cde65fb52ba327bfc9a6f08ba24321d764d6 /Plugin.cs | |
| parent | a7faa4efcadc0b6937e53a26ba8b4cd89d3998c7 (diff) | |
| download | WorldTuningTool-e6b57ca757b4b13dc143c75da0fcc6ccc07789d7.tar.gz WorldTuningTool-e6b57ca757b4b13dc143c75da0fcc6ccc07789d7.tar.bz2 WorldTuningTool-e6b57ca757b4b13dc143c75da0fcc6ccc07789d7.zip | |
Reduce isSet usage to only asserts
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'Plugin.cs')
| -rwxr-xr-x | Plugin.cs | 21 |
1 files changed, 14 insertions, 7 deletions
@@ -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<Override>? currentOverrides, List<Override>? stageOverrides, List<Override>? 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);
}
|