Client changes, admin portal, collection fixes.

This commit is contained in:
dingo
2026-03-02 10:49:49 -05:00
parent ffe1ec5094
commit a3bcc71082
21 changed files with 467 additions and 186 deletions
@@ -110,7 +110,7 @@ func _populate_abilities(def: Dictionary) -> void:
for child in abilities_list.get_children():
child.queue_free()
var json_str := str(def.get("abilitiesJson", ""))
var json_str := str(def.get("abilities", ""))
if json_str.is_empty() or json_str == "[]":
abilities_sep.visible = false
abilities_title.visible = false
@@ -126,10 +126,12 @@ var _is_selected : bool = false
## Populate the widget.
func setup(dto: Dictionary, def: Dictionary = {}) -> void:
_affinity = str(dto.get("affinity", ""))
_definition_id = str(dto.get("cardDefinitionId", ""))
var rarity := str(dto.get("rarity", ""))
var is_foil := bool(dto.get("isFoil", false))
_definition_id = str(dto.get("cardDefinitionId", def.get("id", "")))
_affinity = str(def.get("affinity", dto.get("affinity", "")))
var rarity := str(def.get("rarity", dto.get("rarity", "")))
var name := str(def.get("name", dto.get("name", "")))
var card_type := str(def.get("cardType", dto.get("cardType", "")))
var is_foil := bool(dto.get("isFoil", false))
_apply_style()
@@ -139,6 +141,8 @@ func setup(dto: Dictionary, def: Dictionary = {}) -> void:
foil_label.visible = is_foil
name_label.text = str(dto.get("name", "—"))
type_label.text = str(dto.get("cardType", ""))
name_label.text = name if not name.is_empty() else name_label.text
type_label.text = card_type if not card_type.is_empty() else type_label.text
rarity_label.text = rarity
rarity_label.modulate = RARITY_COLOR.get(rarity, Color(0.67, 0.67, 0.67))
@@ -246,6 +246,9 @@ func _load_deck_contents() -> void:
for child in _deck_card_list.get_children():
child.queue_free()
_deck_loading_lbl.visible = true
var cached := CollectionCache.get_deck_response(_deck_id)
if not cached.is_empty():
_render_deck_response(cached)
Network.request(
"collection.get_deck",
{ "deckId": _deck_id },
@@ -255,31 +258,9 @@ func _load_deck_contents() -> void:
func _on_deck_response(payload: Variant) -> void:
_deck_loading_lbl.visible = false
var p := payload as Dictionary
var deck_raw : Variant = p.get("deck", null)
if deck_raw == null or typeof(deck_raw) != TYPE_DICTIONARY:
push_warning("DeckEditor: missing deck in response")
return
var deck := deck_raw as Dictionary
var cards : Array = deck.get("cards", [])
_deck_qty.clear()
var non_as_total := 0
for c in cards:
var def_id := str(c.get("cardDefinitionId", ""))
var qty := int(c.get("quantity", 0))
if not def_id.is_empty():
_deck_qty[def_id] = qty
if str(c.get("cardType", "")) != "ArchSpirit":
non_as_total += qty
_count_lbl.text = "%d / 40" % non_as_total
for c in cards:
_deck_card_list.add_child(_make_deck_row(c))
_refresh_coll_in_deck_labels()
var p := payload as Dictionary
CollectionCache.store_deck_response(_deck_id, p)
_render_deck_response(p)
func _on_deck_error(msg: String) -> void:
@@ -350,6 +331,9 @@ func _reload_collection() -> void:
for child in _coll_list.get_children():
child.queue_free()
_load_more_btn.visible = false
var cached := CollectionCache.get_cards_response(_collection_query_key(1))
if not cached.is_empty():
_render_coll_response(cached, 1)
_fetch_coll_page(1)
@@ -376,15 +360,10 @@ func _fetch_coll_page(page: int) -> void:
func _on_coll_response(payload: Variant, page: int) -> void:
_is_loading = false
_coll_loading_lbl.visible = false
var p := payload as Dictionary
var cards : Array = p.get("cards", [])
_coll_total = int(p.get("totalCount", 0))
var ps := int(p.get("pageSize", PAGE_SIZE))
_coll_page = page
_has_more = (page * ps) < _coll_total
_load_more_btn.visible = _has_more
var p_cache := payload as Dictionary
CollectionCache.store_cards_response(_collection_query_key(page), p_cache)
_render_coll_response(p_cache, page)
var cards : Array = []
# Track def_ids already in the list to avoid duplicates across pages
var seen : Dictionary = {}
@@ -497,3 +476,94 @@ func _remove_card(def_id: String, qty: Variant) -> void:
func(_t: String, _p: Variant): _load_deck_contents(),
func(_code: String, msg: String): push_warning("DeckEditor remove_card: %s" % msg)
)
func _render_deck_response(payload: Dictionary) -> void:
_deck_loading_lbl.visible = false
var deck_raw : Variant = payload.get("deck", null)
if deck_raw == null or typeof(deck_raw) != TYPE_DICTIONARY:
push_warning("DeckEditor: missing deck in response")
return
var deck := deck_raw as Dictionary
for child in _deck_card_list.get_children():
child.queue_free()
var cards : Array = deck.get("cards", [])
_deck_qty.clear()
var non_as_total := 0
for raw_card in cards:
var card := raw_card as Dictionary
var def_id := str(card.get("cardDefinitionId", ""))
var qty := int(card.get("quantity", 0))
if not def_id.is_empty():
_deck_qty[def_id] = qty
var def := ContentCache.get_definition(def_id)
if str(def.get("cardType", "")) != "ArchSpirit":
non_as_total += qty
_count_lbl.text = "%d / 40" % non_as_total
for raw_card in cards:
var card := raw_card as Dictionary
var def := ContentCache.get_definition(str(card.get("cardDefinitionId", "")))
_deck_card_list.add_child(_make_deck_row(_hydrate_card_dto(card, def)))
_refresh_coll_in_deck_labels()
func _render_coll_response(payload: Dictionary, page: int) -> void:
_is_loading = false
_coll_loading_lbl.visible = false
var cards : Array = payload.get("cards", [])
_coll_total = int(payload.get("totalCount", 0))
var page_size := int(payload.get("pageSize", PAGE_SIZE))
_coll_page = page
_has_more = (page * page_size) < _coll_total
_load_more_btn.visible = _has_more
if page == 1:
for child in _coll_list.get_children():
child.queue_free()
var seen : Dictionary = {}
for child in _coll_list.get_children():
if child.has_meta("def_id"):
seen[str(child.get_meta("def_id"))] = true
for raw_dto in cards:
var dto := raw_dto as Dictionary
var def_id := str(dto.get("cardDefinitionId", ""))
if def_id.is_empty() or def_id in seen:
continue
var def := ContentCache.get_definition(def_id)
var tier_value: Variant = def.get("tier", null)
var tier_num := 1
if tier_value != null:
tier_num = type_convert(tier_value, TYPE_INT)
if str(def.get("cardType", "")) == "ArchSpirit" and tier_num <= 1:
continue
seen[def_id] = true
_coll_list.add_child(_make_coll_row(_hydrate_card_dto(dto, def)))
func _hydrate_card_dto(dto: Dictionary, def: Dictionary) -> Dictionary:
var hydrated := dto.duplicate(true)
if def.is_empty():
return hydrated
hydrated["name"] = str(def.get("name", hydrated.get("name", "")))
hydrated["cardType"] = str(def.get("cardType", hydrated.get("cardType", "")))
hydrated["affinity"] = str(def.get("affinity", hydrated.get("affinity", "")))
hydrated["rarity"] = str(def.get("rarity", hydrated.get("rarity", "")))
var tier_value: Variant = def.get("tier", hydrated.get("tier", null))
hydrated["tier"] = tier_value if tier_value != null else null
return hydrated
func _collection_query_key(page: int) -> String:
var search := _search_input.text.strip_edges()
var type_filter := ""
var type_idx := _type_option.selected
if type_idx > 0:
type_filter = _type_option.get_item_text(type_idx)
return CollectionCache.cards_query_key(page, PAGE_SIZE, search, type_filter)
@@ -62,10 +62,14 @@ func _apply_setup(deck: Dictionary) -> void:
name_label.text = _deck_name
name_edit.text = _deck_name
var arch_name : String = str(deck.get("archSpiritName", ""))
arch_spirit_label.text = arch_name if not arch_name.is_empty() else "No ArchSpirit"
arch_spirit_label.modulate = Color(0.6, 0.6, 0.7) if arch_name.is_empty() \
else Color(0.8, 0.8, 0.9)
var arch_def_id := str(deck.get("archSpiritCardDefinitionId", ""))
var arch_def := ContentCache.get_definition(arch_def_id)
var arch_name := str(arch_def.get("name", ""))
var has_arch := not arch_def_id.is_empty()
arch_spirit_label.text = arch_name if not arch_name.is_empty() \
else ("Unknown ArchSpirit" if has_arch else "No ArchSpirit")
arch_spirit_label.modulate = Color(0.8, 0.8, 0.9) if has_arch \
else Color(0.6, 0.6, 0.7)
count_label.text = "%d cards" % int(deck.get("cardCount", 0))