Merge pull request #730 from Darredevil/master

Added setGoalState
This commit is contained in:
Nick Winter 2014-03-29 14:04:33 -07:00
commit e08265a725
3 changed files with 16 additions and 0 deletions

View file

@ -212,6 +212,16 @@ module.exports = class GoalManager extends CocoClass
else else
state[progressObjectName][thang] = false state[progressObjectName][thang] = false
setGoalState: (goalID, status) ->
state = @goalStates[goalID]
state.status = status
if overallStatus = @checkOverallStatus true
matchedGoals = (_.find(@goals, {id: goalID}) for goalID, goalState of @goalStates when goalState.status is overallStatus)
mostEagerGoal = _.min matchedGoals, 'worldEndsAfter'
victory = overallStatus is "success"
tentative = overallStatus is "success"
@world.endWorld victory, mostEagerGoal.worldEndsAfter, tentative if mostEagerGoal isnt Infinity
updateGoalState: (goalID, thangID, progressObjectName, frameNumber) -> updateGoalState: (goalID, thangID, progressObjectName, frameNumber) ->
# A thang has done something related to the goal! # A thang has done something related to the goal!
# Mark it down and update the goal state. # Mark it down and update the goal state.

View file

@ -39,6 +39,9 @@ module.exports = class Thang
event.thang = @ event.thang = @
@world.publishNote channel, event @world.publishNote channel, event
setGoalState: (goalID, status) ->
@world.setGoalState goalID, status
addComponents: (components...) -> addComponents: (components...) ->
# We don't need to keep the components around after attaching them, but we will keep their initial config for recreating Thangs # We don't need to keep the components around after attaching them, but we will keep their initial config for recreating Thangs
@components ?= [] @components ?= []

View file

@ -222,6 +222,9 @@ module.exports = class World
return unless @goalManager return unless @goalManager
@goalManager.submitWorldGenerationEvent(channel, event, @frames.length) @goalManager.submitWorldGenerationEvent(channel, event, @frames.length)
setGoalState: (goalID, status) ->
@goalManager.setGoalState(goalID, status)
endWorld: (victory=false, delay=3, tentative=false) -> endWorld: (victory=false, delay=3, tentative=false) ->
@totalFrames = Math.min(@totalFrames, @frames.length + Math.floor(delay / @dt)) - 1 # end a few seconds later @totalFrames = Math.min(@totalFrames, @frames.length + Math.floor(delay / @dt)) - 1 # end a few seconds later
@victory = victory # TODO: should just make this signify the winning superteam @victory = victory # TODO: should just make this signify the winning superteam