codecombat/app/views/play/level/HintsState.coffee
Scott Erickson 86fc4a3846 Hints v1
Add per-level tips and tricks, available during gameplay to help unstick players.

Closes #3736
2016-06-15 16:12:41 -07:00

30 lines
902 B
CoffeeScript

module.exports = class HintsState extends Backbone.Model
initialize: (attributes, options) ->
{ @level, @session } = options
@listenTo(@level, 'change:documentation', @update)
@update()
getHint: (index) ->
@get('hints')?[index]
update: ->
hints = switch me.getHintsGroup()
when 'hints' then @level.get('documentation')?.hints or []
when 'hintsB' then @level.get('documentation')?.hintsB or []
else []
haveIntro = false
haveOverview = false
for article in @level.get('documentation')?.specificArticles ? []
if not haveIntro and article.name is 'Intro'
hints.unshift(article)
haveIntro = true
if not haveOverview and article.name is 'Overview'
hints.push(article)
haveOverview = true
break if haveIntro and haveOverview
total = _.size(hints)
@set({
hints: hints
total
})