-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.coffee
More file actions
190 lines (169 loc) · 4.62 KB
/
Copy pathindex.coffee
File metadata and controls
190 lines (169 loc) · 4.62 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
"use strict"
dat = dat or window?.dat or @dat or require? "dat.gui"
throw new Error "Can't find `dat`" unless dat
Phaser = Phaser or window?.Phaser or @Phaser or require? "phaser"
throw new Error "Can't find `Phaser`" unless Phaser
{ScaleManager} = Phaser
{Arcade} = Phaser.Physics
{isArray} = Array
clickTrampolineChoices = ["", "when-not-mouse"]
windowConstraintChoices = ["", "layout", "visual"]
if ScaleManager
scaleModes =
"exact fit": ScaleManager.EXACT_FIT
"no scale": ScaleManager.NO_SCALE
"resize": ScaleManager.RESIZE
"show all": ScaleManager.SHOW_ALL
"user scale": ScaleManager.USER_SCALE
addArcadeSortDirection = (cn, arcade, name) ->
controller = cn.add arcade, name,
"bottom top": Arcade.BOTTOM_TOP
"left right": Arcade.LEFT_RIGHT
"right left": Arcade.RIGHT_LEFT
"top bottom": Arcade.TOP_BOTTOM
"sort none": Arcade.SORT_NONE
controller.onChange saveNumericValue
controller
addScaleMode = (cn, scaleManager, name) ->
controller = cn.add scaleManager, name, scaleModes
controller.onChange saveNumericValue
controller
saveNumericValue = (newValue) ->
@object[@property] = Number newValue
return
PROPS = Object.freeze
game:
clearBeforeRender: yes
disableStep: yes
enableStep: yes
forceSingleUpdate: yes
lockRender: yes
paused: yes
step: yes
camera:
fade: yes
flash: yes
reset: yes
resetFX: yes
roundPx: yes
shake: yes
unfollow: yes
x: (cn, camera) -> [camera.bounds.left, camera.bounds.right - camera.view.width , 10]
y: (cn, camera) -> [camera.bounds.top , camera.bounds.bottom - camera.view.height, 10]
lerp:
x: [0, 1, 0.05]
y: [0, 1, 0.05]
debug:
font: yes
lineHeight: [10, 50, 2]
renderShadow: yes
sprite:
visible: yes
input:
enabled: yes
maxPointers: [-1, 10, 1]
keyboard:
enabled: yes
mouse:
capture: yes
enabled: yes
mspointer: # TODO only if running?
capture: yes
enabled: yes
touch:
enabled: yes
preventDefault: yes
physics:
arcade:
OVERLAP_BIAS: [-16, 16, 1]
TILE_BIAS: [-16, 16, 1]
checkCollision:
down: yes
left: yes
right: yes
up: yes
forceX: yes
gravity:
x: [-1000, 1000, 10]
y: [-1000, 1000, 10]
isPaused: yes
skipQuadTree: yes
sortDirection: addArcadeSortDirection
scale:
compatibility:
canExpandParent: yes
clickTrampoline: [clickTrampolineChoices]
forceMinimumDocumentHeight: yes
noMargins: yes
orientationFallback: yes
# TODO scrollTo
supportsFullScreen: yes
fullScreenScaleMode: addScaleMode
pageAlignHorizontally: yes
pageAlignVertically: yes
parentIsWindow: yes
refresh: yes
scaleMode: addScaleMode
startFullScreen: yes
stopFullScreen: yes
windowConstraints:
bottom: [windowConstraintChoices]
right: [windowConstraintChoices]
sound:
mute: yes
volume: [0, 1, 0.1]
stage:
backgroundColor: (cn, stage, name) -> cn.addColor stage, name
disableVisibilityChange: yes
smoothed: yes
state:
restart: yes
time:
desiredFps: [10, 120, 5]
slowMotion: [0.1, 10, 0.1]
tweens:
frameBased: yes
pauseAll: yes
resumeAll: yes
world:
alpha: [0, 1, 0.1]
visible: yes
class Phaser.Plugin.GameGui extends Phaser.Plugin
gui: null
init: (options) ->
@createGui options
return
destroy: ->
@gui.destroy()
return
add: (guiContainer, obj, props) ->
for name, args of props
@addProp guiContainer, obj, name, args
guiContainer
addProp: (guiContainer, obj, name, args) ->
val = obj[name]
unless val?
console.warn "Skipped '#{name}' (#{val})"
return
if typeof args is "function"
result = args.call null, guiContainer, obj, name
args = if isArray result then result else no
switch
when args is no
return
when args is yes
field = guiContainer.add(obj, name)
unless typeof val is "function"
field.listen()
when isArray args
addArgs = [obj, name].concat args
guiContainer.add.apply(guiContainer, addArgs).listen()
when typeof args is "object"
@add guiContainer.addFolder(name), obj[name], args
else
console.warn "Nothing to do: #{args}"
guiContainer
createGui: (options) ->
@gui = new dat.GUI options
@add @gui, @game, PROPS.game
@gui