mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-12-01 03:16:56 -05:00
38 lines
1.1 KiB
CoffeeScript
38 lines
1.1 KiB
CoffeeScript
View = require 'views/kinds/CocoView'
|
|
template = require 'templates/play/level/gold'
|
|
teamTemplate = require 'templates/play/level/team_gold'
|
|
|
|
module.exports = class GoldView extends View
|
|
id: "gold-view"
|
|
template: template
|
|
|
|
subscriptions:
|
|
'surface:gold-changed': 'onGoldChanged'
|
|
'level-set-letterbox': 'onSetLetterbox'
|
|
|
|
constructor: (options) ->
|
|
super options
|
|
@teamGold = {}
|
|
@teamGoldEarned = {}
|
|
|
|
onGoldChanged: (e) ->
|
|
@$el.show()
|
|
return if @teamGold[e.team] is e.gold and @teamGoldEarned[e.team] is e.goldEarned
|
|
@teamGold[e.team] = e.gold
|
|
@teamGoldEarned[e.team] = e.goldEarned
|
|
goldEl = @$el.find('.gold-amount.team-' + e.team)
|
|
unless goldEl.length
|
|
teamEl = teamTemplate team: e.team
|
|
@$el.append(teamEl)
|
|
goldEl = $('.gold-amount.team-' + e.team, teamEl)
|
|
text = '' + e.gold
|
|
if e.goldEarned and e.goldEarned > e.gold
|
|
text += " (#{e.goldEarned})"
|
|
goldEl.text text
|
|
@updateTitle()
|
|
|
|
updateTitle: ->
|
|
@$el.attr 'title', ("Team '#{team}' has #{gold} now of #{@teamGoldEarned[team]} gold earned." for team, gold of @teamGold).join ' '
|
|
|
|
onSetLetterbox: (e) ->
|
|
@$el.toggle not e.on
|