mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-22 10:55:19 -04:00
Goal states are now tracked in level sessions (state.goalStates)
This commit is contained in:
parent
9f0add22a5
commit
3bfd341363
3 changed files with 30 additions and 0 deletions
app
|
@ -1,6 +1,7 @@
|
|||
Bus = require './Bus'
|
||||
{me} = require 'lib/auth'
|
||||
LevelSession = require 'models/LevelSession'
|
||||
utils = require 'lib/utils'
|
||||
|
||||
module.exports = class LevelBus extends Bus
|
||||
|
||||
|
@ -22,6 +23,7 @@ module.exports = class LevelBus extends Bus
|
|||
'tome:spell-changed': 'onSpellChanged'
|
||||
'tome:spell-created': 'onSpellCreated'
|
||||
'application:idle-changed': 'onIdleChanged'
|
||||
'goal-manager:new-goal-states': 'onNewGoalStates'
|
||||
|
||||
constructor: ->
|
||||
super(arguments...)
|
||||
|
@ -192,6 +194,14 @@ module.exports = class LevelBus extends Bus
|
|||
@changedSessionProperties.state = true
|
||||
@saveSession()
|
||||
|
||||
onNewGoalStates: ({goalStates})->
|
||||
state = @session.get 'state'
|
||||
unless utils.kindaEqual state.goalStates, goalStates # Only save when goals really change
|
||||
state.goalStates = goalStates
|
||||
@session.set 'state', state
|
||||
@changedSessionProperties.state = true
|
||||
@saveSession()
|
||||
|
||||
onPlayerJoined: (snapshot) =>
|
||||
super(arguments...)
|
||||
return unless @onPoint()
|
||||
|
|
|
@ -118,3 +118,15 @@ module.exports.grayscale = (imageData) ->
|
|||
v = 0.2126*r + 0.7152*g + 0.0722*b
|
||||
d[i] = d[i+1] = d[i+2] = v
|
||||
imageData
|
||||
|
||||
# Deep compares l with r, with the exception that undefined values are considered equal to missing values
|
||||
# Very practical for comparing Mongoose documents where undefined is not allowed, instead fields get deleted
|
||||
module.exports.kindaEqual = compare = (l, r) ->
|
||||
if _.isObject(l) and _.isObject(r)
|
||||
for key in _.union Object.keys(l), Object.keys(r)
|
||||
return false unless compare l[key], r[key]
|
||||
return true
|
||||
else if l is r
|
||||
return true
|
||||
else
|
||||
return false
|
||||
|
|
|
@ -97,6 +97,14 @@ _.extend LevelSessionSchema.properties,
|
|||
type: 'object'
|
||||
source:
|
||||
type: 'string'
|
||||
goalStates:
|
||||
type: 'object'
|
||||
description: 'Maps Goal ID on a goal state object'
|
||||
additionalProperties:
|
||||
title: 'Goal State'
|
||||
type: 'object'
|
||||
properties:
|
||||
status: enum: ['failure', 'incomplete', 'success']
|
||||
|
||||
code:
|
||||
type: 'object'
|
||||
|
|
Loading…
Reference in a new issue