mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-30 10:56:53 -05:00
Remove items from course victory dialog
This commit is contained in:
parent
16c9f10043
commit
f8a67ace0e
2 changed files with 10 additions and 123 deletions
|
@ -1,15 +1,9 @@
|
|||
ModalView = require 'views/core/ModalView'
|
||||
template = require 'templates/play/level/modal/course-victory-modal'
|
||||
Achievements = require 'collections/Achievements'
|
||||
Level = require 'models/Level'
|
||||
Course = require 'models/Course'
|
||||
ThangType = require 'models/ThangType'
|
||||
ThangTypes = require 'collections/ThangTypes'
|
||||
LevelSessions = require 'collections/LevelSessions'
|
||||
EarnedAchievement = require 'models/EarnedAchievement'
|
||||
LocalMongo = require 'lib/LocalMongo'
|
||||
ProgressView = require './ProgressView'
|
||||
NewItemView = require './NewItemView'
|
||||
Classroom = require 'models/Classroom'
|
||||
utils = require 'core/utils'
|
||||
|
||||
|
@ -18,7 +12,6 @@ module.exports = class CourseVictoryModal extends ModalView
|
|||
template: template
|
||||
closesOnClickOutside: false
|
||||
|
||||
|
||||
initialize: (options) ->
|
||||
@courseID = options.courseID
|
||||
@courseInstanceID = options.courseInstanceID
|
||||
|
@ -26,20 +19,10 @@ module.exports = class CourseVictoryModal extends ModalView
|
|||
|
||||
@session = options.session
|
||||
@level = options.level
|
||||
@newItems = new ThangTypes()
|
||||
@newHeroes = new ThangTypes()
|
||||
|
||||
if @courseInstanceID
|
||||
@classroom = new Classroom()
|
||||
@supermodel.trackRequest(@classroom.fetchForCourseInstance(@courseInstanceID))
|
||||
@achievements = options.achievements
|
||||
if not @achievements
|
||||
@achievements = new Achievements()
|
||||
@achievements.fetchRelatedToLevel(@session.get('level').original)
|
||||
@achievements = @supermodel.loadCollection(@achievements, 'achievements').model
|
||||
@listenToOnce @achievements, 'sync', @onAchievementsLoaded
|
||||
else
|
||||
@onAchievementsLoaded()
|
||||
|
||||
@playSound 'victory'
|
||||
@nextLevel = new Level()
|
||||
|
@ -68,69 +51,10 @@ module.exports = class CourseVictoryModal extends ModalView
|
|||
return
|
||||
super(arguments...)
|
||||
|
||||
|
||||
onAchievementsLoaded: ->
|
||||
@achievements.models = _.filter @achievements.models, (m) -> not m.get('query')?.ladderAchievementDifficulty # Don't show higher AI difficulty achievements
|
||||
itemOriginals = []
|
||||
heroOriginals = []
|
||||
achievementIDs = []
|
||||
for achievement in @achievements.models
|
||||
rewards = achievement.get('rewards') or {}
|
||||
heroOriginals.push rewards.heroes or []
|
||||
itemOriginals.push rewards.items or []
|
||||
achievement.completed = LocalMongo.matchesQuery(@session.attributes, achievement.get('query'))
|
||||
achievementIDs.push(achievement.id) if achievement.completed
|
||||
|
||||
itemOriginals = _.uniq _.flatten itemOriginals
|
||||
heroOriginals = _.uniq _.flatten heroOriginals
|
||||
#project = ['original', 'rasterIcon', 'name', 'soundTriggers', 'i18n'] # This is what we need, but the PlayHeroesModal needs more, and so we load more to fill up the supermodel.
|
||||
project = ['original', 'rasterIcon', 'name', 'slug', 'soundTriggers', 'featureImages', 'gems', 'heroClass', 'description', 'components', 'extendedName', 'unlockLevelName', 'i18n']
|
||||
for [newThangTypeCollection, originals] in [[@newItems, itemOriginals], [@newHeroes, heroOriginals]]
|
||||
for original in originals
|
||||
thang= new ThangType()
|
||||
thang.url = "/db/thang.type/#{original}/version"
|
||||
thang.project = project
|
||||
@supermodel.loadModel(thang)
|
||||
newThangTypeCollection.add(thang)
|
||||
|
||||
@newEarnedAchievements = []
|
||||
for achievement in @achievements.models
|
||||
continue unless achievement.completed
|
||||
ea = new EarnedAchievement({
|
||||
collection: achievement.get('collection')
|
||||
triggeredBy: @session.id
|
||||
achievement: achievement.id
|
||||
})
|
||||
if me.isSessionless()
|
||||
@newEarnedAchievements.push ea
|
||||
else
|
||||
ea.save()
|
||||
# Can't just add models to supermodel because each ea has the same url
|
||||
ea.sr = @supermodel.addSomethingResource(ea.cid)
|
||||
@newEarnedAchievements.push ea
|
||||
@listenToOnce ea, 'sync', (model) ->
|
||||
model.sr.markLoaded()
|
||||
if _.all((ea.id for ea in @newEarnedAchievements))
|
||||
unless me.loading
|
||||
@supermodel.loadModel(me, {cache: false})
|
||||
@newEarnedAchievementsResource.markLoaded()
|
||||
|
||||
unless me.isSessionless()
|
||||
# have to use a something resource because addModelResource doesn't handle models being upserted/fetched via POST like we're doing here
|
||||
@newEarnedAchievementsResource = @supermodel.addSomethingResource('earned achievements') if @newEarnedAchievements.length
|
||||
|
||||
|
||||
onLoaded: ->
|
||||
super()
|
||||
@views = []
|
||||
|
||||
# TODO: Add main victory view
|
||||
# TODO: Add level up view
|
||||
# TODO: Add new hero view?
|
||||
|
||||
for newItem in @newItems.models
|
||||
@views.push(new NewItemView({item: newItem}))
|
||||
|
||||
@levelSessions?.remove(@session)
|
||||
@levelSessions?.add(@session)
|
||||
progressView = new ProgressView({
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
Course = require 'models/Course'
|
||||
Level = require 'models/Level'
|
||||
LevelSession = require 'models/LevelSession'
|
||||
Achievements = require 'collections/Achievements'
|
||||
CourseVictoryModal = require 'views/play/level/modal/CourseVictoryModal'
|
||||
NewItemView = require 'views/play/level/modal/NewItemView'
|
||||
ProgressView = require 'views/play/level/modal/ProgressView'
|
||||
factories = require 'test/app/factories'
|
||||
|
||||
|
@ -21,7 +19,6 @@ describe 'CourseVictoryModal', ->
|
|||
course: factories.makeCourse()
|
||||
level: level
|
||||
session: factories.makeLevelSession({ state: { complete: true } }, { level })
|
||||
achievements: new Achievements([factories.makeLevelCompleteAchievement({}, {level: level})])
|
||||
nextLevel: factories.makeLevel()
|
||||
courseInstanceID: courseInstance.id
|
||||
courseID: course.id
|
||||
|
@ -31,11 +28,6 @@ describe 'CourseVictoryModal', ->
|
|||
|
||||
handleRequests = (modal) ->
|
||||
requests = jasmine.Ajax.requests.all()
|
||||
thangRequest = _.find(requests, (r) -> _.string.startsWith(r.url, '/db/thang.type'))
|
||||
thangRequest?.respondWith({status: 200, responseText: factories.makeThangType().stringify()})
|
||||
modal.newEarnedAchievements[0].fakeRequests[0].respondWith({
|
||||
status: 200, responseText: factories.makeEarnedAchievement().stringify()
|
||||
})
|
||||
modal.levelSessions.fakeRequests[0].respondWith({ status: 200, responseText: '[]' })
|
||||
modal.classroom.fakeRequests[0].respondWith({
|
||||
status: 200, responseText: factories.makeClassroom().stringify()
|
||||
|
@ -106,32 +98,3 @@ describe 'CourseVictoryModal', ->
|
|||
expect(application.router.navigate).toHaveBeenCalled()
|
||||
|
||||
it '(demo)', -> jasmine.demoModal(modal)
|
||||
|
||||
|
||||
describe 'given a course level with a new item', ->
|
||||
modal = null
|
||||
|
||||
beforeEach (done) ->
|
||||
options = makeViewOptions()
|
||||
|
||||
# insert new item into achievement properties
|
||||
achievement = options.achievements.first()
|
||||
rewards = _.cloneDeep(achievement.get('rewards'))
|
||||
rewards.items = ["53e4108204c00d4607a89f78"]
|
||||
achievement.set('rewards', rewards)
|
||||
|
||||
modal = new CourseVictoryModal(options)
|
||||
handleRequests(modal)
|
||||
nextLevelRequest.respondWith({status: 200, responseText: factories.makeLevel().stringify()})
|
||||
_.defer done
|
||||
|
||||
it 'includes a NewItemView when the level rewards a new item', ->
|
||||
expect(_.size(modal.views)).toBe(2)
|
||||
expect(modal.views[0] instanceof NewItemView).toBe(true)
|
||||
|
||||
it 'continues to the ProgressView when you click the continue button', ->
|
||||
expect(modal.currentView instanceof NewItemView).toBe(true)
|
||||
modal.$el.find('#continue-btn').click()
|
||||
expect(modal.currentView instanceof ProgressView).toBe(true)
|
||||
|
||||
it '(demo)', -> jasmine.demoModal(modal)
|
||||
|
|
Loading…
Reference in a new issue