From 6a983dcb8cb22eb5a3a682d5573c60e2d6046f85 Mon Sep 17 00:00:00 2001 From: Dominik Kundel Date: Mon, 17 Mar 2014 02:14:04 +0100 Subject: [PATCH] changed name of event triggered when config is changed and introduced new event when language is changed --- app/views/play/level/modal/editor_config_modal.coffee | 4 +++- app/views/play/level/tome/spell.coffee | 9 +++++++++ app/views/play/level/tome/spell_view.coffee | 9 +++++++-- app/views/play/level/tome/tome_view.coffee | 4 ++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/app/views/play/level/modal/editor_config_modal.coffee b/app/views/play/level/modal/editor_config_modal.coffee index ded3bdf5e..6eee66071 100644 --- a/app/views/play/level/modal/editor_config_modal.coffee +++ b/app/views/play/level/modal/editor_config_modal.coffee @@ -54,13 +54,15 @@ module.exports = class EditorConfigModal extends View super() onHidden: -> + oldLanguage = @aceConfig.language @aceConfig.language = @$el.find('#tome-language').val() @aceConfig.invisibles = @$el.find('#tome-invisibles').prop('checked') @aceConfig.keyBindings = @$el.find('#tome-key-bindings').val() @aceConfig.indentGuides = @$el.find('#tome-indent-guides').prop('checked') @aceConfig.behaviors = @$el.find('#tome-behaviors').prop('checked') me.set 'aceConfig', @aceConfig - Backbone.Mediator.publish 'change:editor-config' + Backbone.Mediator.publish 'tome:change-config' + Backbone.Mediator.publish 'tome:change-language' unless @aceConfig.language is oldLanguage me.save() destroy: -> diff --git a/app/views/play/level/tome/spell.coffee b/app/views/play/level/tome/spell.coffee index deaf856f8..b18263e9f 100644 --- a/app/views/play/level/tome/spell.coffee +++ b/app/views/play/level/tome/spell.coffee @@ -85,11 +85,13 @@ module.exports = class Spell aether.hasChangedSignificantly (newSource ? @originalSource), (currentSource ? @source), true, true createAether: (thang) -> + aceConfig = me.get 'aceConfig' ? {} aetherOptions = problems: jshint_W040: {level: "ignore"} jshint_W030: {level: "ignore"} # aether_NoEffect instead aether_MissingThis: {level: (if thang.requiresThis then 'error' else 'warning')} + language: aceConfig.language ? 'javascript' functionName: @name functionParameters: @parameters yieldConditionally: thang.plan? @@ -107,5 +109,12 @@ module.exports = class Spell aether = new Aether aetherOptions aether + updateLanguageAether: -> + aceConfig = me.get 'aceConfig' ? {} + for thangId, spellThang of @thangs + spellThang.aether?.setLanguage (aceConfig.language ? 'javascript') + spellThang.castAether = null + @transpile() + toString: -> "" diff --git a/app/views/play/level/tome/spell_view.coffee b/app/views/play/level/tome/spell_view.coffee index c3639e6b3..3cfa7f347 100644 --- a/app/views/play/level/tome/spell_view.coffee +++ b/app/views/play/level/tome/spell_view.coffee @@ -38,8 +38,9 @@ module.exports = class SpellView extends View 'modal-closed': 'focus' 'focus-editor': 'focus' 'tome:spell-statement-index-updated': 'onStatementIndexUpdated' + 'tome:change-language': 'onChangeLanguage' + 'tome:change-config': 'onChangeEditorConfig' 'spell-beautify': 'onSpellBeautify' - 'change:editor-config': 'onChangeEditorConfig' events: 'mouseout': 'onMouseOut' @@ -566,10 +567,14 @@ module.exports = class SpellView extends View onChangeEditorConfig: (e) -> aceConfig = me.get 'aceConfig' @ace.setDisplayIndentGuides aceConfig.indentGuides # default false - @ace.setShowInvisibles # default false + @ace.setShowInvisibles aceConfig.invisibles # default false @ace.setKeyboardHandler @keyBindings[aceConfig.keyBindings ? 'default'] @aceSession.setMode @editModes[aceConfig.language ? 'javascript'] + onChangeLanguage: (e) -> + aceConfig = me.get 'aceConfig' + @aceSession.setMode @editModes[aceConfig.language ? 'javascript'] + dismiss: -> @recompile() if @spell.hasChangedSignificantly @getSource() diff --git a/app/views/play/level/tome/tome_view.coffee b/app/views/play/level/tome/tome_view.coffee index 9640a98d0..8e0d9ac12 100644 --- a/app/views/play/level/tome/tome_view.coffee +++ b/app/views/play/level/tome/tome_view.coffee @@ -48,6 +48,7 @@ module.exports = class TomeView extends View 'tome:spell-loaded': "onSpellLoaded" 'tome:cast-spell': "onCastSpell" 'tome:toggle-spell-list': 'onToggleSpellList' + 'tome:change-language': 'updateLanguageForAllSpells' 'surface:sprite-selected': 'onSpriteSelected' 'god:new-world-created': 'onNewWorld' @@ -217,6 +218,9 @@ module.exports = class TomeView extends View spell.view.reloadCode false for spellKey, spell of @spells Backbone.Mediator.publish 'tome:cast-spells', spells: @spells + updateLanguageForAllSpells: -> + spell.updateLanguageAether for spellKey, spell of @spells + destroy: -> spell.destroy() for spellKey, spell of @spells @worker?._close()