diff --git a/lib/canvas-renderer.coffee b/lib/canvas-renderer.coffee index b5f0605..db4f5dc 100644 --- a/lib/canvas-renderer.coffee +++ b/lib/canvas-renderer.coffee @@ -3,6 +3,7 @@ random = require "lodash.random" colorHelper = require "./color-helper" module.exports = + api: null colorHelper: colorHelper subscriptions: null conf: [] @@ -11,14 +12,18 @@ module.exports = setEffectRegistry: (effectRegistry) -> @effectRegistry = effectRegistry - enable: -> + enable: (api) -> + @api = api @initConfigSubscribers() @colorHelper.init() init: -> - @effectRegistry.effect.init() + @effectRegistry.effect.init(@api) @animationOn() + getEffect: -> + @effectRegistry.effect + resetCanvas: -> @animationOff() @canvas?.style.display = "none" @@ -39,6 +44,7 @@ module.exports = @canvas = null @subscriptions?.dispose() @colorHelper?.disable() + @api = null setupCanvas: (editor, editorElement) -> if not @canvas diff --git a/lib/plugin/power-canvas.coffee b/lib/plugin/power-canvas.coffee index 7802229..88a96c7 100644 --- a/lib/plugin/power-canvas.coffee +++ b/lib/plugin/power-canvas.coffee @@ -1,21 +1,43 @@ throttle = require "lodash.throttle" module.exports = + api: null + setCanvasRenderer: (canvasRenderer) -> @canvas = canvasRenderer - enable: -> - @canvas.enable() + enable: (api) -> + @api = api + @canvas.enable(api) disable: -> + @api = null @canvas.destroy() onChangePane: (editor, editorElement) -> @canvas.resetCanvas() @canvas.setupCanvas editor, editorElement if editor + @canvas.getEffect().onChangePane?(editor, editorElement) - onNewCursor: (cursor) -> + onNewCursor: (cursor, screenPosition, input, data) -> cursor.spawn = throttle @canvas.spawn.bind(@canvas), 25, trailing: false + @canvas.getEffect().onNewCursor?(cursor, screenPosition, input, data) onInput: (cursor, screenPosition, input, data) -> cursor.spawn cursor, screenPosition, input, data['size'] + @canvas.getEffect().onInput?(cursor, screenPosition, input, data) + + onComboStartStreak: -> + @canvas.getEffect().onComboStartStreak?() + + onComboLevelChange: (newLvl, oldLvl) -> + @canvas.getEffect().onComboLevelChange?(newLvl, oldLvl) + + onComboEndStreak: -> + @canvas.getEffect().onComboEndStreak?() + + onComboExclamation: (text) -> + @canvas.getEffect().onComboExclamation?(text) + + onComboMaxStreak: (maxStreak) -> + @canvas.getEffect().onComboMaxStreak?(maxStreak)