using LibXom.Data; using LibXom.Streams; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LibW4M.Data.Stats { public class StatsContainerData : SaveDataEntry { public int[] Values; internal XomString? teamName; public StatsContainerData(W4SaveFile fileBelongs, XomContainer mainContainer, bool load=true) : base(fileBelongs, mainContainer, load) { } public bool IsRenamable { get { return (teamName is not null); } } public void ChangeName(string newName) { if (!IsRenamable) return; if (teamName.Value.Equals(newName)) return; for(int i = 0; i < this.fileBelongs.TeamStatsCollective.Length; i++) { StatsContainerData? stat = this.fileBelongs.TeamStatsCollective[i] as StatsContainerData; if (stat is null) continue; if (stat.Uuid.Equals(this.Uuid)) { if (i > this.fileBelongs.TeamStatsCollective.TeamNames.Count) break; XomString xStr = this.fileBelongs.LookupString(newName); // update in both places this.fileBelongs.TeamStatsCollective.TeamNames[i] = xStr; this.teamName = xStr; } } } public override string FriendlyName { get { if (IsRenamable) return teamName.Value; return String.Join(" - ", Values); } } public override void Load() { using (XomStreamReader reader = new XomStreamReader(new MemoryStream(this.mainContainer.GetData()))) { reader.Skip(3); Values = reader.ReadInt32Array(); } } internal override void loadDefaults() { this.Values = new int[24]; } public override void Save() { using (MemoryStream ms = new MemoryStream()) { using (XomStreamWriter writer = new XomStreamWriter(ms)) { writer.Skip(3); writer.WriteInt32Array(Values); ms.Seek(0x00, SeekOrigin.Begin); mainContainer.SetData(ms.ToArray()); } } } } }