diff --git a/app/lib/world/GoalManager.coffee b/app/lib/world/GoalManager.coffee index 8f629989e..a3d443848 100644 --- a/app/lib/world/GoalManager.coffee +++ b/app/lib/world/GoalManager.coffee @@ -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 diff --git a/app/lib/world/world.coffee b/app/lib/world/world.coffee index 34f24153a..7b967a86f 100644 --- a/app/lib/world/world.coffee +++ b/app/lib/world/world.coffee @@ -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) -> diff --git a/app/schemas/subscriptions/world.coffee b/app/schemas/subscriptions/world.coffee index 2e38a32b2..31076e148 100644 --- a/app/schemas/subscriptions/world.coffee +++ b/app/schemas/subscriptions/world.coffee @@ -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'} diff --git a/app/views/play/level/modal/HeroVictoryModal.coffee b/app/views/play/level/modal/HeroVictoryModal.coffee index 2158eba75..87097eba6 100644 --- a/app/views/play/level/modal/HeroVictoryModal.coffee +++ b/app/views/play/level/modal/HeroVictoryModal.coffee @@ -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)