-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.coffee
52 lines (41 loc) · 1.1 KB
/
index.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"use strict"
{Phaser} = this
class Phaser.Plugin.Step extends Phaser.Plugin
keyChar:
STEP: "/"
TOGGLE: "."
keyCode:
STEP: Phaser.KeyCode.QUESTION_MARK # slash
TOGGLE: Phaser.KeyCode.PERIOD
init: ->
{keyboard} = @game.input
@keyBindings = []
@keyBindings.push keyboard.addKey(@keyCode.STEP) .onUp.add @game.step, @game
@keyBindings.push keyboard.addKey(@keyCode.TOGGLE).onUp.add @toggleStep, this
@position = new Phaser.Point 20, 20
return
render: ->
{debug} = @game
if @game.stepping
text = "[#{@keyChar.STEP}] Step Forward [#{@keyChar.TOGGLE}] Exit Step Step Count: #{@game.stepCount}"
debug.text text, @position.x, @position.y, null, debug.font
return
destroy: ->
super
@removeKeyBindings()
return
disableStep: ->
@game.disableStep()
@game.debug.reset()
return
enableStep: ->
@game.enableStep()
@render()
return
removeKeyBindings: ->
for binding in @keyBindings
binding.detach()
return
toggleStep: ->
if @game.stepping then @disableStep() else @enableStep()
return