97 lines
3.4 KiB
C#
97 lines
3.4 KiB
C#
using LibW4M.Data.Highscores;
|
|
using LibXom.Data;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace LibW4M.Data.Stats
|
|
{
|
|
public class TeamStatsCollective : SaveDataCollective
|
|
{
|
|
public List<XomString> TeamNames;
|
|
|
|
public TeamStatsCollective(W4SaveFile fileBelongs, XomContainer mainContainer) : base(fileBelongs, mainContainer)
|
|
{
|
|
TeamNames = new List<XomString>();
|
|
}
|
|
|
|
public override void Load()
|
|
{
|
|
// team stats are stored *after* the regular stats
|
|
|
|
int[] decompressedCollective = mainContainer.Decompress();
|
|
int statsLen = decompressedCollective[0];
|
|
|
|
|
|
int teamStatsStart = statsLen + 1;
|
|
int teamStatsLen = decompressedCollective[teamStatsStart];
|
|
|
|
// And then the team name this is associated with, is after that
|
|
int teamNamesStart = (statsLen + 1) + (teamStatsLen + 1);
|
|
int teamNamesLen = decompressedCollective[teamNamesStart];
|
|
|
|
for(int i = 0; i < teamNamesLen; i++)
|
|
TeamNames.Add(fileBelongs.LookupStringFromId(decompressedCollective[(teamNamesStart + 1) + i]));
|
|
|
|
for(int i = 0; i < teamStatsLen; i++)
|
|
{
|
|
StatsContainerData stats = new StatsContainerData(this.fileBelongs, fileBelongs.LookupContainerById(decompressedCollective[(teamStatsStart + 1) + i]));
|
|
|
|
if (i < TeamNames.Count)
|
|
stats.teamName = TeamNames[i];
|
|
|
|
this.collectiveEntries.Add(stats);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public override void Save()
|
|
{
|
|
// Decompress the collective
|
|
int[] decompressedCollective = mainContainer.Decompress();
|
|
|
|
// get total length of stats
|
|
int statsLen = decompressedCollective[0];
|
|
|
|
// Team Stats collective starts right *after* the stats collective.
|
|
int teamStatsStart = statsLen + 1;
|
|
int teamStatsLen = this.Length;
|
|
|
|
int teamNamesStart = (statsLen + 1) + (teamStatsLen + 1);
|
|
int teamNamesLen = this.TeamNames.Count;
|
|
|
|
// copy regular stats data from collective.
|
|
int[] statsData = new int[statsLen + 1];
|
|
Array.Copy(decompressedCollective, statsData, statsData.Length);
|
|
|
|
// copy regular stats data back to collective.
|
|
int[] newCollective = new int[statsData.Length + (1 + teamStatsLen) + (1 + TeamNames.Count)];
|
|
Array.Copy(statsData, newCollective, statsData.Length);
|
|
|
|
// populate team stats collective
|
|
newCollective[teamStatsStart] = teamStatsLen;
|
|
|
|
for(int i = 0; i < teamStatsLen; i++)
|
|
{
|
|
StatsContainerData teamStatsData = collectiveEntries[i] as StatsContainerData;
|
|
if (teamStatsData is null) continue;
|
|
teamStatsData.Save();
|
|
newCollective[teamStatsStart + i + 1] = teamStatsData.mainContainer.Id;
|
|
}
|
|
|
|
|
|
// add team names too
|
|
newCollective[teamStatsStart] = teamNamesLen;
|
|
for (int i = 0; i < teamNamesLen; i++)
|
|
newCollective[teamNamesStart + i + 1] = this.TeamNames[i].Id;
|
|
|
|
// Compress whole collective and update the underlying container.
|
|
mainContainer.CompressAndUpdate(newCollective);
|
|
|
|
}
|
|
}
|
|
}
|