- manage_pile = (pile) ->
- pile.$blank = new_blank_card pile.x, pile.y
- count = 0
- top = null
- if state.piles[pile.key]?.length
- count = state.piles[pile.key].length
- top = state.piles[pile.key][0]
- $caption = $ $ "<div class=\"pile_caption\"><div>#{pile.name}:</div><div class=\"n_cards\">#{n_cards count}</div></div>"
- pile.$caption = $caption
- if top?
- top.x = pile.x
- top.y = pile.y
- instantiate_card top
- view = top.view
+ # where should the caption be?
+ if ps[pile.key]?
+ unless ps[pile.key].top_card.view?
+ ps[pile.key].top_card.x = pile.x
+ ps[pile.key].top_card.y = pile.y
+ instantiate_card ps[pile.key].top_card
+ caption_dest = ps[pile.key].top_card.view
+ else
+ caption_dest = pile.$blank
+ if caption_dest isnt pile.caption_loc
+ pile.$caption.detach()
+ caption_dest.append pile.$caption
+ pile.caption_loc = caption_dest
+
+ # update caption to show correct number of cards in the pile
+ card_count = 0
+ card_count = ps[pile.key].total if ps[pile.key]?
+ pile.$caption.children('.n_cards').html n_cards card_count
+
+possible_cards = {}
+
+valumenous = (val) -> return true unless val is '' or val is ' '
+
+init_possible_cards = ->
+ for card in window.cs_cards
+ text = "#{card.cardname} (#{card.faction})"
+ if valumenous card.attack or valumenous card.defense
+ text += " #{card.attack}/#{card.defense}"
+ text += "<br>#{card.type}"
+ if valumenous card.subtype
+ text += " • #{card.subtype}"
+ text += "<br>cost: #{card.cost} thresh: #{card.threshold}<br>"
+ text += card.rules
+
+ summary = text.replace(/<br>/g, "\n")
+
+ possible_cards[card.id] = {id: card.id, text: text, summary: summary}
+
+
+init_card_designer = ->
+ show_message 'init_card_designer'
+ cards_in_deck = {}
+ container = $ '#deck_designer'
+ init_possible_cards()
+ ul = $ $ '<ul/>'
+ for key, card of possible_cards
+ view = $ $ "<li>#{card.summary}</li>"
+ view.data 'id', card.id
+ view.bind 'click', ->
+ $el = $ this
+ id = $el.data 'id'
+ if cards_in_deck[id]?
+ delete cards_in_deck[id]
+ value = false