mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-24 16:17:57 -05:00
870ae9a8a1
Use selected hero in Course mode play Show selected hero on Courses (in progress) Add hero select modal Use short names, only show warriors Use box-shadow instead of borders Add tests for HeroSelectModal Refactor modal opening test Address code review feedback
42 lines
1.3 KiB
CoffeeScript
42 lines
1.3 KiB
CoffeeScript
ModalView = require 'views/core/ModalView'
|
|
template = require 'templates/courses/hero-select-modal'
|
|
Classroom = require 'models/Classroom'
|
|
ThangTypes = require 'collections/ThangTypes'
|
|
State = require 'models/State'
|
|
ThangType = require 'models/ThangType'
|
|
User = require 'models/User'
|
|
|
|
module.exports = class HeroSelectModal extends ModalView
|
|
id: 'hero-select-modal'
|
|
template: template
|
|
|
|
events:
|
|
'click .select-hero-btn': 'onClickSelectHeroButton'
|
|
'click .hero-option': 'onClickHeroOption'
|
|
|
|
initialize: ({ currentHeroID }) ->
|
|
@debouncedRender = _.debounce @render, 0
|
|
|
|
@state = new State({
|
|
currentHeroID
|
|
selectedHeroID: currentHeroID
|
|
})
|
|
|
|
@heroes = new ThangTypes({}, { project: ['original', 'name', 'heroClass'] })
|
|
@supermodel.trackRequest @heroes.fetchHeroes()
|
|
|
|
@listenTo @state, 'all', -> @debouncedRender()
|
|
@listenTo @heroes, 'all', -> @debouncedRender()
|
|
|
|
onClickHeroOption: (e) ->
|
|
heroID = $(e.currentTarget).data('hero-id')
|
|
@state.set selectedHeroID: heroID
|
|
hero = @heroes.get(heroID)
|
|
me.set(heroConfig: {}) unless me.get('heroConfig')
|
|
heroConfig = _.assign me.get('heroConfig'), { thangType: hero.get('original') }
|
|
me.set({ heroConfig })
|
|
me.save().then =>
|
|
@trigger 'hero-select:success', hero
|
|
|
|
onClickSelectHeroButton: () ->
|
|
@hide()
|