using System.Collections.Generic; using Cthangover.Core.Mods; using Cthangover.Core.Settings; namespace Cthangover.Core.Relationship { /// /// Persists the recruit roster in the mod's own save slot. The core save used /// to carry a "Recruits" blob inside the __core__ slot, but the /// roster now belongs to the recruiting mod — so it saves through the generic /// contract under the mod id recruiting. /// /// replaces the roster wholesale and does not re-fire /// ConfigureRecruit: persisted per-recruit properties (for example the /// nutrition timer) are already in the blob and behaviours continue their /// tick logic from the restored state, matching the old core behaviour. /// Backward compatibility with the old core blob is intentionally not /// provided — old saves start with an empty roster. /// public class RecruitingSaveable : IModSaveable { private const string BlobKey = "Recruits"; /// Writes the session roster into the mod slot. public void OnSave(ModSlot slot) { slot.Data[BlobKey] = new DataBlob(1, RecruitingData.Instance.Data); } /// Restores the roster from the mod slot; an absent blob yields an empty roster. public bool OnLoad(ModSlot slot, out string errorMessage) { errorMessage = null; var data = new List(); if (slot?.Data != null && slot.Data.TryGetValue(BlobKey, out var blob)) data = blob.ReadJson>() ?? new List(); RecruitingData.Instance.Data = data; // The core slot (party cards) is restored before mod slots, so any // squad recruit already has a placeholder card again. The mod owns // its data outside battle, so push the saved health onto that card. foreach (var recruit in data) RecruitPartyBridge.SyncToCard(recruit); return true; } } }