- Add Boosters, Decks, Cosmetics, Cards (marketplace) tabs - Sort per-tab: name, price, card count, type, set (boosters) - Cards tab: filter by rarity and card type, sort by price/rarity/name - StoreItemRow gets 72x72 art TextureRect with async HTTP image loading; falls back to cdn.aeternalisgames.com/sor-assets/cardart/0_No-Card-Art.jpg - USD prices shown as greyed "$X.XX (coming soon)" — buy disabled - "Buy OP" button in header present but disabled (USD flow not yet live) - setup_listing() on StoreItemRow handles marketplace card listings with auction bid count, current bid, and Bid/Buy button labels Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
416 lines
15 KiB
GDScript
416 lines
15 KiB
GDScript
extends VBoxContainer
|
||
## Bazaar — Boosters, Decks, Cosmetics, and Cards marketplace.
|
||
##
|
||
## Four tabs each with sort controls. The Cards tab additionally has
|
||
## rarity/type filters and loads from the P2P marketplace.
|
||
## Origin Points purchases are live. USD prices are shown but disabled.
|
||
|
||
const STORE_ITEM_ROW := preload("res://scenes/bazaar/components/StoreItemRow.tscn")
|
||
|
||
const FALLBACK_ART := "https://cdn.aeternalisgames.com/sor-assets/cardart/0_No-Card-Art.jpg"
|
||
|
||
const RARITY_ORDER := { "Common": 0, "Uncommon": 1, "Rare": 2, "Epic": 3, "Legendary": 4 }
|
||
|
||
enum Tab { BOOSTERS, DECKS, COSMETICS, CARDS }
|
||
|
||
# ── Node references ────────────────────────────────────────────────────────────
|
||
|
||
@onready var back_btn : Button = %BackBtn
|
||
@onready var balance_label : Label = %BalanceLabel
|
||
@onready var buy_op_btn : Button = %BuyOpBtn
|
||
@onready var boosters_tab_btn : Button = %BoostersTabBtn
|
||
@onready var decks_tab_btn : Button = %DecksTabBtn
|
||
@onready var cosmetics_tab_btn : Button = %CosmeticsTabBtn
|
||
@onready var cards_tab_btn : Button = %CardsTabBtn
|
||
@onready var sort_option : OptionButton = %SortOption
|
||
@onready var filter_sep : VSeparator = %FilterSep
|
||
@onready var rarity_label : Label = %RarityLabel
|
||
@onready var rarity_option : OptionButton = %RarityOption
|
||
@onready var type_label : Label = %TypeLabel
|
||
@onready var type_option : OptionButton = %TypeOption
|
||
@onready var item_list : VBoxContainer = %ItemList
|
||
@onready var loading_label : Label = %LoadingLabel
|
||
@onready var empty_label : Label = %EmptyLabel
|
||
@onready var confirm_dialog : ConfirmationDialog = %ConfirmDialog
|
||
@onready var result_dialog : AcceptDialog = %ResultDialog
|
||
|
||
# ── Sort option labels per tab ─────────────────────────────────────────────────
|
||
|
||
const SORT_LABELS := {
|
||
Tab.BOOSTERS: ["Name A–Z", "Price ↑", "Price ↓", "Cards ↑", "Set"],
|
||
Tab.DECKS: ["Name A–Z", "Price ↑", "Price ↓", "Cards ↑"],
|
||
Tab.COSMETICS: ["Name A–Z", "Price ↑", "Price ↓", "Type"],
|
||
Tab.CARDS: ["Price ↑", "Price ↓", "Name A–Z", "Rarity"],
|
||
}
|
||
|
||
# ── State ─────────────────────────────────────────────────────────────────────
|
||
|
||
var _tab : Tab = Tab.BOOSTERS
|
||
var _packs : Array = []
|
||
var _decks : Array = []
|
||
var _cosmetics : Array = []
|
||
var _listings : Array = [] # Cards tab (marketplace)
|
||
|
||
var _store_loaded := false
|
||
var _bal_loaded := false
|
||
var _listings_loaded := false
|
||
|
||
var _pending_item : Dictionary = {}
|
||
var _buying := false
|
||
|
||
var _sort : Dictionary = { Tab.BOOSTERS: 0, Tab.DECKS: 0, Tab.COSMETICS: 0, Tab.CARDS: 0 }
|
||
var _rarity_filter : String = ""
|
||
var _type_filter : String = ""
|
||
|
||
# ── Lifecycle ─────────────────────────────────────────────────────────────────
|
||
|
||
func _ready() -> void:
|
||
back_btn.pressed.connect(_on_back)
|
||
boosters_tab_btn.pressed.connect(func(): _switch_tab(Tab.BOOSTERS))
|
||
decks_tab_btn.pressed.connect(func(): _switch_tab(Tab.DECKS))
|
||
cosmetics_tab_btn.pressed.connect(func(): _switch_tab(Tab.COSMETICS))
|
||
cards_tab_btn.pressed.connect(func(): _switch_tab(Tab.CARDS))
|
||
|
||
sort_option.item_selected.connect(_on_sort_changed)
|
||
rarity_option.item_selected.connect(_on_rarity_changed)
|
||
type_option.item_selected.connect(_on_type_changed)
|
||
confirm_dialog.confirmed.connect(_on_purchase_confirmed)
|
||
|
||
buy_op_btn.disabled = true # USD flow not yet available
|
||
|
||
_apply_tab_styles()
|
||
loading_label.visible = true
|
||
empty_label.visible = false
|
||
|
||
_fetch_data()
|
||
|
||
# ── Data fetching ─────────────────────────────────────────────────────────────
|
||
|
||
func _fetch_data() -> void:
|
||
_store_loaded = false
|
||
_bal_loaded = false
|
||
Network.request("bazaar.get_store", {}, _on_store_ok, _on_store_err)
|
||
Network.request("bazaar.get_my_balance", {}, _on_balance_ok, _on_balance_err)
|
||
|
||
|
||
func _fetch_listings() -> void:
|
||
_listings_loaded = false
|
||
Network.request(
|
||
"bazaar.get_listings",
|
||
{ "page": 1, "pageSize": 50 },
|
||
_on_listings_ok,
|
||
_on_listings_err
|
||
)
|
||
|
||
|
||
func _on_store_ok(_t: String, p: Variant) -> void:
|
||
var d := p as Dictionary
|
||
_packs = d.get("packs", [])
|
||
_decks = d.get("decks", [])
|
||
_cosmetics = d.get("cosmetics", [])
|
||
_store_loaded = true
|
||
_check_store_done()
|
||
|
||
|
||
func _on_store_err(code: String, _msg: String) -> void:
|
||
push_warning("Bazaar: get_store failed — %s" % code)
|
||
_store_loaded = true
|
||
_check_store_done()
|
||
|
||
|
||
func _on_balance_ok(_t: String, p: Variant) -> void:
|
||
balance_label.text = "◆ %d OP" % int((p as Dictionary).get("originPoints", 0))
|
||
_bal_loaded = true
|
||
_check_store_done()
|
||
|
||
|
||
func _on_balance_err(code: String, _msg: String) -> void:
|
||
push_warning("Bazaar: balance failed — %s" % code)
|
||
balance_label.text = "◆ — OP"
|
||
_bal_loaded = true
|
||
_check_store_done()
|
||
|
||
|
||
func _check_store_done() -> void:
|
||
if not (_store_loaded and _bal_loaded):
|
||
return
|
||
loading_label.visible = false
|
||
_setup_filter_bar()
|
||
_render_tab()
|
||
|
||
|
||
func _on_listings_ok(_t: String, p: Variant) -> void:
|
||
_listings = (p as Dictionary).get("listings", [])
|
||
_listings_loaded = true
|
||
_rebuild_type_filter()
|
||
loading_label.visible = false
|
||
_render_tab()
|
||
|
||
|
||
func _on_listings_err(code: String, _msg: String) -> void:
|
||
push_warning("Bazaar: get_listings failed — %s" % code)
|
||
_listings_loaded = true
|
||
loading_label.visible = false
|
||
_render_tab()
|
||
|
||
# ── Tabs ──────────────────────────────────────────────────────────────────────
|
||
|
||
func _switch_tab(tab: Tab) -> void:
|
||
_tab = tab
|
||
_apply_tab_styles()
|
||
_setup_filter_bar()
|
||
|
||
if tab == Tab.CARDS and not _listings_loaded:
|
||
loading_label.visible = true
|
||
empty_label.visible = false
|
||
_clear_list()
|
||
_fetch_listings()
|
||
return
|
||
|
||
if _store_loaded and _bal_loaded:
|
||
_render_tab()
|
||
|
||
|
||
func _apply_tab_styles() -> void:
|
||
_style_tab(boosters_tab_btn, _tab == Tab.BOOSTERS)
|
||
_style_tab(decks_tab_btn, _tab == Tab.DECKS)
|
||
_style_tab(cosmetics_tab_btn, _tab == Tab.COSMETICS)
|
||
_style_tab(cards_tab_btn, _tab == Tab.CARDS)
|
||
|
||
|
||
func _style_tab(btn: Button, active: bool) -> void:
|
||
var s := StyleBoxFlat.new()
|
||
s.corner_radius_top_left = 6
|
||
s.corner_radius_top_right = 6
|
||
s.corner_radius_bottom_left = 6
|
||
s.corner_radius_bottom_right = 6
|
||
s.bg_color = Color(0.27, 0.47, 0.80, 1.0) if active else Color(0.18, 0.18, 0.26, 1.0)
|
||
s.border_width_bottom = 2 if active else 0
|
||
s.border_color = Color(0.5, 0.72, 1.0)
|
||
btn.add_theme_stylebox_override("normal", s)
|
||
btn.add_theme_stylebox_override("hover", s)
|
||
btn.add_theme_stylebox_override("pressed", s)
|
||
|
||
# ── Filter / sort bar ─────────────────────────────────────────────────────────
|
||
|
||
func _setup_filter_bar() -> void:
|
||
sort_option.clear()
|
||
for lbl: String in (SORT_LABELS as Dictionary)[_tab]:
|
||
sort_option.add_item(lbl)
|
||
sort_option.selected = _sort[_tab]
|
||
|
||
var is_cards := _tab == Tab.CARDS
|
||
filter_sep.visible = is_cards
|
||
rarity_label.visible = is_cards
|
||
rarity_option.visible = is_cards
|
||
type_label.visible = is_cards
|
||
type_option.visible = is_cards
|
||
|
||
|
||
func _rebuild_type_filter() -> void:
|
||
var types := PackedStringArray()
|
||
for l: Dictionary in _listings:
|
||
var t: String = l.get("cardType", "")
|
||
if not t.is_empty() and t not in types:
|
||
types.append(t)
|
||
types.sort()
|
||
|
||
type_option.clear()
|
||
type_option.add_item("All Types")
|
||
for t: String in types:
|
||
type_option.add_item(t)
|
||
|
||
rarity_option.clear()
|
||
rarity_option.add_item("All Rarities")
|
||
for r: String in ["Common", "Uncommon", "Rare", "Epic", "Legendary"]:
|
||
rarity_option.add_item(r)
|
||
|
||
|
||
func _on_sort_changed(idx: int) -> void:
|
||
_sort[_tab] = idx
|
||
_render_tab()
|
||
|
||
|
||
func _on_rarity_changed(idx: int) -> void:
|
||
_rarity_filter = "" if idx == 0 else rarity_option.get_item_text(idx)
|
||
_render_tab()
|
||
|
||
|
||
func _on_type_changed(idx: int) -> void:
|
||
_type_filter = "" if idx == 0 else type_option.get_item_text(idx)
|
||
_render_tab()
|
||
|
||
# ── Render ────────────────────────────────────────────────────────────────────
|
||
|
||
func _render_tab() -> void:
|
||
_clear_list()
|
||
|
||
var items: Array
|
||
match _tab:
|
||
Tab.BOOSTERS: items = _packs.duplicate()
|
||
Tab.DECKS: items = _decks.duplicate()
|
||
Tab.COSMETICS: items = _cosmetics.duplicate()
|
||
Tab.CARDS: items = _listings.duplicate()
|
||
|
||
items = _sort_items(items)
|
||
if _tab == Tab.CARDS:
|
||
items = _filter_cards(items)
|
||
|
||
empty_label.visible = items.is_empty()
|
||
|
||
for item: Dictionary in items:
|
||
var row := STORE_ITEM_ROW.instantiate()
|
||
item_list.add_child(row)
|
||
if _tab == Tab.CARDS:
|
||
row.setup_listing(item, FALLBACK_ART)
|
||
else:
|
||
row.setup(item, FALLBACK_ART)
|
||
row.buy_pressed.connect(_on_buy_pressed)
|
||
|
||
|
||
func _clear_list() -> void:
|
||
for c in item_list.get_children():
|
||
c.queue_free()
|
||
|
||
|
||
func _sort_items(items: Array) -> Array:
|
||
var idx: int = _sort[_tab]
|
||
match _tab:
|
||
Tab.BOOSTERS:
|
||
match idx:
|
||
0: items.sort_custom(func(a, b): return a.get("name","") < b.get("name",""))
|
||
1: items.sort_custom(func(a, b): return a.get("originPointPrice",0) < b.get("originPointPrice",0))
|
||
2: items.sort_custom(func(a, b): return a.get("originPointPrice",0) > b.get("originPointPrice",0))
|
||
3: items.sort_custom(func(a, b): return a.get("totalSlots",0) < b.get("totalSlots",0))
|
||
4: items.sort_custom(func(a, b): return str(a.get("cardSetId","")) < str(b.get("cardSetId","")))
|
||
Tab.DECKS:
|
||
match idx:
|
||
0: items.sort_custom(func(a, b): return a.get("name","") < b.get("name",""))
|
||
1: items.sort_custom(func(a, b): return a.get("originPointPrice",0) < b.get("originPointPrice",0))
|
||
2: items.sort_custom(func(a, b): return a.get("originPointPrice",0) > b.get("originPointPrice",0))
|
||
3: items.sort_custom(func(a, b): return a.get("totalCards",0) < b.get("totalCards",0))
|
||
Tab.COSMETICS:
|
||
match idx:
|
||
0: items.sort_custom(func(a, b): return a.get("name","") < b.get("name",""))
|
||
1: items.sort_custom(func(a, b): return a.get("originPointPrice",0) < b.get("originPointPrice",0))
|
||
2: items.sort_custom(func(a, b): return a.get("originPointPrice",0) > b.get("originPointPrice",0))
|
||
3: items.sort_custom(func(a, b): return a.get("cosmeticType","") < b.get("cosmeticType",""))
|
||
Tab.CARDS:
|
||
match idx:
|
||
0: items.sort_custom(func(a, b): return float(a.get("price",0)) < float(b.get("price",0)))
|
||
1: items.sort_custom(func(a, b): return float(a.get("price",0)) > float(b.get("price",0)))
|
||
2: items.sort_custom(func(a, b): return a.get("cardName","") < b.get("cardName",""))
|
||
3: items.sort_custom(func(a, b):
|
||
return RARITY_ORDER.get(a.get("rarity",""), 99) < RARITY_ORDER.get(b.get("rarity",""), 99))
|
||
return items
|
||
|
||
|
||
func _filter_cards(items: Array) -> Array:
|
||
return items.filter(func(item: Dictionary) -> bool:
|
||
if not _rarity_filter.is_empty() and item.get("rarity","") != _rarity_filter:
|
||
return false
|
||
if not _type_filter.is_empty() and item.get("cardType","") != _type_filter:
|
||
return false
|
||
return true)
|
||
|
||
# ── Purchase flow ─────────────────────────────────────────────────────────────
|
||
|
||
func _on_buy_pressed(item: Dictionary) -> void:
|
||
_pending_item = item
|
||
var name_str : String = item.get("name", item.get("cardName", "?"))
|
||
var price_str : String
|
||
if _tab == Tab.CARDS:
|
||
price_str = "◆ %d OP" % int(float(item.get("price", 0)))
|
||
else:
|
||
price_str = "◆ %d OP" % int(item.get("originPointPrice", 0))
|
||
confirm_dialog.dialog_text = "Buy \"%s\" for %s?" % [name_str, price_str]
|
||
confirm_dialog.popup_centered()
|
||
|
||
|
||
func _on_purchase_confirmed() -> void:
|
||
if _pending_item.is_empty() or _buying:
|
||
return
|
||
_buying = true
|
||
|
||
var item := _pending_item
|
||
var tab := _tab
|
||
var id_str : String = str(item.get("id", ""))
|
||
|
||
var req_type : String
|
||
var req_payload : Dictionary
|
||
match tab:
|
||
Tab.BOOSTERS:
|
||
req_type = "bazaar.buy_booster_pack"
|
||
req_payload = { "packId": id_str }
|
||
Tab.DECKS:
|
||
req_type = "bazaar.buy_prebuilt_deck"
|
||
req_payload = { "deckId": id_str }
|
||
Tab.COSMETICS:
|
||
req_type = "bazaar.buy_cosmetic"
|
||
req_payload = { "cosmeticId": id_str }
|
||
Tab.CARDS:
|
||
req_type = "bazaar.buy_listing"
|
||
req_payload = { "listingId": id_str }
|
||
|
||
Network.request(req_type, req_payload,
|
||
func(_t: String, p: Variant): _on_purchase_ok(tab, p),
|
||
func(code: String, msg: String): _on_purchase_err(code, msg))
|
||
|
||
|
||
func _on_purchase_ok(tab: Tab, p: Variant) -> void:
|
||
_buying = false
|
||
var d := p as Dictionary
|
||
var new_bal: int = int(d.get("newOriginPointBalance", 0))
|
||
if new_bal > 0:
|
||
balance_label.text = "◆ %d OP" % new_bal
|
||
|
||
match tab:
|
||
Tab.BOOSTERS:
|
||
_show_pack_result(d.get("cardsOpened", []))
|
||
Tab.DECKS:
|
||
var dname: String = d.get("deckName", _pending_item.get("name", "deck"))
|
||
_show_result("Purchase Complete", "Deck \"%s\" added to your collection!" % dname)
|
||
Tab.COSMETICS:
|
||
_show_result("Purchase Complete", "\"%s\" added to your account!" % _pending_item.get("name", "item"))
|
||
Tab.CARDS:
|
||
var sold_id: String = str(_pending_item.get("id", ""))
|
||
_listings = _listings.filter(func(l: Dictionary) -> bool:
|
||
return str(l.get("id", "")) != sold_id)
|
||
_show_result("Purchase Complete", "Card purchased and added to your collection!")
|
||
|
||
_pending_item = {}
|
||
|
||
|
||
func _on_purchase_err(code: String, msg: String) -> void:
|
||
_buying = false
|
||
_pending_item = {}
|
||
_show_result("Purchase Failed", "Error: %s\n%s" % [code, msg])
|
||
|
||
|
||
func _show_pack_result(cards: Array) -> void:
|
||
var lines := PackedStringArray()
|
||
for card: Dictionary in cards:
|
||
var foil : String = " ✦" if bool(card.get("isFoil", false)) else ""
|
||
var serial = card.get("serialNumber", null)
|
||
var snum : String = " #%d" % int(serial) if serial != null else ""
|
||
lines.append("%s · %s · %s%s%s" % [
|
||
card.get("name", "?"),
|
||
card.get("rarity", ""),
|
||
card.get("affinity", ""),
|
||
foil, snum,
|
||
])
|
||
result_dialog.title = "Pack Opened! (%d cards)" % cards.size()
|
||
result_dialog.dialog_text = "\n".join(lines)
|
||
result_dialog.popup_centered()
|
||
|
||
|
||
func _show_result(title: String, body: String) -> void:
|
||
result_dialog.title = title
|
||
result_dialog.dialog_text = body
|
||
result_dialog.popup_centered()
|
||
|
||
# ── Navigation ─────────────────────────────────────────────────────────────────
|
||
|
||
func _on_back() -> void:
|
||
get_tree().change_scene_to_file("res://scenes/main/MainScreen.tscn")
|