From 18aeaf093b3b9716f1071b1a5308b0130d825e34 Mon Sep 17 00:00:00 2001 From: dingo Date: Tue, 3 Mar 2026 08:48:00 -0500 Subject: [PATCH] Client bug fixes --- .../collection/components/card_widget.gd | 20 ++++++++ .../scenes/collection/views/cards_view.gd | 51 +++++++++++++++++-- 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/Client/origin-client/scenes/collection/components/card_widget.gd b/Client/origin-client/scenes/collection/components/card_widget.gd index dbbfa59..640393e 100644 --- a/Client/origin-client/scenes/collection/components/card_widget.gd +++ b/Client/origin-client/scenes/collection/components/card_widget.gd @@ -121,11 +121,31 @@ signal card_pressed(definition_id: String) var _affinity : String = "" var _definition_id : String = "" var _is_selected : bool = false +var _is_ready : bool = false +var _pending_dto : Dictionary = {} +var _pending_def : Dictionary = {} + + +func _ready() -> void: + _is_ready = true + if not _pending_dto.is_empty(): + _apply_setup(_pending_dto, _pending_def) + _pending_dto.clear() + _pending_def.clear() # ── Public API ──────────────────────────────────────────────────────────────── ## Populate the widget. func setup(dto: Dictionary, def: Dictionary = {}) -> void: + if not _is_ready: + _pending_dto = dto.duplicate(true) + _pending_def = def.duplicate(true) + return + + _apply_setup(dto, def) + + +func _apply_setup(dto: Dictionary, def: Dictionary = {}) -> void: _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", ""))) diff --git a/Client/origin-client/scenes/collection/views/cards_view.gd b/Client/origin-client/scenes/collection/views/cards_view.gd index 9fffe5d..86f52a5 100644 --- a/Client/origin-client/scenes/collection/views/cards_view.gd +++ b/Client/origin-client/scenes/collection/views/cards_view.gd @@ -28,6 +28,7 @@ var _total_count : int = 0 var _has_more : bool = false var _loading : bool = false var _search_timer : float = 0.0 +var _card_entries : Dictionary = {} ## definitionId(String) -> { count, label } const _SEARCH_DEBOUNCE := 0.4 # Emitted when the user taps a card — parent uses this to show the detail popup. @@ -94,6 +95,7 @@ func _reload() -> void: _current_page = 1 _total_count = 0 _has_more = false + _card_entries.clear() for child in card_grid.get_children(): child.queue_free() var cached := CollectionCache.get_cards_response(_query_key_for_page(1)) @@ -172,6 +174,7 @@ func _render_cards_response(payload: Dictionary, page: int) -> void: _has_more = (page * page_size) < _total_count if page == 1: + _card_entries.clear() for child in card_grid.get_children(): child.queue_free() @@ -179,11 +182,7 @@ func _render_cards_response(payload: Dictionary, page: int) -> void: var dto := raw_dto as Dictionary var def := ContentCache.get_definition(str(dto.get("cardDefinitionId", ""))) var hydrated := _hydrate_card_dto(dto, def) - var widget = CARD_WIDGET.instantiate() as PanelContainer - widget.card_pressed.connect(func(_def_id: String): - card_selected.emit(hydrated, def)) - card_grid.add_child(widget) - widget.setup(hydrated, def) + _add_or_increment_card(hydrated, def) if cards.is_empty() and page == 1: _set_status("empty") @@ -193,6 +192,48 @@ func _render_cards_response(payload: Dictionary, page: int) -> void: load_more_btn.visible = _has_more +func _add_or_increment_card(dto: Dictionary, def: Dictionary) -> void: + var def_id := str(dto.get("cardDefinitionId", "")) + if def_id.is_empty(): + return + + if _card_entries.has(def_id): + var entry := _card_entries.get(def_id, {}) as Dictionary + var next_count := int(entry.get("count", 1)) + 1 + entry["count"] = next_count + var count_label := entry.get("label", null) as Label + if count_label != null: + count_label.text = "x%d" % next_count + _card_entries[def_id] = entry + return + + var wrapper := VBoxContainer.new() + wrapper.add_theme_constant_override("separation", 4) + wrapper.size_flags_horizontal = Control.SIZE_SHRINK_CENTER + + var widget := CARD_WIDGET.instantiate() as PanelContainer + widget.card_pressed.connect(func(_pressed_id: String): + var selected_dto := dto.duplicate(true) + var entry := _card_entries.get(def_id, {}) as Dictionary + selected_dto["copyCount"] = int(entry.get("count", 1)) + card_selected.emit(selected_dto, def)) + wrapper.add_child(widget) + widget.setup(dto, def) + + var count_label := Label.new() + count_label.text = "x1" + count_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER + count_label.add_theme_font_size_override("font_size", 11) + count_label.modulate = Color(0.72, 0.72, 0.80) + wrapper.add_child(count_label) + + card_grid.add_child(wrapper) + _card_entries[def_id] = { + "count": 1, + "label": count_label, + } + + func _hydrate_card_dto(dto: Dictionary, def: Dictionary) -> Dictionary: var hydrated := dto.duplicate(true) if def.is_empty():