+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
+ else
+ value = true
+ cards_in_deck[id] = true
+ $el.toggleClass 'in_deck', value
+ ul.append view
+
+ container.append ul
+
+ submit = $ $ "<div style=\"border: 1px solid black; margin: 0 auto 10px 10px; width: 40px; text-align: center\">Done</div>"
+ submit.bind 'click', ->
+ $('#deck_designer').remove()
+ show_message cards_in_deck
+ cards = []
+ for key, value of cards_in_deck
+ card = {
+ text: possible_cards[key].text
+ owner: state.agent
+ pile: "#{state.agent}_draw"
+ x: 0
+ y: 0
+ flipped: true
+ }
+ cards.push card
+ cards.push $.extend {}, card # clone
+ cards.push $.extend {}, card # clone
+ cards.push $.extend {}, card # clone
+
+ # asign z-index in random order
+ cards.shuffle()
+ for card in cards
+ card.z = next_card_z()
+ show_message cards
+
+ # let server assign card numbers
+ tell_server ['new_cards', state.agent, cards]
+
+
+ container.append submit
+
+new_game_slug = ->
+ charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
+ ret = ''
+ while ret.length < 10
+ ret += charset[Math.floor(Math.random() * charset.length)]
+ return ret