Skip to content

Commit

Permalink
Add possibility to handle plugin events on canvas effects (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
lexcast authored Aug 6, 2017
1 parent 11c7ad0 commit 37f7c51
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
10 changes: 8 additions & 2 deletions lib/canvas-renderer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ random = require "lodash.random"
colorHelper = require "./color-helper"

module.exports =
api: null
colorHelper: colorHelper
subscriptions: null
conf: []
Expand All @@ -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"
Expand All @@ -39,6 +44,7 @@ module.exports =
@canvas = null
@subscriptions?.dispose()
@colorHelper?.disable()
@api = null

setupCanvas: (editor, editorElement) ->
if not @canvas
Expand Down
28 changes: 25 additions & 3 deletions lib/plugin/power-canvas.coffee
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 37f7c51

Please sign in to comment.