fix(loot): Keep # 0 and salvage combine off survive a save

LootJsonContext writes with WhenWritingDefault, so LootRule.KeepCount = 0 and
SalvageCombineSettings.Enabled = false were left out of the profile and loaded back
as the initializers' 1 / true. Always write both (JsonIgnore Never, as
LootRule.Enabled already is). The Keep # 0 host test is no longer a known failure;
new salvage-combine-off round trip.
This commit is contained in:
BlankenshipG 2026-10-08 22:51:01 -04:00
commit de981aeb3e
4 changed files with 41 additions and 3 deletions

View file

@ -0,0 +1,23 @@
# Loot profiles - "Keep # 0" and salvage combine off survive a save - 2026-10-08
## Fixed
- **"Keep #" with a count of 0 loads back as 0.** `LootJsonContext` skips values equal to the
type default when writing (`WhenWritingDefault`), so `"KeepCount": 0` was left out of the
`.json` profile and loaded back as the initializer's 1: a "keep none" rule kept one.
- **Salvage combine turned off stays off.** `SalvageCombineSettings.Enabled = false` was left
out the same way and loaded back as `true`.
- Both properties are now always written (`JsonIgnore(Condition = Never)`, as `LootRule.Enabled`
already was). Profiles saved before this still have the value missing and load as before
(1 / on) until they are saved again with the intended value.
## Files
- `Shared/RynthCore.LootSdk/LootModel.cs`: `LootRule.KeepCount` always written.
- `Shared/RynthCore.LootSdk/SalvageCombineSettings.cs`: `Enabled` always written.
- `Tools/RynthCore.RynthAiHostTests/Tests/NativeLootTests.cs`: the Keep # 0 round trip is a
normal test now (was a known failure); new salvage-combine-off round trip.
## Checks
- `loot native` host tests: 24 passed, 0 known failures.

View file

@ -95,6 +95,8 @@ public sealed class LootRule : System.ComponentModel.INotifyPropertyChanged
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)]
public bool Enabled { get; set; } = true;
public LootAction Action { get; set; } = LootAction.Keep;
// Always written: the context skips default values, and a skipped "Keep # 0" would load back as 1.
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)]
public int KeepCount { get; set; } = 1;
public List<LootCondition> Conditions { get; set; } = new();

View file

@ -12,6 +12,8 @@ namespace RynthCore.Loot;
/// </summary>
public sealed class SalvageCombineSettings
{
// Always written: LootJsonContext skips default values, and a skipped false would load back as true.
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)]
public bool Enabled { get; set; } = true;
/// <summary>Default bands applied to materials with no per-material override.</summary>

View file

@ -42,9 +42,8 @@ internal static class NativeLootTests
r.Add("loot native: profile JSON round trip keeps rules and order", JsonRoundTrip);
r.Add("loot native: malformed or missing JSON profile", MalformedJson);
r.Add("loot native: an invalid regex in a String rule does not match", InvalidRegexDoesNotThrow); // was a known failure; fixed by a2902c3
r.KnownFailure("loot native: Keep # with a count of 0 survives a save and load",
"LootJsonContext skips default values when writing, so KeepCount 0 is left out and loads back as the initializer's 1",
KeepCountZeroRoundTrip);
r.Add("loot native: Keep # with a count of 0 survives a save and load", KeepCountZeroRoundTrip); // was a known failure
r.Add("loot native: salvage combine turned off survives a save and load", SalvageCombineOffRoundTrip);
}
private static LootRule Rule(string name, LootAction action, params LootCondition[] conds)
@ -366,4 +365,16 @@ internal static class NativeLootTests
Profile(rule).Save(path);
Check.Eq(LootProfile.Load(path).Rules[0].KeepCount, 0, "KeepCount after reload");
}
/// <summary>LootJsonContext skips default values: SalvageCombine.Enabled = false was left out and loaded back as true.</summary>
private static void SalvageCombineOffRoundTrip()
{
var p = Profile(Rule("any", LootAction.Salvage));
p.SalvageCombine = new SalvageCombineSettings { Enabled = false };
string path = TempFile("combine-off.json");
p.Save(path);
var loaded = LootProfile.Load(path);
Check.NotNull(loaded.SalvageCombine, "SalvageCombine after reload");
Check.False(loaded.SalvageCombine?.Enabled ?? true, "SalvageCombine.Enabled stays off");
}
}