From 0640f382ba52f412605685384fc5cf54ed915e6f Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Wed, 19 Nov 2014 13:23:55 -0800 Subject: [PATCH] Fixed coordinate hover cursors fighting flag cursors. Added suspect code check functionality for scripts to slap hands. --- app/lib/LevelOptions.coffee | 12 ++++++++++ app/lib/surface/CoordinateDisplay.coffee | 6 ++++- app/schemas/subscriptions/tome.coffee | 4 ++++ app/views/game-menu/InventoryModal.coffee | 2 +- app/views/play/level/tome/SpellView.coffee | 26 +++++++++++++--------- 5 files changed, 38 insertions(+), 12 deletions(-) diff --git a/app/lib/LevelOptions.coffee b/app/lib/LevelOptions.coffee index 4b82d8764..df0cfa2f6 100644 --- a/app/lib/LevelOptions.coffee +++ b/app/lib/LevelOptions.coffee @@ -10,6 +10,7 @@ module.exports = LevelOptions = hidesRealTimePlayback: true requiredGear: {feet: 'simple-boots'} restrictedGear: {feet: 'leather-boots'} + requiredCode: ['moveRight'] 'gems-in-the-deep': disableSpaces: true hidesSubmitUntilRun: true @@ -71,6 +72,7 @@ module.exports = LevelOptions = hidesRealTimePlayback: true requiredGear: {feet: 'simple-boots', 'right-hand': 'simple-sword', waist: 'leather-belt'} restrictedGear: {feet: 'leather-boots'} + requiredCode: ['Brak'] 'favorable-odds': disableSpaces: true hidesRunShortcut: true @@ -97,6 +99,7 @@ module.exports = LevelOptions = hidesRealTimePlayback: true requiredGear: {feet: 'simple-boots', 'programming-book': 'programmaticon-i'} restrictedGear: {feet: 'leather-boots'} + requiredCode: ['loop'] 'haunted-kithmaze': hidesRunShortcut: true hidesHUD: true @@ -105,6 +108,7 @@ module.exports = LevelOptions = hidesRealTimePlayback: true requiredGear: {feet: 'simple-boots', 'programming-book': 'programmaticon-i'} restrictedGear: {feet: 'leather-boots'} + requiredCode: ['loop'] 'descending-further': hidesHUD: true hidesSay: true @@ -140,6 +144,8 @@ module.exports = LevelOptions = hidesRealTimePlayback: true requiredGear: {feet: 'simple-boots', 'right-hand': 'simple-sword', 'programming-book': 'programmaticon-i', eyes: 'crude-glasses', torso: 'leather-tunic'} restrictedGear: {feet: 'leather-boots'} + requiredCode: ['findNearestEnemy'] + suspectCode: [{name: 'lone-find-nearest-enemy', pattern: /^[ ]*(self|this|@)?[:.]?findNearestEnemy()/m}] 'lowly-kithmen': hidesHUD: true hidesSay: true @@ -147,6 +153,8 @@ module.exports = LevelOptions = hidesRealTimePlayback: true requiredGear: {feet: 'simple-boots', 'right-hand': 'simple-sword', 'programming-book': 'programmaticon-i', eyes: 'crude-glasses', torso: 'leather-tunic'} restrictedGear: {feet: 'leather-boots'} + requiredCode: ['findNearestEnemy'] + suspectCode: [{name: 'lone-find-nearest-enemy', pattern: /^[ ]*(self|this|@)?[:.]?findNearestEnemy()/m}] 'closing-the-distance': hidesHUD: true hidesSay: true @@ -154,6 +162,7 @@ module.exports = LevelOptions = hidesRealTimePlayback: true requiredGear: {feet: 'simple-boots', 'right-hand': 'simple-sword', torso: 'leather-tunic', eyes: 'crude-glasses'} restrictedGear: {feet: 'leather-boots'} + suspectCode: [{name: 'lone-find-nearest-enemy', pattern: /^[ ]*(self|this|@)?[:.]?findNearestEnemy()/m}] 'tactical-strike': hidesHUD: true hidesSay: true @@ -161,12 +170,14 @@ module.exports = LevelOptions = hidesRealTimePlayback: true requiredGear: {feet: 'simple-boots', 'right-hand': 'simple-sword', torso: 'leather-tunic', eyes: 'crude-glasses'} restrictedGear: {feet: 'leather-boots'} + suspectCode: [{name: 'lone-find-nearest-enemy', pattern: /^[ ]*(self|this|@)?[:.]?findNearestEnemy()/m}] 'the-final-kithmaze': hidesHUD: true hidesSay: true hidesCodeToolbar: true hidesRealTimePlayback: true requiredGear: {feet: 'simple-boots', 'right-hand': 'simple-sword', torso: 'leather-tunic', 'programming-book': 'programmaticon-i', eyes: 'crude-glasses'} + suspectCode: [{name: 'lone-find-nearest-enemy', pattern: /^[ ]*(self|this|@)?[:.]?findNearestEnemy()/m}] 'the-gauntlet': hidesHUD: true hidesSay: true @@ -174,6 +185,7 @@ module.exports = LevelOptions = hidesRealTimePlayback: true requiredGear: {feet: 'simple-boots', 'right-hand': 'simple-sword', torso: 'leather-tunic', 'programming-book': 'programmaticon-i', eyes: 'crude-glasses'} restrictedGear: {feet: 'leather-boots'} + suspectCode: [{name: 'lone-find-nearest-enemy', pattern: /^[ ]*(self|this|@)?[:.]?findNearestEnemy()/m}] 'kithgard-gates': hidesSay: true hidesCodeToolbar: true diff --git a/app/lib/surface/CoordinateDisplay.coffee b/app/lib/surface/CoordinateDisplay.coffee index e9928ed60..5f4684884 100644 --- a/app/lib/surface/CoordinateDisplay.coffee +++ b/app/lib/surface/CoordinateDisplay.coffee @@ -6,6 +6,7 @@ module.exports = class CoordinateDisplay extends createjs.Container 'surface:mouse-over': 'onMouseOver' 'surface:stage-mouse-down': 'onMouseDown' 'camera:zoom-updated': 'onZoomUpdated' + 'level:flag-color-selected': 'onFlagColorSelected' constructor: (options) -> super() @@ -60,6 +61,9 @@ module.exports = class CoordinateDisplay extends createjs.Container @hide() @show() + onFlagColorSelected: (e) -> + @placingFlag = Boolean e.color + hide: -> return unless @label.parent @removeChild @label @@ -154,6 +158,6 @@ module.exports = class CoordinateDisplay extends createjs.Container @y = sup.y @addChild @background @addChild @label - @addChild @pointMarker + @addChild @pointMarker unless @placingFlag @updateCache() Backbone.Mediator.publish 'surface:coordinates-shown', {} diff --git a/app/schemas/subscriptions/tome.coffee b/app/schemas/subscriptions/tome.coffee index b4530a9a8..26712d1e1 100644 --- a/app/schemas/subscriptions/tome.coffee +++ b/app/schemas/subscriptions/tome.coffee @@ -122,6 +122,10 @@ module.exports = 'tome:required-code-fragment-deleted': c.object {title: 'Required Code Fragment Deleted', description: 'Published when a required code fragment is deleted from the sample code.', required: ['codeFragment']}, codeFragment: {type: 'string'} + 'tome:suspect-code-fragment-added': c.object {title: 'Suspect Code Fragment Added', description: 'Published when a suspect code fragment is added to the sample code.', required: ['codeFragment']}, + codeFragment: {type: 'string'} + codeLanguage: {type: 'string'} + 'tome:winnability-updated': c.object {title: 'Winnability Updated', description: 'When we think we can now win (or can no longer win), we may want to emphasize the submit button versus the run button (or vice versa), so this fires when we get new goal states (even preloaded goal states) suggesting success or failure change.', required: ['winnable']}, winnable: {type: 'boolean'} diff --git a/app/views/game-menu/InventoryModal.coffee b/app/views/game-menu/InventoryModal.coffee index 4de79d40d..d83089468 100644 --- a/app/views/game-menu/InventoryModal.coffee +++ b/app/views/game-menu/InventoryModal.coffee @@ -86,7 +86,7 @@ module.exports = class InventoryModal extends ModalView locked = not (item.get('original') in me.items()) locked = false if me.get('slug') is 'nick' - if not item.getFrontFacingStats().props.length and not _.size item.getFrontFacingStats().stats # Temp: while there are placeholder items + if not item.getFrontFacingStats().props.length and not _.size(item.getFrontFacingStats().stats) and not locked # Temp: while there are placeholder items null # Don't put into a collection else if locked and item.get('slug') isnt 'simple-boots' @itemGroups.lockedItems.add(item) diff --git a/app/views/play/level/tome/SpellView.coffee b/app/views/play/level/tome/SpellView.coffee index 986eb749b..209ac6f36 100644 --- a/app/views/play/level/tome/SpellView.coffee +++ b/app/views/play/level/tome/SpellView.coffee @@ -450,7 +450,8 @@ module.exports = class SpellView extends CocoView _.throttle @updateLines, 500 _.throttle @hideProblemAlert, 500 ] - onSignificantChange.push _.debounce @checkRequiredCode, 1500 if requiredCodePerLevel[@options.level.get('slug')] + onSignificantChange.push _.debounce @checkRequiredCode, 750 if LevelOptions[@options.level.get('slug')]?.requiredCode + onSignificantChange.push _.debounce @checkSuspectCode, 750 if LevelOptions[@options.level.get('slug')]?.suspectCode @onCodeChangeMetaHandler = => return if @eventsSuppressed Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'code-change', volume: 0.5 @@ -881,13 +882,26 @@ module.exports = class SpellView extends CocoView checkRequiredCode: => return if @destroyed source = @getSource().replace @singleLineCommentRegex(), '' - for requiredCodeFragment in requiredCodePerLevel[@options.level.get('slug')] + requiredCodeFragments = LevelOptions[@options.level.get('slug')].requiredCode + for requiredCodeFragment in requiredCodeFragments + # Could make this obey regular expressions like suspectCode if needed if source.indexOf(requiredCodeFragment) is -1 @warnedCodeFragments ?= {} unless @warnedCodeFragments[requiredCodeFragment] Backbone.Mediator.publish 'tome:required-code-fragment-deleted', codeFragment: requiredCodeFragment @warnedCodeFragments[requiredCodeFragment] = true + checkSuspectCode: => + return if @destroyed + source = @getSource().replace @singleLineCommentRegex(), '' + suspectCodeFragments = LevelOptions[@options.level.get('slug')].suspectCode + for suspectCodeFragment in suspectCodeFragments + if suspectCodeFragment.pattern.test source + @warnedCodeFragments ?= {} + unless @warnedCodeFragments[suspectCodeFragment.name] + Backbone.Mediator.publish 'tome:suspect-code-fragment-added', codeFragment: suspectCodeFragment.name, codeLanguage: @spell.language + @warnedCodeFragments[suspectCodeFragment] = true + destroy: -> $(@ace?.container).find('.ace_gutter').off 'click', '.ace_error, .ace_warning, .ace_info', @onAnnotationClick $(@ace?.container).find('.ace_gutter').off 'click', @onGutterClick @@ -900,11 +914,3 @@ module.exports = class SpellView extends CocoView @debugView?.destroy() $(window).off 'resize', @onWindowResize super() - - -requiredCodePerLevel = - 'dungeons-of-kithgard': ['moveRight'] - 'true-names': ['Brak'] - 'the-first-kithmaze': ['loop'] - 'haunted-kithmaze': ['loop'] - 'lowly-kithmen': ['findNearestEnemy']