Starting to work on codeProblems goal type. Rearranged script import for publishing notes earlier. Fallback for Math.log10.

This commit is contained in:
Nick Winter 2014-10-20 09:41:28 -07:00
parent 08d9e39764
commit 1219710cbb
4 changed files with 25 additions and 3 deletions

View file

@ -44,6 +44,7 @@ module.exports = class GoalManager extends CocoClass
'world:thang-touched-goal': 'onThangTouchedGoal'
'world:thang-left-map': 'onThangLeftMap'
'world:thang-collected-item': 'onThangCollectedItem'
'world:user-code-problem': 'onUserCodeProblem'
'world:ended': 'onWorldEnded'
onLevelRestarted: ->
@ -140,6 +141,8 @@ module.exports = class GoalManager extends CocoClass
@initGoalState(state, [goal.getToLocations?.who, goal.keepFromLocations?.who], 'arrived')
@initGoalState(state, [goal.leaveOffSides?.who, goal.keepFromLeavingOffSides?.who], 'left')
@initGoalState(state, [goal.collectThangs?.targets, goal.keepFromCollectingThangs?.targets], 'collected')
@initGoalState(state, [goal.linesOfCode?.who], 'lines') # TODO: find out how many lines there are
@initGoalState(state, [goal.codeProblems?.who], 'problems') # TODO: count initial problems, not just runtime
@goalStates[goal.id] = state
onThangDied: (e, frameNumber) ->
@ -187,6 +190,14 @@ module.exports = class GoalManager extends CocoClass
return unless thang.id in who or thang.team in who
@updateGoalState(goalID, itemID, 'collected', frameNumber)
onUserCodeProblem: (e, frameNumber) ->
for goal in @goals ? [] when goal.codeProblems
@checkCodeProblem goal.id, goal.codeProblems.who, e.thang, frameNumber
checkCodeProblem: (goalID, who, thang, frameNumber) ->
return unless thang.id in who or thang.team in who
@updateGoalState goal.id, thang.id, 'problems', frameNumber
wrapUpGoalStates: (finalFrame) ->
for goalID, state of @goalStates
if state.status is null
@ -247,7 +258,7 @@ module.exports = class GoalManager extends CocoClass
# saveThangs: by default we would want to save all the Thangs, which means that we would want none of them to be 'done'
numNeeded = _.size(stateThangs) - Math.max((goal.howMany ? 1), _.size stateThangs) + 1
numDone = _.filter(stateThangs).length
#console.log 'needed', numNeeded, 'done', numDone, 'of total', _.size(stateThangs), 'with how many', goal.howMany, 'and stateThangs', stateThangs
#console.log 'needed', numNeeded, 'done', numDone, 'of total', _.size(stateThangs), 'with how many', goal.howMany, 'and stateThangs', stateThangs, 'for', goalID, thangID, 'on frame', frameNumber
return unless numDone >= numNeeded
return if state.status and not success # already failed it; don't wipe keyframe
state.status = if success then 'success' else 'failure'
@ -278,6 +289,8 @@ module.exports = class GoalManager extends CocoClass
keepFromLeavingOffSides: 0
collectThangs: 1
keepFromCollectingThangs: 0
linesOfCode: 0
codeProblems: 0
updateCodeGoalStates: ->
# TODO

View file

@ -201,9 +201,9 @@ module.exports = class World
@levelID = level.slug
@levelComponents = level.levelComponents
@thangTypes = level.thangTypes
@loadScriptsFromLevel level
@loadSystemsFromLevel level
@loadThangsFromLevel level, willSimulate
@loadScriptsFromLevel level
system.start @thangs for system in @systems
loadSystemsFromLevel: (level) ->

View file

@ -30,3 +30,12 @@ module.exports =
thang: {type: 'object'}
'world:custom-script-trigger': {type: 'object'}
'world:user-code-problem': c.object {required: ['thang', 'problem']},
thang: {type: 'object'}
problem: c.object {required: ['message', 'level', 'type']}, #, 'userInfo', 'error']},
userInfo: {type: 'object'}
message: {type: 'string'}
level: {type: 'string', enum: ['info', 'warning', 'error']}
type: {type: 'string'}
error: {type: 'object'}

View file

@ -146,7 +146,7 @@ module.exports = class HeroVictoryModal extends ModalView
tickNumberAnimation: =>
# TODO: make sure the animation pulses happen when the numbers go up and sounds play (up to a max speed)
return @endAnimateNumbers() unless panel = @numericalItemPanels[0]
duration = Math.log10(panel.number + 1) * 1000
duration = Math.log(panel.number + 1) / Math.LN10 * 1000 # Math.log10 is ES6
ratio = @getEaseRatio (new Date() - @numberAnimationStart), duration
if panel.unit is 'xp'
totalXP = @totalXPAnimated + Math.floor(ratio * panel.number)