From 87a498ac05b3fa3934311dc0c2f9db88d150e2b6 Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 25 Nov 2019 22:50:53 -0800 Subject: [PATCH] Add flag api --- .../Substructures/Gen8/FashionUnlock8.cs | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/PKHeX.Core/Saves/Substructures/Gen8/FashionUnlock8.cs b/PKHeX.Core/Saves/Substructures/Gen8/FashionUnlock8.cs index d4615834e..66833bc4a 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/FashionUnlock8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/FashionUnlock8.cs @@ -1,7 +1,42 @@ -namespace PKHeX.Core +using System.Collections.Generic; +using System.Linq; + +namespace PKHeX.Core { public sealed class FashionUnlock8 : SaveBlock { + private const int SIZE_ENTRY = 0x80; + private const int REGIONS = 15; + public FashionUnlock8(SaveFile sav, SCBlock block) : base(sav, block.Data) { } + + public bool[] GetArrayOwned(int region) => ArrayUtil.GitBitFlagArray(Data, region * SIZE_ENTRY, SIZE_ENTRY * 8); + public bool[] GetArrayNew(int region) => ArrayUtil.GitBitFlagArray(Data, (region + REGIONS) * SIZE_ENTRY, SIZE_ENTRY * 8); + public int[] GetIndexesOwned(int region) => GetIndexes(GetArrayOwned(region)); + public int[] GetIndexesNew(int region) => GetIndexes(GetArrayNew(region)); + + public void SetArrayOwned(int region, bool[] value) => ArrayUtil.SetBitFlagArray(Data, region * SIZE_ENTRY, value); + public void SetArrayNew(int region, bool[] value) => ArrayUtil.SetBitFlagArray(Data, (region + REGIONS) * SIZE_ENTRY, value); + public void SetIndexesOwned(int region, int[] value) => SetArrayOwned(region, SetIndexes(value)); + public void SetIndexesNew(int region, int[] value) => SetArrayNew(region, SetIndexes(value)); + + public static int[] GetIndexes(bool[] arr) + { + var list = new List(); + for (int i = 0; i < arr.Length; i++) + { + if (arr[i]) + list.Add(i); + } + return list.ToArray(); + } + + public static bool[] SetIndexes(int[] arr) + { + var result = new bool[arr.Max()]; + foreach (var index in arr) + result[index] = true; + return result; + } } } \ No newline at end of file