Add card salvage system and player storefront / trading features
Server: - CardSalvageValues: rarity-base + (SpCost+StCost)*CostMultiplier formula, foil 2x - CollectionSalvageCardHandler: collection.salvage_card — validates ownership, tradeable, not listed, deck copy check, then atomically deletes card + credits OP - BazaarGetPlayerShopHandler: bazaar.get_player_shop — paginated active listings for any seller with their display name (public read endpoint) - BazaarGetSuggestedPriceHandler: bazaar.get_suggested_price — recent sale avg if ≥3 sales, otherwise 4× salvage floor - Added GetPlayerShopRequest/Response + GetSuggestedPriceRequest/Response DTOs - Added SalvageCardRequest/Response DTOs - Registered all 3 new handlers in their respective ServiceRegistration files Client: - card_detail_popup: List for Sale form (with live price suggestion) + Salvage button with OP preview; both gated on IsTradeable - salvage_confirm_popup: confirmation modal that calls collection.salvage_card, emits confirmed(player_card_id, op_awarded) on success - bazaar_screen: My Shop tab (own active listings + cancel), player storefront search by account ID, sort options for own listings 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>
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
extends VBoxContainer
|
||||
## Bazaar — Boosters, Decks, Cosmetics, and Cards marketplace.
|
||||
## Bazaar — Boosters, Decks, Cosmetics, Cards marketplace, and My Shop.
|
||||
##
|
||||
## 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.
|
||||
## Five tabs with sort/filter controls.
|
||||
## Cards tab: P2P marketplace with rarity/type filtering.
|
||||
## My Shop tab: own active listings with cancel + re-list actions, plus a
|
||||
## search field to navigate to another player's storefront.
|
||||
|
||||
const STORE_ITEM_ROW := preload("res://scenes/bazaar/components/StoreItemRow.tscn")
|
||||
|
||||
@@ -11,7 +12,7 @@ const FALLBACK_ART := "https://cdn.aeternalisgames.com/sor-assets/cardart/0_No-C
|
||||
|
||||
const RARITY_ORDER := { "Common": 0, "Uncommon": 1, "Rare": 2, "Epic": 3, "Legendary": 4 }
|
||||
|
||||
enum Tab { BOOSTERS, DECKS, COSMETICS, CARDS }
|
||||
enum Tab { BOOSTERS, DECKS, COSMETICS, CARDS, MY_SHOP }
|
||||
|
||||
# ── Node references ────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -22,6 +23,7 @@ enum Tab { BOOSTERS, DECKS, COSMETICS, CARDS }
|
||||
@onready var decks_tab_btn : Button = %DecksTabBtn
|
||||
@onready var cosmetics_tab_btn : Button = %CosmeticsTabBtn
|
||||
@onready var cards_tab_btn : Button = %CardsTabBtn
|
||||
@onready var my_shop_tab_btn : Button = %MyShopTabBtn
|
||||
@onready var sort_option : OptionButton = %SortOption
|
||||
@onready var filter_sep : VSeparator = %FilterSep
|
||||
@onready var rarity_label : Label = %RarityLabel
|
||||
@@ -33,6 +35,10 @@ enum Tab { BOOSTERS, DECKS, COSMETICS, CARDS }
|
||||
@onready var empty_label : Label = %EmptyLabel
|
||||
@onready var confirm_dialog : ConfirmationDialog = %ConfirmDialog
|
||||
@onready var result_dialog : AcceptDialog = %ResultDialog
|
||||
# My Shop tab extras
|
||||
@onready var player_shop_row : HBoxContainer = %PlayerShopRow
|
||||
@onready var player_shop_input : LineEdit = %PlayerShopInput
|
||||
@onready var player_shop_btn : Button = %PlayerShopBtn
|
||||
|
||||
# ── Sort option labels per tab ─────────────────────────────────────────────────
|
||||
|
||||
@@ -41,6 +47,7 @@ const SORT_LABELS := {
|
||||
Tab.DECKS: ["Name A–Z", "Price ↑", "Price ↓", "Cards ↑"],
|
||||
Tab.COSMETICS: ["Name A–Z", "Price ↑", "Price ↓", "Type"],
|
||||
Tab.CARDS: ["Price ↑", "Price ↓", "Name A–Z", "Rarity"],
|
||||
Tab.MY_SHOP: ["Listed ↓", "Price ↑", "Price ↓"],
|
||||
}
|
||||
|
||||
# ── State ─────────────────────────────────────────────────────────────────────
|
||||
@@ -50,15 +57,20 @@ var _packs : Array = []
|
||||
var _decks : Array = []
|
||||
var _cosmetics : Array = []
|
||||
var _listings : Array = [] # Cards tab (marketplace)
|
||||
var _my_listings: Array = [] # My Shop tab
|
||||
|
||||
var _store_loaded := false
|
||||
var _bal_loaded := false
|
||||
var _listings_loaded := false
|
||||
var _store_loaded := false
|
||||
var _bal_loaded := false
|
||||
var _listings_loaded := false
|
||||
var _my_shop_loaded := false
|
||||
|
||||
var _pending_item : Dictionary = {}
|
||||
var _buying := false
|
||||
var _pending_item : Dictionary = {}
|
||||
var _pending_cancel_id : String = ""
|
||||
var _buying := false
|
||||
|
||||
var _sort : Dictionary = { Tab.BOOSTERS: 0, Tab.DECKS: 0, Tab.COSMETICS: 0, Tab.CARDS: 0 }
|
||||
var _sort : Dictionary = {
|
||||
Tab.BOOSTERS: 0, Tab.DECKS: 0, Tab.COSMETICS: 0, Tab.CARDS: 0, Tab.MY_SHOP: 0
|
||||
}
|
||||
var _rarity_filter : String = ""
|
||||
var _type_filter : String = ""
|
||||
|
||||
@@ -71,11 +83,13 @@ func _ready() -> void:
|
||||
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))
|
||||
my_shop_tab_btn.pressed.connect(func(): _switch_tab(Tab.MY_SHOP))
|
||||
|
||||
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)
|
||||
player_shop_btn.pressed.connect(_on_player_shop_search)
|
||||
|
||||
buy_op_btn.disabled = true # USD flow not yet available
|
||||
|
||||
@@ -154,6 +168,30 @@ func _on_listings_err(code: String, _msg: String) -> void:
|
||||
loading_label.visible = false
|
||||
_render_tab()
|
||||
|
||||
|
||||
func _fetch_my_listings() -> void:
|
||||
_my_shop_loaded = false
|
||||
Network.request(
|
||||
"bazaar.get_my_listings",
|
||||
{ "statusFilter": "Active" },
|
||||
_on_my_listings_ok,
|
||||
_on_my_listings_err
|
||||
)
|
||||
|
||||
|
||||
func _on_my_listings_ok(_t: String, p: Variant) -> void:
|
||||
_my_listings = (p as Dictionary).get("listings", [])
|
||||
_my_shop_loaded = true
|
||||
loading_label.visible = false
|
||||
_render_tab()
|
||||
|
||||
|
||||
func _on_my_listings_err(code: String, _msg: String) -> void:
|
||||
push_warning("Bazaar: get_my_listings failed — %s" % code)
|
||||
_my_shop_loaded = true
|
||||
loading_label.visible = false
|
||||
_render_tab()
|
||||
|
||||
# ── Tabs ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
func _switch_tab(tab: Tab) -> void:
|
||||
@@ -168,6 +206,13 @@ func _switch_tab(tab: Tab) -> void:
|
||||
_fetch_listings()
|
||||
return
|
||||
|
||||
if tab == Tab.MY_SHOP and not _my_shop_loaded:
|
||||
loading_label.visible = true
|
||||
empty_label.visible = false
|
||||
_clear_list()
|
||||
_fetch_my_listings()
|
||||
return
|
||||
|
||||
if _store_loaded and _bal_loaded:
|
||||
_render_tab()
|
||||
|
||||
@@ -177,6 +222,7 @@ func _apply_tab_styles() -> void:
|
||||
_style_tab(decks_tab_btn, _tab == Tab.DECKS)
|
||||
_style_tab(cosmetics_tab_btn, _tab == Tab.COSMETICS)
|
||||
_style_tab(cards_tab_btn, _tab == Tab.CARDS)
|
||||
_style_tab(my_shop_tab_btn, _tab == Tab.MY_SHOP)
|
||||
|
||||
|
||||
func _style_tab(btn: Button, active: bool) -> void:
|
||||
@@ -200,12 +246,15 @@ func _setup_filter_bar() -> void:
|
||||
sort_option.add_item(lbl)
|
||||
sort_option.selected = _sort[_tab]
|
||||
|
||||
var is_cards := _tab == Tab.CARDS
|
||||
var is_cards := _tab == Tab.CARDS
|
||||
var is_my_shop := _tab == Tab.MY_SHOP
|
||||
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
|
||||
# My Shop: show player shop search row
|
||||
player_shop_row.visible = is_my_shop
|
||||
|
||||
|
||||
func _rebuild_type_filter() -> void:
|
||||
@@ -252,6 +301,7 @@ func _render_tab() -> void:
|
||||
Tab.DECKS: items = _decks.duplicate()
|
||||
Tab.COSMETICS: items = _cosmetics.duplicate()
|
||||
Tab.CARDS: items = _listings.duplicate()
|
||||
Tab.MY_SHOP: items = _my_listings.duplicate()
|
||||
|
||||
items = _sort_items(items)
|
||||
if _tab == Tab.CARDS:
|
||||
@@ -264,9 +314,15 @@ func _render_tab() -> void:
|
||||
item_list.add_child(row)
|
||||
if _tab == Tab.CARDS:
|
||||
row.setup_listing(item, FALLBACK_ART)
|
||||
elif _tab == Tab.MY_SHOP:
|
||||
row.setup_listing(item, FALLBACK_ART)
|
||||
# Override buy button label to "Cancel" for own listings.
|
||||
if row.has_method("set_action_label"):
|
||||
row.set_action_label("Cancel")
|
||||
row.buy_pressed.connect(_on_cancel_listing_pressed)
|
||||
else:
|
||||
row.setup(item, FALLBACK_ART)
|
||||
row.buy_pressed.connect(_on_buy_pressed)
|
||||
row.buy_pressed.connect(_on_buy_pressed)
|
||||
|
||||
|
||||
func _clear_list() -> void:
|
||||
@@ -303,6 +359,11 @@ func _sort_items(items: Array) -> Array:
|
||||
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))
|
||||
Tab.MY_SHOP:
|
||||
match idx:
|
||||
0: items.sort_custom(func(a, b): return str(a.get("listedAt","")) > str(b.get("listedAt","")))
|
||||
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 float(a.get("price",0)) > float(b.get("price",0)))
|
||||
return items
|
||||
|
||||
|
||||
@@ -410,6 +471,78 @@ func _show_result(title: String, body: String) -> void:
|
||||
result_dialog.dialog_text = body
|
||||
result_dialog.popup_centered()
|
||||
|
||||
# ── My Shop: cancel listing ────────────────────────────────────────────────────
|
||||
|
||||
func _on_cancel_listing_pressed(item: Dictionary) -> void:
|
||||
var listing_id : String = str(item.get("id", ""))
|
||||
var card_name : String = item.get("cardName", "this listing")
|
||||
_pending_cancel_id = listing_id
|
||||
confirm_dialog.dialog_text = "Cancel listing for \"%s\"?" % card_name
|
||||
confirm_dialog.popup_centered()
|
||||
# Re-route the confirmed signal to the cancel handler for this press.
|
||||
if confirm_dialog.confirmed.is_connected(_on_purchase_confirmed):
|
||||
confirm_dialog.confirmed.disconnect(_on_purchase_confirmed)
|
||||
if not confirm_dialog.confirmed.is_connected(_on_cancel_listing_confirmed):
|
||||
confirm_dialog.confirmed.connect(_on_cancel_listing_confirmed, CONNECT_ONE_SHOT)
|
||||
|
||||
|
||||
func _on_cancel_listing_confirmed() -> void:
|
||||
if _pending_cancel_id.is_empty():
|
||||
return
|
||||
var lid := _pending_cancel_id
|
||||
_pending_cancel_id = ""
|
||||
Network.request(
|
||||
"bazaar.cancel_listing",
|
||||
{ "listingId": lid },
|
||||
func(_t: String, _p: Variant):
|
||||
_my_listings = _my_listings.filter(func(l: Dictionary) -> bool:
|
||||
return str(l.get("id","")) != lid)
|
||||
_render_tab()
|
||||
# Reconnect original confirmed handler.
|
||||
if not confirm_dialog.confirmed.is_connected(_on_purchase_confirmed):
|
||||
confirm_dialog.confirmed.connect(_on_purchase_confirmed),
|
||||
func(code: String, _msg: String):
|
||||
_show_result("Cancel Failed", "Error: %s" % code)
|
||||
if not confirm_dialog.confirmed.is_connected(_on_purchase_confirmed):
|
||||
confirm_dialog.confirmed.connect(_on_purchase_confirmed)
|
||||
)
|
||||
|
||||
# ── My Shop: view another player's storefront ──────────────────────────────────
|
||||
|
||||
func _on_player_shop_search() -> void:
|
||||
var seller_id := player_shop_input.text.strip_edges()
|
||||
if seller_id.is_empty():
|
||||
return
|
||||
loading_label.visible = true
|
||||
_clear_list()
|
||||
Network.request(
|
||||
"bazaar.get_player_shop",
|
||||
{ "sellerAccountId": seller_id, "page": 0, "pageSize": 50 },
|
||||
_on_player_shop_ok,
|
||||
_on_player_shop_err
|
||||
)
|
||||
|
||||
|
||||
func _on_player_shop_ok(_t: String, p: Variant) -> void:
|
||||
var d := p as Dictionary
|
||||
var name_ := str(d.get("sellerDisplayName", "Player"))
|
||||
var listings: Array = d.get("listings", [])
|
||||
loading_label.visible = false
|
||||
_clear_list()
|
||||
empty_label.visible = listings.is_empty()
|
||||
for item: Dictionary in listings:
|
||||
var row := STORE_ITEM_ROW.instantiate()
|
||||
item_list.add_child(row)
|
||||
row.setup_listing(item, FALLBACK_ART)
|
||||
row.buy_pressed.connect(_on_buy_pressed)
|
||||
# Show whose shop this is.
|
||||
_show_result("%s's Shop" % name_, "%d active listing(s)" % listings.size())
|
||||
|
||||
|
||||
func _on_player_shop_err(code: String, _msg: String) -> void:
|
||||
loading_label.visible = false
|
||||
_show_result("Shop Not Found", "Error: %s" % code)
|
||||
|
||||
# ── Navigation ─────────────────────────────────────────────────────────────────
|
||||
|
||||
func _on_back() -> void:
|
||||
|
||||
Reference in New Issue
Block a user