fix(rynthai): keep pet refill, monster blacklist and radar placement on profile load
Loading a profile (login, profile switch) copies the file into the live settings field by field in CopySettings, which had no line for PetAutoRefill, MonsterNameBlacklist or RadarPosX/Y / RadarSizeX/Y. The defaults stayed in memory and the next autosave wrote them over the profile. Copy them, and add ProfileLoadTests, which fails for any serialized field CopySettings leaves out. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
0daf0a44a3
commit
a86883e781
4 changed files with 172 additions and 1 deletions
29
Changelog/2026-10-08-fix-profile-load-copy-settings.md
Normal file
29
Changelog/2026-10-08-fix-profile-load-copy-settings.md
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# RynthAi - settings dropped when a profile loads - 2026-10-08
|
||||
|
||||
## Fixed
|
||||
|
||||
- Loading a profile (at login and on a profile switch) copies the profile file into the live
|
||||
settings one field at a time (`LegacyDashboardRenderer.CopySettings`). Fields with no copy line
|
||||
kept their in-memory defaults, and the next autosave wrote those defaults over the file, so
|
||||
these settings reset on every login:
|
||||
- "Refill empty essences with Encapsulated Spirit" (`PetAutoRefill`);
|
||||
- the Monster Blacklist (`MonsterNameBlacklist`, Advanced, Combat);
|
||||
- the radar window's saved position and size (`RadarPosX/Y`, `RadarSizeX/Y`).
|
||||
- A profile with a `null` monster blacklist loads an empty list.
|
||||
|
||||
## Files
|
||||
|
||||
- `Plugins/RynthCore.Plugin.RynthAi/LegacyUi/LegacyDashboardRenderer.cs`: the copy lines. The
|
||||
comment that claimed the source generator guaranteed full coverage now points at the test.
|
||||
- `Tools/RynthCore.RynthAiHostTests/Tests/ProfileLoadTests.cs` (new):
|
||||
- every serialized `LegacyUiSettings` member set to a non-default value must come through
|
||||
`CopySettings`, so a field added later without a copy line fails the run;
|
||||
- settings written to a profile file and loaded back serialize unchanged.
|
||||
- `Tools/RynthCore.RynthAiHostTests/Program.cs`: registers `ProfileLoadTests`.
|
||||
|
||||
## Checks
|
||||
|
||||
- Without the copy lines, the new tests fail and name the six dropped fields; with them, both
|
||||
pass.
|
||||
- RynthAi host tests: 552 passed, 4 known failures, 1 failure (the map bake, which needs the
|
||||
real dat files on the machine).
|
||||
|
|
@ -1561,7 +1561,9 @@ internal sealed class LegacyDashboardRenderer
|
|||
var tmp = JsonSerializer.Deserialize(json, RynthAiJsonContext.Default.LegacyUiSettings);
|
||||
if (tmp == null) return;
|
||||
|
||||
// Copy all serialized fields manually (the source generator guarantees coverage)
|
||||
// Every serialized field must be listed here, or loading a profile silently drops it and
|
||||
// the next autosave writes the default back. "profile: every saved setting survives
|
||||
// loading" (RynthAiHostTests, ProfileLoadTests) fails for any field that is missing.
|
||||
dst.EnableBuffing = tmp.EnableBuffing;
|
||||
dst.EnableCombat = tmp.EnableCombat;
|
||||
dst.EnableNavigation = tmp.EnableNavigation;
|
||||
|
|
@ -1666,6 +1668,7 @@ internal sealed class LegacyDashboardRenderer
|
|||
dst.SummonPets = tmp.SummonPets;
|
||||
dst.CustomPetRange = tmp.CustomPetRange;
|
||||
dst.PetMinMonsters = tmp.PetMinMonsters;
|
||||
dst.PetAutoRefill = tmp.PetAutoRefill;
|
||||
dst.AdvancedOptions = tmp.AdvancedOptions;
|
||||
dst.MineOnly = tmp.MineOnly;
|
||||
dst.ShowEditor = tmp.ShowEditor;
|
||||
|
|
@ -1715,6 +1718,7 @@ internal sealed class LegacyDashboardRenderer
|
|||
dst.TargetFPSBackground = tmp.TargetFPSBackground;
|
||||
// MonsterRule deep-copy preserves Category + MatchExpression via JSON round-trip
|
||||
dst.MonsterRules = tmp.MonsterRules;
|
||||
dst.MonsterNameBlacklist = tmp.MonsterNameBlacklist ?? new();
|
||||
dst.ItemRules = tmp.ItemRules;
|
||||
dst.ConsumableRules = tmp.ConsumableRules;
|
||||
dst.BuffRules = tmp.BuffRules;
|
||||
|
|
@ -1803,6 +1807,10 @@ internal sealed class LegacyDashboardRenderer
|
|||
dst.RadarWallPaintRadius = tmp.RadarWallPaintRadius;
|
||||
dst.RadarCircular = tmp.RadarCircular;
|
||||
dst.RadarClickThrough = tmp.RadarClickThrough;
|
||||
dst.RadarPosX = tmp.RadarPosX;
|
||||
dst.RadarPosY = tmp.RadarPosY;
|
||||
dst.RadarSizeX = tmp.RadarSizeX;
|
||||
dst.RadarSizeY = tmp.RadarSizeY;
|
||||
dst.SuppressRetailPowerbar = tmp.SuppressRetailPowerbar;
|
||||
dst.ShowRynthChat = tmp.ShowRynthChat;
|
||||
dst.ChatOpacity = tmp.ChatOpacity;
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ internal static class Program
|
|||
HazardEscapeTests.Register(runner);
|
||||
ManaStoneChoiceTests.Register(runner);
|
||||
CustomDebuffTests.Register(runner);
|
||||
ProfileLoadTests.Register(runner);
|
||||
return runner.Run("RynthAi host tests", args.Length > 0 ? args[0] : null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
133
Tools/RynthCore.RynthAiHostTests/Tests/ProfileLoadTests.cs
Normal file
133
Tools/RynthCore.RynthAiHostTests/Tests/ProfileLoadTests.cs
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using RynthCore.Plugin.RynthAi;
|
||||
using RynthCore.Plugin.RynthAi.LegacyUi;
|
||||
using RynthCore.RynthAiTests.Harness;
|
||||
|
||||
namespace RynthCore.RynthAiHostTests.Tests;
|
||||
|
||||
// Loading a profile (login, profile switch) runs LegacyDashboardRenderer.CopySettings, which
|
||||
// copies the loaded file into the live settings one field at a time. A field with no copy line
|
||||
// keeps its in-memory default, and the next autosave writes that default over the profile.
|
||||
// PetAutoRefill, MonsterNameBlacklist and the radar placement were dropped that way.
|
||||
// - every serialized LegacyUiSettings member set to a non-default value comes through
|
||||
// CopySettings (catches any field added later without a copy line);
|
||||
// - a profile written to disk and loaded back serializes unchanged.
|
||||
internal static class ProfileLoadTests
|
||||
{
|
||||
private const BindingFlags Any = BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public;
|
||||
|
||||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("profile: every saved setting survives loading (CopySettings lists each serialized field)", EverySavedFieldIsCopied);
|
||||
r.Add("profile: settings survive a save and a reload through the profile file", SettingsSurviveReload);
|
||||
}
|
||||
|
||||
/// <summary>LegacyDashboardRenderer.CopySettings(src, dst): what LoadSettings / SwitchProfile run.</summary>
|
||||
private static void CopySettings(LegacyUiSettings src, LegacyUiSettings dst) =>
|
||||
typeof(LegacyDashboardRenderer).GetMethod("CopySettings", Any)!.Invoke(null, new object[] { src, dst });
|
||||
|
||||
/// <summary>A different value of the member's type that CopySettings' normalizing keeps distinct from the default.</summary>
|
||||
private static bool TryMutate(string name, Type type, object? value, out object? mutated)
|
||||
{
|
||||
mutated = null;
|
||||
if (name == nameof(LegacyUiSettings.OffhandDefault)) { mutated = "Shield"; return true; } // must parse as an OffhandMode
|
||||
if (name == nameof(LegacyUiSettings.NavLabelMode)) { mutated = 1; return true; } // NavLabelModes.Clamp: 0..2
|
||||
Type t = Nullable.GetUnderlyingType(type) ?? type;
|
||||
if (t == typeof(bool)) { mutated = !((bool?)value ?? false); return true; }
|
||||
if (t == typeof(int)) { mutated = ((int?)value ?? 0) + 3; return true; } // +3: MovementMode 1/2 map back to 0
|
||||
if (t == typeof(long)) { mutated = ((long?)value ?? 0) + 3; return true; }
|
||||
if (t == typeof(uint)) { mutated = ((uint?)value ?? 0) + 3; return true; }
|
||||
if (t == typeof(float)) { mutated = ((float?)value ?? 0f) + 3f; return true; }
|
||||
if (t == typeof(double)) { mutated = ((double?)value ?? 0.0) + 3.0; return true; }
|
||||
if (t == typeof(string)) { mutated = (string?)value + "x"; return true; }
|
||||
if (t.IsEnum)
|
||||
{
|
||||
foreach (object v in Enum.GetValues(t))
|
||||
if (!v.Equals(value)) { mutated = v; return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void EverySavedFieldIsCopied()
|
||||
{
|
||||
var info = RynthAiJsonContext.Default.LegacyUiSettings;
|
||||
var defaults = new LegacyUiSettings();
|
||||
var src = new LegacyUiSettings();
|
||||
var dst = new LegacyUiSettings();
|
||||
|
||||
// Reference members (lists, option objects): dst must end up with a new instance.
|
||||
var dstOriginal = new Dictionary<string, object?>();
|
||||
var skipped = new List<string>();
|
||||
foreach (var p in info.Properties)
|
||||
{
|
||||
if (p.Get == null || p.Set == null) continue;
|
||||
Type t = p.PropertyType;
|
||||
if (t.IsValueType || t == typeof(string))
|
||||
{
|
||||
if (TryMutate(p.Name, t, p.Get(src), out object? m)) p.Set(src, m);
|
||||
else skipped.Add(p.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
dstOriginal[p.Name] = p.Get(dst);
|
||||
}
|
||||
}
|
||||
|
||||
CopySettings(src, dst);
|
||||
|
||||
int members = 0;
|
||||
var missing = new List<string>();
|
||||
foreach (var p in info.Properties)
|
||||
{
|
||||
if (p.Get == null || p.Set == null) continue;
|
||||
members++;
|
||||
if (dstOriginal.TryGetValue(p.Name, out object? before))
|
||||
{
|
||||
if (before != null && ReferenceEquals(p.Get(dst), before)) missing.Add(p.Name);
|
||||
}
|
||||
else if (!skipped.Contains(p.Name)
|
||||
&& Equals(p.Get(dst), p.Get(defaults)) && !Equals(p.Get(src), p.Get(defaults)))
|
||||
{
|
||||
missing.Add(p.Name);
|
||||
}
|
||||
}
|
||||
|
||||
Check.True(members > 100, $"the JSON metadata lists the settings ({members} members)");
|
||||
Check.Eq(skipped.Count, 0, "every value member has a test value (no test value for: " + string.Join(", ", skipped) + ")");
|
||||
Check.Eq(missing.Count, 0, "members CopySettings leaves at their default: " + string.Join(", ", missing));
|
||||
}
|
||||
|
||||
private static void SettingsSurviveReload()
|
||||
{
|
||||
var saved = new LegacyUiSettings();
|
||||
saved.ItemInfoOnSelect = !saved.ItemInfoOnSelect;
|
||||
saved.PetAutoRefill = !saved.PetAutoRefill;
|
||||
saved.MonsterNameBlacklist.Add("Drudge Skulker");
|
||||
saved.RadarPosX = 120f;
|
||||
saved.RadarSizeY = 300f;
|
||||
|
||||
string path = Path.Combine(Program.TempRoot, "profile-load", "Default.json");
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
||||
File.WriteAllText(path, JsonSerializer.Serialize(saved, RynthAiJsonContext.Default.LegacyUiSettings));
|
||||
|
||||
// LoadSettings: read the file, copy it into the live settings object (a fresh session).
|
||||
var loaded = JsonSerializer.Deserialize(File.ReadAllText(path), RynthAiJsonContext.Default.LegacyUiSettings)!;
|
||||
var live = new LegacyUiSettings();
|
||||
CopySettings(loaded, live);
|
||||
|
||||
Check.Eq(live.ItemInfoOnSelect, saved.ItemInfoOnSelect, "describe items when selected");
|
||||
Check.Eq(live.PetAutoRefill, saved.PetAutoRefill, "pet auto refill");
|
||||
Check.True(live.MonsterNameBlacklist.Contains("Drudge Skulker"), "monster blacklist");
|
||||
Check.Eq(live.RadarPosX, 120f, "radar position");
|
||||
Check.Eq(live.RadarSizeY, 300f, "radar size");
|
||||
|
||||
// Unchanged JSON means the autosave right after login has nothing to write over the file.
|
||||
Check.Eq(JsonSerializer.Serialize(live, RynthAiJsonContext.Default.LegacyUiSettings),
|
||||
JsonSerializer.Serialize(saved, RynthAiJsonContext.Default.LegacyUiSettings),
|
||||
"the reloaded profile saves back unchanged (autosave writes nothing different)");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue