mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 23:58:02 -05:00
Allow using hero levels as course levels. Refactor current course tracking to use GET parameters.
This commit is contained in:
parent
8b00c38350
commit
f7f7cd683e
6 changed files with 30 additions and 27 deletions
|
@ -34,6 +34,7 @@ module.exports = class LevelLoader extends CocoClass
|
|||
@sessionless = options.sessionless
|
||||
@spectateMode = options.spectateMode ? false
|
||||
@observing = options.observing
|
||||
@isCourse = options.courseID?
|
||||
|
||||
@worldNecessities = []
|
||||
@listenTo @supermodel, 'resource-loaded', @onWorldNecessityLoaded
|
||||
|
@ -56,6 +57,14 @@ module.exports = class LevelLoader extends CocoClass
|
|||
@listenToOnce @level, 'sync', @onLevelLoaded
|
||||
|
||||
onLevelLoaded: ->
|
||||
console.log 'is course?', @isCourse, 'type', @level.get('type', true), @level.get('type', true) not in ['course', 'course-ladder']
|
||||
if @isCourse and @level.get('type', true) not in ['course', 'course-ladder']
|
||||
# Because we now use original hero levels for both hero and course levels, we fake being a course level in this context.
|
||||
console.log 'doin it'
|
||||
originalGet = @level.get
|
||||
@level.get = ->
|
||||
return 'course' if arguments[0] is 'type'
|
||||
originalGet.apply @, arguments
|
||||
@loadSession() unless @sessionless
|
||||
@populateLevel()
|
||||
|
||||
|
|
|
@ -312,11 +312,11 @@ _.extend UserSchema.properties,
|
|||
|
||||
siteref: { type: 'string' }
|
||||
referrer: { type: 'string' }
|
||||
chinaVersion: { type: 'boolean' } # Old
|
||||
chinaVersion: { type: 'boolean' } # Old, can be removed after we make sure it's deleted from all users
|
||||
country: { type: 'string', enum: ['brazil', 'china'] } # New, supports multiple countries for different versions--only set for specific countries where we have premium servers right now
|
||||
|
||||
clans: c.array {}, c.objectId()
|
||||
currentCourse: c.object {}, {
|
||||
currentCourse: c.object {}, { # Old, can be removed after we deploy and delete it from all users
|
||||
courseID: c.objectId({})
|
||||
courseInstanceID: c.objectId({})
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ module.exports = class CourseDetailsView extends RootView
|
|||
# console.log 'onCampaignSync'
|
||||
if @courseInstanceID
|
||||
@loadCourseInstance(@courseInstanceID)
|
||||
else if !me.isAnonymous()
|
||||
else unless me.isAnonymous()
|
||||
@courseInstances = new CocoCollection([], { url: "/db/user/#{me.id}/course_instances", model: CourseInstance})
|
||||
@listenToOnce @courseInstances, 'sync', @onCourseInstancesSync
|
||||
@supermodel.loadCollection(@courseInstances, 'course_instances')
|
||||
|
@ -129,13 +129,6 @@ module.exports = class CourseDetailsView extends RootView
|
|||
@supermodel.loadCollection @levelSessions, 'level_sessions', cache: false
|
||||
@members = new CocoCollection([], { url: "/db/course_instance/#{@courseInstance.id}/members", model: User, comparator: 'nameLower' })
|
||||
@listenToOnce @members, 'sync', @onMembersSync
|
||||
me.set({
|
||||
currentCourse: {
|
||||
courseInstanceID: @courseInstance.id,
|
||||
courseID: @course.id
|
||||
}
|
||||
})
|
||||
me.patch()
|
||||
@supermodel.loadCollection @members, 'members', cache: false
|
||||
@owner = new User({_id: @courseInstance.get('ownerID')})
|
||||
@supermodel.loadModel @owner, 'user'
|
||||
|
@ -227,11 +220,14 @@ module.exports = class CourseDetailsView extends RootView
|
|||
onClickPlayLevel: (e) ->
|
||||
levelSlug = $(e.target).data('level-slug')
|
||||
Backbone.Mediator.publish 'router:navigate', {
|
||||
route: "/play/level/#{levelSlug}"
|
||||
route: @getLevelURL levelSlug
|
||||
viewClass: 'views/play/level/PlayLevelView'
|
||||
viewArgs: [{courseID: @courseID, courseInstanceID: @courseInstanceID}, levelSlug]
|
||||
}
|
||||
|
||||
getLevelURL: (levelSlug) ->
|
||||
"/play/level/#{levelSlug}?course=#{@courseID}&course-instance=#{@courseInstanceID}"
|
||||
|
||||
onClickSaveSettings: (e) ->
|
||||
return unless @courseInstance
|
||||
if name = $('.settings-name-input').val()
|
||||
|
@ -256,9 +252,9 @@ module.exports = class CourseDetailsView extends RootView
|
|||
levelSlug = $(e.currentTarget).data('level-slug')
|
||||
userID = $(e.currentTarget).data('user-id')
|
||||
return unless levelID and levelSlug and userID
|
||||
route = "/play/level/#{levelSlug}"
|
||||
route = @getLevelURL levelSlug
|
||||
if @userLevelSessionMap[userID]?[levelID]
|
||||
route += "?session=#{@userLevelSessionMap[userID][levelID].id}&observing=true"
|
||||
route += "&session=#{@userLevelSessionMap[userID][levelID].id}&observing=true"
|
||||
Backbone.Mediator.publish 'router:navigate', {
|
||||
route: route
|
||||
viewClass: 'views/play/level/PlayLevelView'
|
||||
|
|
|
@ -28,9 +28,8 @@ module.exports = class ControlBarView extends CocoView
|
|||
'click #control-bar-sign-up-button': 'onClickSignupButton'
|
||||
|
||||
constructor: (options) ->
|
||||
currentCourse = me.get('currentCourse') or {}
|
||||
@courseID = options.courseID or currentCourse.courseID
|
||||
@courseInstanceID = options.courseInstanceID or currentCourse.courseInstanceID
|
||||
@courseID = options.courseID
|
||||
@courseInstanceID = options.courseInstanceID
|
||||
|
||||
@worldName = options.worldName
|
||||
@session = options.session
|
||||
|
|
|
@ -94,8 +94,8 @@ module.exports = class PlayLevelView extends RootView
|
|||
console.profile?() if PROFILE_ME
|
||||
super options
|
||||
|
||||
@courseID = options.courseID
|
||||
@courseInstanceID = options.courseInstanceID
|
||||
@courseID = options.courseID or @getQueryVariable 'course'
|
||||
@courseInstanceID = options.courseInstanceID or @getQueryVariable 'course-instance'
|
||||
|
||||
@isEditorPreview = @getQueryVariable 'dev'
|
||||
@sessionID = @getQueryVariable 'session'
|
||||
|
@ -133,7 +133,7 @@ module.exports = class PlayLevelView extends RootView
|
|||
load: ->
|
||||
@loadStartTime = new Date()
|
||||
@god = new God debugWorker: true
|
||||
@levelLoader = new LevelLoader supermodel: @supermodel, levelID: @levelID, sessionID: @sessionID, opponentSessionID: @opponentSessionID, team: @getQueryVariable('team'), observing: @observing
|
||||
@levelLoader = new LevelLoader supermodel: @supermodel, levelID: @levelID, sessionID: @sessionID, opponentSessionID: @opponentSessionID, team: @getQueryVariable('team'), observing: @observing, courseID: @courseID
|
||||
@listenToOnce @levelLoader, 'world-necessities-loaded', @onWorldNecessitiesLoaded
|
||||
|
||||
trackLevelLoadEnd: ->
|
||||
|
|
|
@ -406,12 +406,14 @@ module.exports = class HeroVictoryModal extends ModalView
|
|||
# need to do something more complicated to load its slug
|
||||
console.log 'have @nextLevel', @nextLevel, 'from nextLevel', nextLevel
|
||||
link = "/play/level/#{@nextLevel.get('slug')}"
|
||||
if @courseID
|
||||
link += "?course=#{@courseID}"
|
||||
link += "&course-instance=#{@courseInstanceID}" if @courseInstanceID
|
||||
else if @level.get('type', true) is 'course'
|
||||
link = "/courses"
|
||||
if @courseID
|
||||
link += "/#{@courseID}"
|
||||
if @courseInstanceID
|
||||
link += "/#{@courseInstanceID}"
|
||||
link += "/#{@courseInstanceID}" if @courseInstanceID
|
||||
else
|
||||
link = '/play'
|
||||
nextCampaign = @getNextLevelCampaign()
|
||||
|
@ -428,10 +430,8 @@ module.exports = class HeroVictoryModal extends ModalView
|
|||
_.merge options, extraOptions if extraOptions
|
||||
if @level.get('type', true) is 'course' and @nextLevel and not options.returnToCourse
|
||||
viewClass = require 'views/play/level/PlayLevelView'
|
||||
if @courseID
|
||||
options.courseID = @courseID
|
||||
if @courseInstanceID
|
||||
options.courseInstanceID = @courseInstanceID
|
||||
options.courseID = @courseID
|
||||
options.courseInstanceID = @courseInstanceID
|
||||
viewArgs = [options, @nextLevel.get('slug')]
|
||||
else if @level.get('type', true) is 'course'
|
||||
# TODO: shouldn't set viewClass and route in different places
|
||||
|
@ -440,8 +440,7 @@ module.exports = class HeroVictoryModal extends ModalView
|
|||
if @courseID
|
||||
viewClass = require 'views/courses/CourseDetailsView'
|
||||
viewArgs.push @courseID
|
||||
if @courseInstanceID
|
||||
viewArgs.push @courseInstanceID
|
||||
viewArgs.push @courseInstanceID if @courseInstanceID
|
||||
else
|
||||
viewClass = require 'views/play/CampaignView'
|
||||
viewArgs = [options, @getNextLevelCampaign()]
|
||||
|
|
Loading…
Reference in a new issue