mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-26 05:53:39 -04:00
Changed how goal states are stored in the level session. Once a goal is succeeded, it can't be undone.
This commit is contained in:
parent
4e931ea031
commit
a123fb4b08
1 changed files with 17 additions and 6 deletions
|
@ -210,12 +210,23 @@ module.exports = class LevelBus extends Bus
|
|||
@changedSessionProperties.state = true
|
||||
@reallySaveSession() # Make sure it saves right away; don't debounce it.
|
||||
|
||||
onNewGoalStates: ({goalStates})->
|
||||
state = @session.get 'state'
|
||||
unless utils.kindaEqual state.goalStates, goalStates # Only save when goals really change
|
||||
# TODO: this log doesn't capture when null-status goals are being set during world streaming. Where can they be coming from?
|
||||
return console.error("Somehow trying to save null goal states!", goalStates) if _.find(goalStates, (gs) -> not gs.status)
|
||||
state.goalStates = goalStates
|
||||
onNewGoalStates: ({goalStates}) ->
|
||||
# TODO: this log doesn't capture when null-status goals are being set during world streaming. Where can they be coming from?
|
||||
return console.error("Somehow trying to save null goal states!", newGoalStates) if _.find(newGoalStates, (gs) -> not gs.status)
|
||||
|
||||
newGoalStates = goalStates
|
||||
state = @session.get('state')
|
||||
oldGoalStates = state.goalStates or {}
|
||||
|
||||
changed = false
|
||||
for goalKey, goalState of newGoalStates
|
||||
continue if oldGoalStates[goalKey]?.status is 'success' and goalState.status isnt 'success' # don't undo success, this property is for keying off achievements
|
||||
continue if utils.kindaEqual state.goalStates?[goalKey], goalState # Only save when goals really change
|
||||
changed = true
|
||||
oldGoalStates[goalKey] = _.cloneDeep newGoalStates[goalKey]
|
||||
|
||||
if changed
|
||||
state.goalStates = oldGoalStates
|
||||
@session.set 'state', state
|
||||
@changedSessionProperties.state = true
|
||||
@saveSession()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue