diff --git a/Client/origin-client/scenes/collection/components/CardWidget.tscn b/Client/origin-client/scenes/collection/components/CardWidget.tscn index 20bad25..15743cd 100644 --- a/Client/origin-client/scenes/collection/components/CardWidget.tscn +++ b/Client/origin-client/scenes/collection/components/CardWidget.tscn @@ -3,55 +3,88 @@ [ext_resource type="Script" uid="uid://cqrcq3lrws6qm" path="res://scenes/collection/components/card_widget.gd" id="1_cw"] [node name="CardWidget" type="PanelContainer"] -custom_minimum_size = Vector2(146, 204) +custom_minimum_size = Vector2(152, 238) script = ExtResource("1_cw") [node name="Margin" type="MarginContainer" parent="."] layout_mode = 2 -theme_override_constants/margin_left = 5 -theme_override_constants/margin_top = 5 -theme_override_constants/margin_right = 5 -theme_override_constants/margin_bottom = 5 +theme_override_constants/margin_left = 6 +theme_override_constants/margin_top = 6 +theme_override_constants/margin_right = 6 +theme_override_constants/margin_bottom = 6 [node name="VBox" type="VBoxContainer" parent="Margin"] layout_mode = 2 -theme_override_constants/separation = 3 +theme_override_constants/separation = 5 -[node name="TopRow" type="HBoxContainer" parent="Margin/VBox"] -custom_minimum_size = Vector2(0, 20) +[node name="HeaderRow" type="HBoxContainer" parent="Margin/VBox"] +custom_minimum_size = Vector2(0, 28) +layout_mode = 2 +theme_override_constants/separation = 6 + +[node name="AffinityIcon" type="TextureRect" parent="Margin/VBox/HeaderRow"] +unique_name_in_owner = true +custom_minimum_size = Vector2(24, 24) +layout_mode = 2 +expand_mode = 1 +stretch_mode = 5 + +[node name="NameLabel" type="Label" parent="Margin/VBox/HeaderRow"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +theme_override_font_sizes/font_size = 13 +text = "Card Name" +horizontal_alignment = 1 +vertical_alignment = 1 +text_overrun_behavior = 3 + +[node name="CostColumn" type="VBoxContainer" parent="Margin/VBox/HeaderRow"] layout_mode = 2 theme_override_constants/separation = 2 -[node name="SpLabel" type="Label" parent="Margin/VBox/TopRow"] +[node name="SpRow" type="HBoxContainer" parent="Margin/VBox/HeaderRow/CostColumn"] unique_name_in_owner = true layout_mode = 2 -theme_override_font_sizes/font_size = 12 -text = "◆?" +theme_override_constants/separation = 3 -[node name="TopFill" type="Control" parent="Margin/VBox/TopRow"] -layout_mode = 2 -size_flags_horizontal = 3 - -[node name="FoilLabel" type="Label" parent="Margin/VBox/TopRow"] +[node name="SpIcon" type="TextureRect" parent="Margin/VBox/HeaderRow/CostColumn/SpRow"] unique_name_in_owner = true -visible = false -modulate = Color(0.95, 0.85, 0.3, 1) +custom_minimum_size = Vector2(12, 12) layout_mode = 2 -theme_override_font_sizes/font_size = 12 -text = "✦" +expand_mode = 1 +stretch_mode = 5 -[node name="StLabel" type="Label" parent="Margin/VBox/TopRow"] +[node name="SpLabel" type="Label" parent="Margin/VBox/HeaderRow/CostColumn/SpRow"] unique_name_in_owner = true -visible = false layout_mode = 2 -theme_override_font_sizes/font_size = 12 +theme_override_font_sizes/font_size = 11 +text = "?" + +[node name="StRow" type="HBoxContainer" parent="Margin/VBox/HeaderRow/CostColumn"] +unique_name_in_owner = true +layout_mode = 2 +theme_override_constants/separation = 3 + +[node name="StIcon" type="TextureRect" parent="Margin/VBox/HeaderRow/CostColumn/StRow"] +unique_name_in_owner = true +custom_minimum_size = Vector2(12, 12) +layout_mode = 2 +expand_mode = 1 +stretch_mode = 5 + +[node name="StLabel" type="Label" parent="Margin/VBox/HeaderRow/CostColumn/StRow"] +unique_name_in_owner = true +layout_mode = 2 +theme_override_font_sizes/font_size = 11 +text = "0" [node name="ArtArea" type="Panel" parent="Margin/VBox"] -custom_minimum_size = Vector2(0, 80) +custom_minimum_size = Vector2(0, 122) layout_mode = 2 size_flags_vertical = 3 -[node name="ArtRect" type="ColorRect" parent="Margin/VBox/ArtArea"] +[node name="ArtTexture" type="TextureRect" parent="Margin/VBox/ArtArea"] unique_name_in_owner = true layout_mode = 1 anchors_preset = 15 @@ -59,75 +92,145 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -color = Color(0.18, 0.18, 0.24, 1) +expand_mode = 1 +stretch_mode = 6 -[node name="ArtSymbol" type="TextureRect" parent="Margin/VBox/ArtArea"] +[node name="MetaRow" type="HBoxContainer" parent="Margin/VBox"] +custom_minimum_size = Vector2(0, 18) +layout_mode = 2 +theme_override_constants/separation = 4 + +[node name="SetIcon" type="TextureRect" parent="Margin/VBox/MetaRow"] unique_name_in_owner = true -modulate = Color(1, 1, 1, 0.85) -layout_mode = 1 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 +custom_minimum_size = Vector2(14, 14) +layout_mode = 2 expand_mode = 1 stretch_mode = 5 -[node name="NameLabel" type="Label" parent="Margin/VBox"] +[node name="GenusLabel" type="Label" parent="Margin/VBox/MetaRow"] unique_name_in_owner = true -custom_minimum_size = Vector2(0, 18) +modulate = Color(0.82, 0.82, 0.86, 1) layout_mode = 2 -theme_override_font_sizes/font_size = 13 -text = "Card Name" +size_flags_horizontal = 3 +theme_override_font_sizes/font_size = 10 +text = "Genus" +vertical_alignment = 1 text_overrun_behavior = 3 -[node name="TypeRarityRow" type="HBoxContainer" parent="Margin/VBox"] -custom_minimum_size = Vector2(0, 14) -layout_mode = 2 -theme_override_constants/separation = 2 - -[node name="TypeLabel" type="Label" parent="Margin/VBox/TypeRarityRow"] +[node name="TypeLabel" type="Label" parent="Margin/VBox/MetaRow"] unique_name_in_owner = true -modulate = Color(0.7, 0.7, 0.75, 1) +modulate = Color(0.65, 0.65, 0.72, 1) layout_mode = 2 theme_override_font_sizes/font_size = 10 +text = "Type" +vertical_alignment = 1 -[node name="TypeFill" type="Control" parent="Margin/VBox/TypeRarityRow"] +[node name="StatsGrid" type="GridContainer" parent="Margin/VBox"] layout_mode = 2 -size_flags_horizontal = 3 +theme_override_constants/h_separation = 4 +theme_override_constants/v_separation = 4 +columns = 2 -[node name="RarityLabel" type="Label" parent="Margin/VBox/TypeRarityRow"] +[node name="AttackBadge" type="HBoxContainer" parent="Margin/VBox/StatsGrid"] unique_name_in_owner = true layout_mode = 2 -theme_override_font_sizes/font_size = 10 +theme_override_constants/separation = 4 -[node name="StatsRow" type="HBoxContainer" parent="Margin/VBox"] -custom_minimum_size = Vector2(0, 18) +[node name="AttackIconLabel" type="Label" parent="Margin/VBox/StatsGrid/AttackBadge"] layout_mode = 2 -theme_override_constants/separation = 2 +theme_override_font_sizes/font_size = 9 +text = "ATK" -[node name="DmgLabel" type="Label" parent="Margin/VBox/StatsRow"] +[node name="AttackValue" type="Label" parent="Margin/VBox/StatsGrid/AttackBadge"] unique_name_in_owner = true layout_mode = 2 theme_override_font_sizes/font_size = 11 -text = "⚔ –" +text = "-" -[node name="StatsFill" type="Control" parent="Margin/VBox/StatsRow"] +[node name="MoveBadge" type="HBoxContainer" parent="Margin/VBox/StatsGrid"] +unique_name_in_owner = true layout_mode = 2 -size_flags_horizontal = 3 +theme_override_constants/separation = 4 -[node name="HpLabel" type="Label" parent="Margin/VBox/StatsRow"] +[node name="MoveIcon" type="TextureRect" parent="Margin/VBox/StatsGrid/MoveBadge"] +unique_name_in_owner = true +custom_minimum_size = Vector2(12, 12) +layout_mode = 2 +expand_mode = 1 +stretch_mode = 5 + +[node name="MoveValue" type="Label" parent="Margin/VBox/StatsGrid/MoveBadge"] unique_name_in_owner = true layout_mode = 2 theme_override_font_sizes/font_size = 11 -text = "♥ –" +text = "-" -[node name="StatsFill2" type="Control" parent="Margin/VBox/StatsRow"] +[node name="RangeBadge" type="HBoxContainer" parent="Margin/VBox/StatsGrid"] +unique_name_in_owner = true layout_mode = 2 -size_flags_horizontal = 3 +theme_override_constants/separation = 4 -[node name="DefLabel" type="Label" parent="Margin/VBox/StatsRow"] +[node name="RangeIconLabel" type="Label" parent="Margin/VBox/StatsGrid/RangeBadge"] +layout_mode = 2 +theme_override_font_sizes/font_size = 9 +text = "RNG" + +[node name="RangeValue" type="Label" parent="Margin/VBox/StatsGrid/RangeBadge"] unique_name_in_owner = true layout_mode = 2 theme_override_font_sizes/font_size = 11 -text = "▲ –" +text = "-" + +[node name="HpBadge" type="HBoxContainer" parent="Margin/VBox/StatsGrid"] +unique_name_in_owner = true +layout_mode = 2 +theme_override_constants/separation = 4 + +[node name="HpIcon" type="TextureRect" parent="Margin/VBox/StatsGrid/HpBadge"] +unique_name_in_owner = true +custom_minimum_size = Vector2(12, 12) +layout_mode = 2 +expand_mode = 1 +stretch_mode = 5 + +[node name="HpValue" type="Label" parent="Margin/VBox/StatsGrid/HpBadge"] +unique_name_in_owner = true +layout_mode = 2 +theme_override_font_sizes/font_size = 11 +text = "-" + +[node name="DefBadge" type="HBoxContainer" parent="Margin/VBox/StatsGrid"] +unique_name_in_owner = true +layout_mode = 2 +theme_override_constants/separation = 4 + +[node name="DefIcon" type="TextureRect" parent="Margin/VBox/StatsGrid/DefBadge"] +unique_name_in_owner = true +custom_minimum_size = Vector2(12, 12) +layout_mode = 2 +expand_mode = 1 +stretch_mode = 5 + +[node name="DefValue" type="Label" parent="Margin/VBox/StatsGrid/DefBadge"] +unique_name_in_owner = true +layout_mode = 2 +theme_override_font_sizes/font_size = 11 +text = "-" + +[node name="AbilityBadge" type="HBoxContainer" parent="Margin/VBox/StatsGrid"] +unique_name_in_owner = true +layout_mode = 2 +theme_override_constants/separation = 4 + +[node name="AbilityIcon" type="TextureRect" parent="Margin/VBox/StatsGrid/AbilityBadge"] +unique_name_in_owner = true +custom_minimum_size = Vector2(12, 12) +layout_mode = 2 +expand_mode = 1 +stretch_mode = 5 + +[node name="AbilityValue" type="Label" parent="Margin/VBox/StatsGrid/AbilityBadge"] +unique_name_in_owner = true +layout_mode = 2 +theme_override_font_sizes/font_size = 11 +text = "0" diff --git a/Client/origin-client/scenes/collection/components/card_widget.gd b/Client/origin-client/scenes/collection/components/card_widget.gd index 640393e..64519e8 100644 --- a/Client/origin-client/scenes/collection/components/card_widget.gd +++ b/Client/origin-client/scenes/collection/components/card_widget.gd @@ -2,26 +2,30 @@ extends PanelContainer ## Visual card widget. ## ## Call setup(dto, def) after instantiation, where: -## dto — PlayerCardDto dictionary from collection.get_cards -## def — CardDefinitionDto from ContentCache.get_definition() (pass {} if absent) +## dto - PlayerCardDto dictionary from collection.get_cards +## def - CardDefinitionDto from ContentCache.get_definition() (pass {} if absent) ## ## Emits card_pressed(definition_id) on tap/click. ## Call set_selected(true/false) to highlight the card (used by the arch-spirit picker). -# ── Colour tables ───────────────────────────────────────────────────────────── -# Affinities match SOR.Database.Enums.Affinity. -# Basic: Void, Aether, Lake, Hill, Forest, Field. -# Non-basics are two-basic combos; tile-only affinities never appear on cards. +const DEFAULT_CARD_ART_URL := "https://cdn.aeternalisgames.com/sor-assets/cardart/0_No-Card-Art.jpg" +const GRAPHICS_BASE_URL := "https://cdn.aeternalisgames.com/sor-assets/graphics" +const REMOTE_CACHE_DIR := "user://remote_texture_cache" +const ICON_SP_URL := "%s/card_SP_Icon.png" % GRAPHICS_BASE_URL +const ICON_ST_URL := "%s/card_ST_Icon.png" % GRAPHICS_BASE_URL +const ICON_SET_URL := "%s/Origin-Symbol.png" % GRAPHICS_BASE_URL +const ICON_MOVE_URL := "%s/movement.svg" % GRAPHICS_BASE_URL +const ICON_ABILITY_URL := "%s/ability.svg" % GRAPHICS_BASE_URL +const ICON_DEF_URL := "%s/Shield.png" % GRAPHICS_BASE_URL +const ICON_HP_URL := "%s/Heart.png" % GRAPHICS_BASE_URL const AFFINITY_BORDER := { - # ── Basic ────────────────────────────────────────────────────────────── "Void": Color(0.45, 0.18, 0.65), "Aether": Color(0.35, 0.72, 1.00), "Lake": Color(0.22, 0.52, 0.92), "Hill": Color(0.70, 0.55, 0.30), "Forest": Color(0.28, 0.68, 0.25), "Field": Color(0.82, 0.72, 0.18), - # ── Non-basic ────────────────────────────────────────────────────────── "Ocean": Color(0.12, 0.38, 0.82), "Island": Color(0.22, 0.65, 0.72), "Marsh": Color(0.35, 0.60, 0.38), @@ -37,14 +41,12 @@ const AFFINITY_BORDER := { } const AFFINITY_BG := { - # ── Basic ────────────────────────────────────────────────────────────── "Void": Color(0.15, 0.04, 0.22), "Aether": Color(0.06, 0.18, 0.38), "Lake": Color(0.05, 0.15, 0.40), "Hill": Color(0.28, 0.20, 0.08), "Forest": Color(0.08, 0.24, 0.08), "Field": Color(0.25, 0.20, 0.03), - # ── Non-basic ────────────────────────────────────────────────────────── "Ocean": Color(0.03, 0.10, 0.32), "Island": Color(0.05, 0.22, 0.28), "Marsh": Color(0.08, 0.18, 0.10), @@ -59,20 +61,79 @@ const AFFINITY_BG := { "PureVoid": Color(0.08, 0.02, 0.14), } -# One icon per basic affinity. Non-basics share their primary component's icon -# via _affinity_icon() below. -const AFFINITY_ICONS := { - "Void": preload("res://icons/affinity_void.svg"), - "Aether": preload("res://icons/affinity_aether.svg"), - "Lake": preload("res://icons/affinity_lake.svg"), - "Hill": preload("res://icons/affinity_hill.svg"), - "Forest": preload("res://icons/affinity_forest.svg"), - "Field": preload("res://icons/affinity_field.svg"), +const RARITY_COLOR := { + "Common": Color(0.67, 0.67, 0.67), + "Uncommon": Color(0.27, 0.85, 0.27), + "Rare": Color(0.27, 0.53, 1.00), + "Epic": Color(0.67, 0.27, 1.00), + "Legendary": Color(1.00, 0.67, 0.13), } -## Returns the icon texture for any affinity, mapping non-basics to their -## primary basic component. +const AFFINITY_ICONS := { + "Void": preload("res://icons/affinity_void.svg"), + "Aether": preload("res://icons/affinity_aether.svg"), + "Lake": preload("res://icons/affinity_lake.svg"), + "Hill": preload("res://icons/affinity_hill.svg"), + "Forest": preload("res://icons/affinity_forest.svg"), + "Field": preload("res://icons/affinity_field.svg"), +} + +static var _texture_cache: Dictionary = {} + +signal card_pressed(definition_id: String) + +@onready var affinity_icon_rect: TextureRect = %AffinityIcon +@onready var name_label: Label = %NameLabel +@onready var sp_row: HBoxContainer = %SpRow +@onready var sp_icon: TextureRect = %SpIcon +@onready var sp_label: Label = %SpLabel +@onready var st_row: HBoxContainer = %StRow +@onready var st_icon: TextureRect = %StIcon +@onready var st_label: Label = %StLabel +@onready var art_area: Panel = $Margin/VBox/ArtArea +@onready var art_texture: TextureRect = %ArtTexture +@onready var set_icon: TextureRect = %SetIcon +@onready var genus_label: Label = %GenusLabel +@onready var type_label: Label = %TypeLabel +@onready var attack_badge: HBoxContainer = %AttackBadge +@onready var attack_value: Label = %AttackValue +@onready var move_badge: HBoxContainer = %MoveBadge +@onready var move_icon: TextureRect = %MoveIcon +@onready var move_value: Label = %MoveValue +@onready var range_badge: HBoxContainer = %RangeBadge +@onready var range_value: Label = %RangeValue +@onready var hp_badge: HBoxContainer = %HpBadge +@onready var hp_icon: TextureRect = %HpIcon +@onready var hp_value: Label = %HpValue +@onready var def_badge: HBoxContainer = %DefBadge +@onready var def_icon: TextureRect = %DefIcon +@onready var def_value: Label = %DefValue +@onready var ability_badge: HBoxContainer = %AbilityBadge +@onready var ability_icon: TextureRect = %AbilityIcon +@onready var ability_value: Label = %AbilityValue + +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 + _load_static_icons() + if not _pending_dto.is_empty(): + _apply_setup(_pending_dto, _pending_def) + _pending_dto.clear() + _pending_def.clear() + + static func affinity_icon(affinity: String) -> Texture2D: + var cached : Variant = _texture_cache.get(_affinity_icon_url(affinity), null) + if cached != null: + return cached as Texture2D + match affinity: "Lake", "Ocean", "Island", "Marsh", "Swamp": return AFFINITY_ICONS["Lake"] @@ -89,53 +150,7 @@ static func affinity_icon(affinity: String) -> Texture2D: _: return null -const RARITY_COLOR := { - "Common": Color(0.67, 0.67, 0.67), - "Uncommon": Color(0.27, 0.85, 0.27), - "Rare": Color(0.27, 0.53, 1.00), - "Epic": Color(0.67, 0.27, 1.00), - "Legendary": Color(1.00, 0.67, 0.13), -} -# ── Signals ─────────────────────────────────────────────────────────────────── - -## Emitted on mouse-click or screen-touch. -signal card_pressed(definition_id: String) - -# ── Node refs ───────────────────────────────────────────────────────────────── - -@onready var sp_label : Label = %SpLabel -@onready var st_label : Label = %StLabel -@onready var foil_label : Label = %FoilLabel -@onready var art_rect : ColorRect = %ArtRect -@onready var art_symbol : TextureRect = %ArtSymbol -@onready var name_label : Label = %NameLabel -@onready var type_label : Label = %TypeLabel -@onready var rarity_label : Label = %RarityLabel -@onready var dmg_label : Label = %DmgLabel -@onready var hp_label : Label = %HpLabel -@onready var def_label : Label = %DefLabel - -# ── State ───────────────────────────────────────────────────────────────────── - -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) @@ -147,107 +162,391 @@ func setup(dto: Dictionary, def: Dictionary = {}) -> void: 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", ""))) - var name := str(def.get("name", dto.get("name", ""))) + _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() - art_rect.color = AFFINITY_BG.get(_affinity, Color(0.18, 0.18, 0.24)) - art_symbol.texture = affinity_icon(_affinity) - - 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)) + name_label.text = name if not name.is_empty() else str(dto.get("name", "-")) + name_label.modulate = RARITY_COLOR.get(rarity, Color.WHITE) + type_label.text = card_type + type_label.tooltip_text = card_type + _apply_art(def) + _apply_meta(def, dto) _load_stats(def) _load_abilities(def) -## Toggle the selection highlight (arch-spirit picker). func set_selected(selected: bool) -> void: _is_selected = selected _apply_style() -## The cached definition ID this widget represents. func get_definition_id() -> String: return _definition_id -# ── Input ───────────────────────────────────────────────────────────────────── func _gui_input(event: InputEvent) -> void: - if event is InputEventMouseButton \ - and event.pressed and event.button_index == MOUSE_BUTTON_LEFT: + if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT: card_pressed.emit(_definition_id) accept_event() elif event is InputEventScreenTouch and event.pressed: card_pressed.emit(_definition_id) accept_event() -# ── Visuals ─────────────────────────────────────────────────────────────────── func _apply_style() -> void: var border: Color var width: int if _is_selected: border = Color(1.0, 1.0, 1.0) - width = 3 + width = 3 else: border = AFFINITY_BORDER.get(_affinity, Color(0.31, 0.38, 0.63)) - width = 2 + width = 2 + var s := StyleBoxFlat.new() - s.bg_color = Color(0.09, 0.09, 0.14) + s.bg_color = AFFINITY_BG.get(_affinity, Color(0.09, 0.09, 0.14)) s.border_color = border s.set_border_width_all(width) - s.set_corner_radius_all(6) + s.set_corner_radius_all(8) add_theme_stylebox_override("panel", s) -# ── Stats ───────────────────────────────────────────────────────────────────── + var art_style := StyleBoxFlat.new() + art_style.bg_color = Color(0.05, 0.05, 0.08, 0.92) + art_style.border_color = border + art_style.set_border_width_all(1) + art_style.set_corner_radius_all(6) + art_area.add_theme_stylebox_override("panel", art_style) + + +func _apply_art(def: Dictionary) -> void: + var art_url := _find_card_art_url(def) + _set_remote_texture(art_texture, art_url, DEFAULT_CARD_ART_URL) + affinity_icon_rect.texture = affinity_icon(_affinity) + _set_remote_texture(affinity_icon_rect, _affinity_icon_url(_affinity)) + affinity_icon_rect.tooltip_text = _affinity if not _affinity.is_empty() else "Affinity" + + +func _apply_meta(def: Dictionary, dto: Dictionary) -> void: + _set_remote_texture(set_icon, ICON_SET_URL) + set_icon.tooltip_text = "Card Set" + + var genus_text := _format_genus(def) + genus_label.text = genus_text + genus_label.tooltip_text = genus_text + + sp_label.text = _display_int_or_unknown(def.get("spCost", dto.get("spCost", null))) + sp_row.tooltip_text = "Spirit Point Cost" + sp_label.tooltip_text = "Spirit Point Cost" + sp_icon.tooltip_text = "Spirit Point Cost" + + var st_value: Variant = def.get("stCost", dto.get("stCost", null)) + var has_st := st_value != null and _to_int(st_value) > 0 + st_row.visible = has_st + if has_st: + st_label.text = _display_int(st_value) + st_row.tooltip_text = "Sacrifice Token Cost" + st_label.tooltip_text = "Sacrifice Token Cost" + st_icon.tooltip_text = "Sacrifice Token Cost" + func _load_stats(def: Dictionary) -> void: - var sp : Variant = def.get("spCost", null) - var st : Variant = def.get("stCost", null) - var dmg : Variant = def.get("damage", null) - var hp : Variant = def.get("maxHealth", null) - var dfs : Variant = def.get("maxDefense", null) - var mov : Variant = def.get("movementPoints", null) + var dmg: Variant = def.get("damage", null) + var hp: Variant = def.get("maxHealth", null) + var dfs: Variant = def.get("maxDefense", null) + var mov: Variant = def.get("movementPoints", null) - sp_label.text = ("◆%s" % str(sp)) if sp != null else "◆?" - st_label.text = ("⚡%s" % str(st)) if (st != null and int(st) > 0) else "" - st_label.visible = st != null and int(st) > 0 + attack_value.text = _display_int(dmg) + move_value.text = _display_int(mov) + range_value.text = _format_range(def) + hp_value.text = _display_int(hp) + def_value.text = _display_int(dfs) - dmg_label.text = "⚔ %s" % (str(dmg) if dmg != null else "–") - hp_label.text = "♥ %s" % (str(hp) if hp != null else "–") - def_label.text = "▲ %s" % (str(dfs) if dfs != null else "–") - - sp_label.tooltip_text = "Spirit Cost" - st_label.tooltip_text = "Stamina Cost" - dmg_label.tooltip_text = "Attack Damage" \ - + (" | Move: %s" % str(mov) if mov != null else "") - hp_label.tooltip_text = "Max Health" - def_label.tooltip_text = "Max Defense" + attack_badge.tooltip_text = _build_attack_tooltip(def) + range_badge.tooltip_text = _build_range_tooltip(def) + move_badge.tooltip_text = _build_move_tooltip(def) + hp_badge.tooltip_text = "Max Health" + def_badge.tooltip_text = "Max Defense" + attack_value.tooltip_text = attack_badge.tooltip_text + range_value.tooltip_text = range_badge.tooltip_text + move_value.tooltip_text = move_badge.tooltip_text + hp_value.tooltip_text = hp_badge.tooltip_text + def_value.tooltip_text = def_badge.tooltip_text func _load_abilities(def: Dictionary) -> void: - var json_str := str(def.get("abilities", "")) - if json_str.is_empty() or json_str == "[]": - return - var parsed: Variant = JSON.parse_string(json_str) - if typeof(parsed) != TYPE_ARRAY: - return + var ability_lines := _parse_ability_lines(def) + var count := ability_lines.size() + ability_value.text = str(count) + var tooltip := "Abilities" + if count > 0: + tooltip += "\n%s" % "\n".join(ability_lines) + ability_badge.tooltip_text = tooltip + ability_icon.tooltip_text = tooltip + ability_value.tooltip_text = tooltip + art_texture.tooltip_text = tooltip if count > 0 else "" + + +func _display_int(value: Variant) -> String: + return str(_to_int(value)) if value != null else "-" + + +func _display_int_or_unknown(value: Variant) -> String: + return str(_to_int(value)) if value != null else "?" + + +func _format_genus(def: Dictionary) -> String: + var genus: Variant = def.get("genus", []) + if typeof(genus) == TYPE_ARRAY and not (genus as Array).is_empty(): + var labels: PackedStringArray = [] + for tag in genus as Array: + labels.append(str(tag)) + return ", ".join(labels) + return "No Genus" + + +func _format_range(def: Dictionary) -> String: + var min_attack: Variant = def.get("minAttackRange", null) + var max_attack: Variant = def.get("maxAttackRange", null) + if min_attack != null or max_attack != null: + return _format_range_values(min_attack, max_attack) + + var min_channel: Variant = def.get("minChannelRange", null) + var max_channel: Variant = def.get("maxChannelRange", null) + if min_channel != null or max_channel != null: + return _format_range_values(min_channel, max_channel) + + return "-" + + +func _format_range_values(min_value: Variant, max_value: Variant) -> String: + if min_value == null and max_value == null: + return "-" + if min_value == null: + return str(_to_int(max_value)) + if max_value == null: + return str(_to_int(min_value)) + if _to_int(min_value) == _to_int(max_value): + return str(_to_int(min_value)) + return "%s-%s" % [str(_to_int(min_value)), str(_to_int(max_value))] + + +func _build_attack_tooltip(def: Dictionary) -> String: + var parts: PackedStringArray = [] + parts.append("Attack Damage") + var attack_type := str(def.get("attackType", "")) + if not attack_type.is_empty(): + parts.append("Type: %s" % attack_type) + var can_attack: Variant = def.get("canAttack", null) + if can_attack != null: + parts.append("Can Attack: %s" % ("Yes" if bool(can_attack) else "No")) + return "\n".join(parts) + + +func _build_move_tooltip(def: Dictionary) -> String: + var parts: PackedStringArray = [] + parts.append("Movement") + var movement_type := str(def.get("movementType", "")) + if not movement_type.is_empty(): + parts.append("Type: %s" % movement_type) + var can_move: Variant = def.get("canMove", null) + if can_move != null: + parts.append("Can Move: %s" % ("Yes" if bool(can_move) else "No")) + return "\n".join(parts) + + +func _build_range_tooltip(def: Dictionary) -> String: + var min_attack: Variant = def.get("minAttackRange", null) + var max_attack: Variant = def.get("maxAttackRange", null) + if min_attack != null or max_attack != null: + return "Attack Range\n%s" % _format_range_values(min_attack, max_attack) + + var min_channel: Variant = def.get("minChannelRange", null) + var max_channel: Variant = def.get("maxChannelRange", null) + if min_channel != null or max_channel != null: + return "Channel Range\n%s" % _format_range_values(min_channel, max_channel) + + return "Range" + + +func _parse_ability_lines(def: Dictionary) -> PackedStringArray: var lines: PackedStringArray = [] + var raw_value: Variant = def.get("abilitiesJson", def.get("abilities", "")) + if raw_value == null: + return lines + var json_str := str(raw_value).strip_edges() + if json_str.is_empty() or json_str in ["[]", "null", "NULL", ""]: + return lines + if not json_str.begins_with("["): + return lines + + var json := JSON.new() + var err := json.parse(json_str) + if err != OK: + return lines + + var parsed: Variant = json.data + if typeof(parsed) != TYPE_ARRAY: + return lines + for ab in parsed as Array: - if typeof(ab) == TYPE_DICTIONARY: - var d := ab as Dictionary - var n := str(d.get("name", d.get("Name", ""))) - var t := str(d.get("description", d.get("Description", ""))) - lines.append(("[%s] %s" % [n, t]) if not t.is_empty() else ("[%s]" % n)) - if not lines.is_empty(): - art_rect.tooltip_text = "\n".join(lines) + if typeof(ab) != TYPE_DICTIONARY: + continue + var d := ab as Dictionary + var name_ := str(d.get("name", d.get("Name", ""))) + var desc := str(d.get("description", d.get("Description", ""))) + if desc.is_empty(): + lines.append("[%s]" % name_) + else: + lines.append("[%s] %s" % [name_, desc]) + + return lines + + +func _find_card_art_url(def: Dictionary) -> String: + var assets: Variant = def.get("assets", []) + if typeof(assets) != TYPE_ARRAY: + return DEFAULT_CARD_ART_URL + + for asset in assets as Array: + if typeof(asset) != TYPE_DICTIONARY: + continue + var d := asset as Dictionary + if str(d.get("assetType", "")) == "Art2D": + return str(d.get("cdnUrl", DEFAULT_CARD_ART_URL)) + + return DEFAULT_CARD_ART_URL + + +func _load_static_icons() -> void: + DirAccess.make_dir_recursive_absolute(REMOTE_CACHE_DIR) + _set_remote_texture(sp_icon, ICON_SP_URL) + _set_remote_texture(st_icon, ICON_ST_URL) + _set_remote_texture(set_icon, ICON_SET_URL) + _set_remote_texture(move_icon, ICON_MOVE_URL) + _set_remote_texture(hp_icon, ICON_HP_URL) + _set_remote_texture(def_icon, ICON_DEF_URL) + _set_remote_texture(ability_icon, ICON_ABILITY_URL) + + +static func _affinity_icon_url(affinity: String) -> String: + if affinity.is_empty(): + return "" + return "%s/%s.png" % [GRAPHICS_BASE_URL, affinity.uri_encode()] + + +func _set_remote_texture(target: TextureRect, url: String, fallback_url: String = "") -> void: + var final_url := url + if final_url.is_empty(): + final_url = fallback_url + if final_url.is_empty() or not is_instance_valid(target): + return + + var cached: Variant = _texture_cache.get(final_url, null) + if cached != null: + target.texture = cached as Texture2D + return + + var cache_path := _cache_path_for_url(final_url) + var disk_texture := _load_texture_from_disk(final_url, cache_path) + if disk_texture != null: + _texture_cache[final_url] = disk_texture + target.texture = disk_texture + return + + if not final_url.begins_with("http"): + return + + var requester := HTTPRequest.new() + requester.use_threads = true + add_child(requester) + requester.request_completed.connect( + func(_result: int, response_code: int, _headers: PackedStringArray, body: PackedByteArray) -> void: + if response_code >= 200 and response_code < 300: + var texture := _texture_from_bytes(final_url, body) + if texture != null: + _write_cache_file(cache_path, body) + _texture_cache[final_url] = texture + if is_instance_valid(target): + target.texture = texture + elif not fallback_url.is_empty() and final_url != fallback_url: + _set_remote_texture(target, fallback_url) + elif not fallback_url.is_empty() and final_url != fallback_url: + _set_remote_texture(target, fallback_url) + requester.queue_free() + ) + + var err := requester.request(final_url) + if err != OK: + requester.queue_free() + if not fallback_url.is_empty() and final_url != fallback_url: + _set_remote_texture(target, fallback_url) + + +func _load_texture_from_disk(url: String, cache_path: String) -> Texture2D: + if not FileAccess.file_exists(cache_path): + return null + var file := FileAccess.open(cache_path, FileAccess.READ) + if file == null: + return null + var bytes := file.get_buffer(file.get_length()) + file.close() + return _texture_from_bytes(url, bytes) + + +func _write_cache_file(cache_path: String, bytes: PackedByteArray) -> void: + DirAccess.make_dir_recursive_absolute(REMOTE_CACHE_DIR) + var file := FileAccess.open(cache_path, FileAccess.WRITE) + if file == null: + return + file.store_buffer(bytes) + file.close() + + +func _cache_path_for_url(url: String) -> String: + var ext := url.get_file().get_extension().to_lower() + if ext.is_empty(): + ext = "bin" + return "%s/%s.%s" % [REMOTE_CACHE_DIR, url.sha256_text(), ext] + + +func _texture_from_bytes(url: String, body: PackedByteArray) -> Texture2D: + var image := Image.new() + var ext := url.get_file().get_extension().to_lower() + var err := ERR_FILE_UNRECOGNIZED + + match ext: + "png": + err = image.load_png_from_buffer(body) + "jpg", "jpeg": + err = image.load_jpg_from_buffer(body) + "webp": + err = image.load_webp_from_buffer(body) + "svg": + err = image.load_svg_from_buffer(body) + _: + err = image.load_png_from_buffer(body) + if err != OK: + err = image.load_jpg_from_buffer(body) + + if err != OK: + return null + + return ImageTexture.create_from_image(image) + + +func _to_int(value: Variant) -> int: + match typeof(value): + TYPE_INT: + return int(value) + TYPE_FLOAT: + return int(round(float(value))) + TYPE_STRING: + var text := str(value) + return int(round(float(text))) if text.contains(".") else int(text) + _: + return int(value) diff --git a/Client/origin-client/scenes/collection/views/cards_view.gd b/Client/origin-client/scenes/collection/views/cards_view.gd index 86f52a5..183ac6e 100644 --- a/Client/origin-client/scenes/collection/views/cards_view.gd +++ b/Client/origin-client/scenes/collection/views/cards_view.gd @@ -10,6 +10,7 @@ extends VBoxContainer const CARD_WIDGET := preload("res://scenes/collection/components/CardWidget.tscn") const PAGE_SIZE := 20 +const CARD_WIDTH_ESTIMATE := 168 # ── Node references ─────────────────────────────────────────────────────────── @@ -86,8 +87,10 @@ func _populate_affinity_options() -> void: # ── Responsive columns ──────────────────────────────────────────────────────── func _update_columns() -> void: - var vp_w := get_viewport_rect().size.x - card_grid.columns = max(2, int(vp_w / 160)) + var available_width := card_grid.size.x + if available_width <= 0.0: + available_width = get_viewport_rect().size.x - 16.0 + card_grid.columns = max(1, int(available_width / CARD_WIDTH_ESTIMATE)) # ── Data fetching ─────────────────────────────────────────────────────────────