feat(loader): export owned cards, decks, items; fix rupy currency key

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-05-29 19:01:06 -04:00
parent 8c79725869
commit b454d58cf2

View File

@@ -153,7 +153,7 @@ internal static class CaptureWriter
{
var cur = new Dictionary<string, object>();
Copy(crystal, "crystal", cur, "crystals");
Copy(crystal, "rupies", cur, "rupees");
Copy(crystal, "rupy", cur, "rupees");
Copy(crystal, "red_ether", cur, "red_ether");
if (cur.Count > 0) dump["currency"] = cur;
}
@@ -164,6 +164,9 @@ internal static class CaptureWriter
ExtractMyPageList(loadIndexData, dump);
ExtractOwnedLeaderSkins(loadIndexData, dump);
ExtractClasses(loadIndexData, dump);
ExtractOwnedCards(loadIndexData, dump);
ExtractItems(loadIndexData, dump);
ExtractDecks(loadIndexData, dump);
lock (_lock)
{
@@ -278,6 +281,129 @@ internal static class CaptureWriter
if (classes.Count > 0) dump["classes"] = classes;
}
private static void ExtractOwnedCards(JsonData data, Dictionary<string, object> dump)
{
var list = SafeGet(data, "user_card_list");
if (list == null || !list.IsArray) return;
var cards = new List<Dictionary<string, object>>();
for (int i = 0; i < list.Count; i++)
{
var entry = list[i];
var idVal = SafeGet(entry, "card_id");
if (idVal == null) continue;
long cardId;
if (idVal.IsInt) cardId = (int)idVal;
else if (idVal.IsLong) cardId = (long)idVal;
else continue;
var c = new Dictionary<string, object> { { "card_id", cardId } };
var num = SafeGet(entry, "number");
if (num != null)
{
if (num.IsInt) c["count"] = (int)num;
else if (num.IsLong) c["count"] = (int)(long)num;
}
var prot = SafeGet(entry, "is_protected");
if (prot != null)
{
c["is_protected"] =
(prot.IsBoolean && (bool)prot) ||
(prot.IsInt && (int)prot != 0) ||
(prot.IsLong && (long)prot != 0);
}
cards.Add(c);
}
if (cards.Count > 0) dump["owned_cards"] = cards;
}
private static void ExtractItems(JsonData data, Dictionary<string, object> dump)
{
var list = SafeGet(data, "user_item_list");
if (list == null || !list.IsArray) return;
var items = new List<Dictionary<string, object>>();
for (int i = 0; i < list.Count; i++)
{
var entry = list[i];
var idVal = SafeGet(entry, "item_id");
if (idVal == null) continue;
var item = new Dictionary<string, object>();
if (idVal.IsInt) item["item_id"] = (int)idVal;
else if (idVal.IsLong) item["item_id"] = (int)(long)idVal;
else continue;
var num = SafeGet(entry, "number");
if (num != null)
{
if (num.IsInt) item["count"] = (int)num;
else if (num.IsLong) item["count"] = (int)(long)num;
}
items.Add(item);
}
if (items.Count > 0) dump["items"] = items;
}
// /load/index splits decks into one container per format; the format is the KEY, not a
// per-deck field. Values mirror the wire deck_format codes (Wizard/Data.cs FormatConvertApi).
private struct DeckFormatKey
{
public string Key;
public int Format;
public DeckFormatKey(string key, int format) { Key = key; Format = format; }
}
private static readonly DeckFormatKey[] DeckFormatKeys =
{
new DeckFormatKey("user_deck_rotation", 1),
new DeckFormatKey("user_deck_unlimited", 2),
new DeckFormatKey("user_deck_pre_rotation", 3),
new DeckFormatKey("user_deck_crossover", 4),
new DeckFormatKey("user_deck_my_rotation", 5),
};
private static void ExtractDecks(JsonData data, Dictionary<string, object> dump)
{
var decks = new List<Dictionary<string, object>>();
foreach (var fmt in DeckFormatKeys)
{
var container = SafeGet(data, fmt.Key);
var deckList = SafeGet(container, "user_deck_list");
if (deckList == null || !deckList.IsArray) continue;
for (int i = 0; i < deckList.Count; i++)
{
var entry = deckList[i];
var d = new Dictionary<string, object> { { "deck_format", fmt.Format } };
Copy(entry, "deck_no", d, "deck_no");
Copy(entry, "deck_name", d, "deck_name");
Copy(entry, "class_id", d, "class_id");
Copy(entry, "sleeve_id", d, "sleeve_id");
Copy(entry, "leader_skin_id", d, "leader_skin_id");
Copy(entry, "is_random_leader_skin", d, "is_random_leader_skin");
Copy(entry, "rotation_id", d, "my_rotation_id"); // UserDeck.rotation_id -> import my_rotation_id
var arr = ExtractLongArray(entry, "card_id_array");
if (arr != null) d["card_id_array"] = arr;
decks.Add(d);
}
}
if (decks.Count > 0) dump["decks"] = decks;
}
private static List<long> ExtractLongArray(JsonData entry, string key)
{
var arr = SafeGet(entry, key);
if (arr == null || !arr.IsArray) return null;
var ids = new List<long>();
for (int i = 0; i < arr.Count; i++)
{
var v = arr[i];
if (v == null) continue;
if (v.IsInt) ids.Add((int)v);
else if (v.IsLong) ids.Add((long)v);
}
return ids;
}
// Splice the body into the envelope as nested JSON (parseable) or escaped string
// (fallback). Cannot route this through Dictionary<string,object> → JsonMapper.ToJson:
// a LitJson.JsonData value inside such a dict makes the reflection serializer