diff --git a/PKHeX.Core/Saves/Substructures/Gen5/Misc5.cs b/PKHeX.Core/Saves/Substructures/Gen5/Misc5.cs index 58c7a400b..95fb8ddae 100644 --- a/PKHeX.Core/Saves/Substructures/Gen5/Misc5.cs +++ b/PKHeX.Core/Saves/Substructures/Gen5/Misc5.cs @@ -2,7 +2,7 @@ namespace PKHeX.Core { - public abstract class Misc5 : SaveBlock + public abstract class Misc5 : SaveBlock, IGymTeamInfo { protected Misc5(SAV5 sav, int offset) : base(sav) => Offset = offset; @@ -36,7 +36,7 @@ public ushort GetBadgeVictorySpecies(uint badge, uint slot) return BitConverter.ToUInt16(Data, ofs); } - public void GetBadgeVictorySpecies(uint badge, uint slot, ushort species) + public void SetBadgeVictorySpecies(uint badge, uint slot, ushort species) { var ofs = GetBadgeVictorySpeciesOffset(badge, slot); SAV.SetData(BitConverter.GetBytes(species), ofs); diff --git a/PKHeX.Core/Saves/Substructures/Gen6/IGymTeamInfo.cs b/PKHeX.Core/Saves/Substructures/Gen6/IGymTeamInfo.cs new file mode 100644 index 000000000..b02cd12a9 --- /dev/null +++ b/PKHeX.Core/Saves/Substructures/Gen6/IGymTeamInfo.cs @@ -0,0 +1,39 @@ +namespace PKHeX.Core +{ + public interface IGymTeamInfo + { + ushort GetBadgeVictorySpecies(uint badge, uint slot); + void SetBadgeVictorySpecies(uint badge, uint slot, ushort species); + } + + public static class GymTeamInfoExtensions + { + public static ushort[][] GetGymTeams(this IGymTeamInfo info) + { + ushort[][] teams = new ushort[8][]; + for (uint badge = 0; badge < teams.Length; badge++) + teams[badge] = GetGymTeam(info, badge); + return teams; + } + + private static ushort[] GetGymTeam(IGymTeamInfo info, uint badge) + { + var team = new ushort[6]; + for (uint slot = 0; slot < team.Length; slot++) + team[slot] = info.GetBadgeVictorySpecies(badge, slot); + return team; + } + + public static void SetGymTeams(this IGymTeamInfo info, ushort[][] teams) + { + for (uint badge = 0; badge < teams.Length; badge++) + info.SetGymTeam(badge, teams[badge]); + } + + public static void SetGymTeam(this IGymTeamInfo info, uint badge, ushort[] team) + { + for (uint slot = 0; slot < team.Length; slot++) + info.SetBadgeVictorySpecies(badge, slot, team[slot]); + } + } +} \ No newline at end of file diff --git a/PKHeX.Core/Saves/Substructures/Gen6/SubEventLog6.cs b/PKHeX.Core/Saves/Substructures/Gen6/SubEventLog6.cs index 3b6d499cf..b78eb4b48 100644 --- a/PKHeX.Core/Saves/Substructures/Gen6/SubEventLog6.cs +++ b/PKHeX.Core/Saves/Substructures/Gen6/SubEventLog6.cs @@ -2,7 +2,7 @@ namespace PKHeX.Core { - public abstract class SubEventLog6 : SaveBlock + public abstract class SubEventLog6 : SaveBlock, IGymTeamInfo { protected SubEventLog6(SAV6 sav, int offset) : base(sav) => Offset = offset; @@ -24,7 +24,7 @@ public ushort GetBadgeVictorySpecies(uint badge, uint slot) return BitConverter.ToUInt16(Data, ofs); } - public void GetBadgeVictorySpecies(uint badge, uint slot, ushort species) + public void SetBadgeVictorySpecies(uint badge, uint slot, ushort species) { var ofs = GetBadgeVictorySpeciesOffset(badge, slot); SAV.SetData(BitConverter.GetBytes(species), ofs);