87 lines
3.1 KiB
C#
87 lines
3.1 KiB
C#
using LibW4M.Data.Teams;
|
|
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 StatsCollective : SaveDataCollective
|
|
{
|
|
private List<StatsContainerData> teamStats = new List<StatsContainerData>();
|
|
private List<XomString> teamNames = new List<XomString>();
|
|
public StatsCollective(W4SaveFile fileBelongs, XomContainer mainContainer) : base(fileBelongs, mainContainer)
|
|
{
|
|
}
|
|
|
|
public override void Load()
|
|
{
|
|
int[] decompressedCollective = mainContainer.Decompress();
|
|
int numStats = decompressedCollective[0];
|
|
for (int i = 0; i < numStats; i++)
|
|
{
|
|
StatsContainerData stat = new StatsContainerData(this.fileBelongs, this.fileBelongs.LookupContainerById(decompressedCollective[i + 1]));
|
|
this.collectiveEntries.Add(stat);
|
|
}
|
|
|
|
int teamStatsStart = (1 + numStats) + 1;
|
|
int numTeamStats = decompressedCollective[(1 + numStats)];
|
|
for (int i = 0; i < numTeamStats; i++)
|
|
{
|
|
StatsContainerData teamStat = new StatsContainerData(this.fileBelongs, this.fileBelongs.LookupContainerById(decompressedCollective[i + (teamStatsStart)]));
|
|
this.teamStats.Add(teamStat);
|
|
}
|
|
|
|
int teamNamesStart = ((((1 + numStats) + 1) + numTeamStats) + 1);
|
|
int numTeamNames = decompressedCollective[(((1 + numStats) + 1) + numTeamStats)];
|
|
for (int i = 0; i < numTeamNames; i++)
|
|
{
|
|
this.teamNames.Add(this.fileBelongs.LookupStringFromId(decompressedCollective[i + (teamNamesStart)]));
|
|
}
|
|
}
|
|
|
|
public override void Save()
|
|
{
|
|
int numStats = this.collectiveEntries.Count;
|
|
int numTeamStats = this.teamStats.Count;
|
|
int numTeamNames = this.teamNames.Count;
|
|
|
|
|
|
// Save regular stats
|
|
int statsStart = 1;
|
|
int[] collective = new int[(numStats + 1) + (numTeamStats + 1) + (numTeamNames + 1)];
|
|
collective[statsStart - 1] = numStats;
|
|
|
|
for(int i = 0; i < numStats; i++)
|
|
{
|
|
this.collectiveEntries[i].Save();
|
|
collective[statsStart + i] = this.collectiveEntries[i].containerId;
|
|
}
|
|
|
|
// Save team stats
|
|
int teamStatsStart = (1 + numStats) + 1;
|
|
collective[teamStatsStart-1] = numTeamStats;
|
|
|
|
for (int i = 0; i < numTeamStats; i++)
|
|
{
|
|
this.teamStats[i].Save();
|
|
|
|
collective[teamStatsStart + i] = this.teamStats[i].containerId;
|
|
}
|
|
|
|
// Save team names
|
|
int teamNamesStart = ((1 + numStats) + (1 + numTeamStats) + 1);
|
|
collective[teamNamesStart - 1] = numTeamNames;
|
|
for (int i = 0; i < numTeamStats; i++)
|
|
{
|
|
collective[teamNamesStart + i] = this.teamNames[i].Id;
|
|
}
|
|
|
|
mainContainer.CompressAndUpdate(collective);
|
|
}
|
|
}
|
|
}
|