/
controllers.ds
415 lines (363 loc) · 14.2 KB
/
controllers.ds
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# Gamepad Controller Presets
import App, Input, Console, Version
def event(context, button, command, repeat=False, condition=None)
# Bind an event to a console command.
if condition: condition = ' + ' + condition
else: condition = ''
if 'hat' in button
Input.bindEvent('%s:%s%s' % [context, button, condition], command)
else
Input.bindEvent('%s:%s-down%s' % [context, button, condition], command)
if repeat: Input.bindEvent('%s:%s-repeat%s' % [context, button, condition], command)
end
end
def control(ctl, impulse, inverse=False, condition=None)
# Bind a control to a player impulse.
if inverse: ctl += '-inverse'
if condition: ctl += ' + ' + condition
Input.bindControl(ctl, 'local1-%s' % impulse)
end
record Gamepad()
def __init__(id, regex)
# Arguments:
# id: Identifier of the controller.
# regex: One or more regexes (Text, or Array of Texts)
# for matching against the joystick name.
self.id = id
self.regex = regex
end
def bind(); end
def register()
regs = self.regex
if typeof(regs) != 'Array': regs = [regs]
for reg in regs
Input.controllerPresets[reg] = Record(self)
end
end
def resetDeadzones()
for var in Console.listVars('input-joy-.*-deadzone')
Console.set(var, Input.DEFAULT_STICK_DEADZONE)
end
for var in Console.listVars('input-joy-.*-factor')
Console.set(var, Input.DEFAULT_STICK_FACTOR)
end
for var in Console.listVars('input-joy-.*-offset')
Console.set(var, 0)
end
end
def disableAllAxes()
for var in Console.listVars('input-joy-.*-factor')
Console.set(var, 0)
end
end
end
record GenericGamepad(Gamepad)
def __init__(): self.Gamepad->__init__('Generic', '')
def bind()
print 'Bindings for GenericGamePad:', self.id
self.resetDeadzones()
end
end
record PS3Gamepad(Gamepad)
def __init__(id, regex): self.Gamepad->__init__(id, regex)
def bind()
# Names for buttons and other controls.
x = 'joy-button15'
o = 'joy-button14'
tri = 'joy-button13'
sqr = 'joy-button16'
play = 'joy-button4'
select = 'joy-button1'
leftPress = 'joy-button2'
rightPress = 'joy-button3'
up = 'joy-button5'
down = 'joy-button7'
left = 'joy-button8'
right = 'joy-button6'
L1 = 'joy-button11'
L2 = 'joy-button9'
R1 = 'joy-button12'
R2 = 'joy-button10'
leftHoriz = 'joy-x'
leftVert = 'joy-y'
rightHoriz = 'joy-z'
rightVert = 'joy-w'
# Common controls, suitable for all games.
event('shortcut', play, 'menu')
event('menu', o, 'menuback')
event('menu', x, 'menuselect')
event('menu', up, 'menuup', repeat=True)
event('menu', down, 'menudown', repeat=True)
event('menu', left, 'menuleft', repeat=True)
event('menu', right, 'menuright', repeat=True)
event('game', L1, 'pause')
event('game', o, 'impulse jump')
event('game', sqr, 'impulse use')
event('game', up, 'impulse nextweapon')
event('game', down, 'impulse prevweapon')
event('game', rightPress, 'impulse lookcenter', condition='modifier-2-up')
event('game', select, 'impulse automap')
control(R1, 'flymode') # modifier 2
control(rightVert, 'zfly', inverse=True, condition='modifier-2-down')
event('game', rightPress, 'impulse falldown', condition='modifier-2-down')
control(leftHoriz, 'sidestep')
control(leftVert, 'walk', inverse=True)
control(rightHoriz, 'turn')
control(rightVert, 'look', inverse=True, condition='modifier-2-up')
control(x, 'attack')
control(R2, 'attack')
control(L2, 'speed')
event('map', rightPress, 'impulse follow')
event('map', leftPress, 'impulse rotate')
control(rightHoriz, 'mappanx')
control(rightVert, 'mappany', inverse=True)
control(R2, 'mapzoom')
control(R1, 'mapzoom', inverse=True)
# Inventory controls for Heretic and Hexen.
if App.gamePlugin() in ['heretic', 'hexen']
event('game', left, 'impulse previtem')
event('game', right, 'impulse nextitem')
event('game', tri, 'impulse useitem')
end
# Deadzones.
self.resetDeadzones()
self.disableAllAxes()
for axis in ['x', 'y', 'z', 'w']
Console.set('input-joy-%s-deadzone' % axis, 0.15)
Console.set('input-joy-%s-factor' % axis, 1)
end
end
end
record PS4Gamepad(Gamepad)
def __init__(id, regex): self.Gamepad->__init__(id, regex)
def bind()
# Names for buttons and other controls.
sqr = 'joy-button1'
x = 'joy-button2'
o = 'joy-button3'
tri = 'joy-button4'
pad = 'joy-button14'
options = 'joy-button10'
share = 'joy-button9'
ps = 'joy-button13'
leftPress = 'joy-button11'
rightPress = 'joy-button12'
up = 'joy-hat1-angle0'
down = 'joy-hat1-angle4'
left = 'joy-hat1-angle6'
right = 'joy-hat1-angle2'
L1 = 'joy-button5'
R1 = 'joy-button6'
L2 = 'joy-button7'
R2 = 'joy-button8'
leftHoriz = 'joy-x'
leftVert = 'joy-y'
rightHoriz = 'joy-z'
rightVert = 'joy-axis06'
# Common controls, suitable for all games.
event('shortcut', options, 'menu')
event('menu', o, 'menuback')
event('menu', x, 'menuselect')
event('menu', up, 'menuup', repeat=True)
event('menu', down, 'menudown', repeat=True)
event('menu', left, 'menuleft', repeat=True)
event('menu', right, 'menuright', repeat=True)
event('game', L1, 'pause')
event('game', o, 'impulse jump')
event('game', sqr, 'impulse use')
event('game', up, 'impulse nextweapon')
event('game', down, 'impulse prevweapon')
event('game', rightPress, 'impulse lookcenter', condition='modifier-2-up')
event('game', pad, 'impulse automap')
control(R1, 'flymode') # modifier 2
control(rightVert, 'zfly', inverse=True, condition='modifier-2-down')
event('game', rightPress, 'impulse falldown', condition='modifier-2-down')
control(leftHoriz, 'sidestep')
control(leftVert, 'walk', inverse=True)
control(rightHoriz, 'turn')
control(rightVert, 'look', inverse=True, condition='modifier-2-up')
control(x, 'attack')
control(R2, 'attack')
control(L2, 'speed')
event('map', rightPress, 'impulse follow')
event('map', leftPress, 'impulse rotate')
control(rightHoriz, 'mappanx')
control(rightVert, 'mappany', inverse=True)
control(R2, 'mapzoom')
control(R1, 'mapzoom', inverse=True)
# Inventory controls for Heretic and Hexen.
if App.gamePlugin() in ['heretic', 'hexen']
event('game', left, 'impulse previtem')
event('game', right, 'impulse nextitem')
event('game', tri, 'impulse useitem')
end
# Deadzones.
self.resetDeadzones()
self.disableAllAxes()
for axis in ['x', 'y', 'z', 'axis06']
Console.set('input-joy-%s-deadzone' % axis, 0.15)
Console.set('input-joy-%s-factor' % axis, 1)
end
end
end
record XboxWindowsGamepad(Gamepad)
# Xbox One controller with default Windows game controller setup.
def __init__(id, regex): self.Gamepad->__init__(id, regex)
def bind()
# Names for buttons and other controls.
a = 'joy-button1'
b = 'joy-button2'
x = 'joy-button3'
y = 'joy-button4'
leftPress = 'joy-button9'
rightPress = 'joy-button10'
menu = 'joy-button8'
view = 'joy-button7'
up = 'joy-hat1-angle0'
down = 'joy-hat1-angle4'
left = 'joy-hat1-angle6'
right = 'joy-hat1-angle2'
LB = 'joy-button5'
RB = 'joy-button6'
thruster = 'joy-z'
leftHoriz = 'joy-x'
leftVert = 'joy-y'
rightHoriz = 'joy-w'
rightVert = 'joy-axis05'
# Common controls, suitable for all games.
event('shortcut', menu, 'menu')
event('menu', b, 'menuback')
event('menu', a, 'menuselect')
event('menu', up, 'menuup', repeat=True)
event('menu', down, 'menudown', repeat=True)
event('menu', left, 'menuleft', repeat=True)
event('menu', right, 'menuright', repeat=True)
event('game', leftPress, 'pause')
event('game', view, 'impulse automap')
event('game', b, 'impulse jump')
event('game', x, 'impulse use')
event('game', up, 'impulse nextweapon')
event('game', down, 'impulse prevweapon')
event('game', rightPress, 'impulse lookcenter', condition='modifier-2-up')
control(RB, 'flymode') # modifier 2
control(rightVert, 'zfly', inverse=True, condition='modifier-2-down')
event('game', rightPress, 'impulse falldown', condition='modifier-2-down')
control(leftHoriz, 'sidestep')
control(leftVert, 'walk', inverse=True)
control(rightHoriz, 'turn')
control(rightVert, 'look', inverse=True, condition='modifier-2-up')
control(a, 'attack')
control(thruster, 'attack')
control(LB, 'speed')
event('map', rightPress, 'impulse follow')
event('map', leftPress, 'impulse rotate')
control(rightHoriz, 'mappanx')
control(rightVert, 'mappany', inverse=True)
control(thruster, 'mapzoom')
#control(RB, 'mapzoom', inverse=True)
# Inventory controls for Heretic and Hexen.
if App.gamePlugin() in ['heretic', 'hexen']
event('game', left, 'impulse previtem')
event('game', right, 'impulse nextitem')
event('game', y, 'impulse useitem')
end
# Deadzones.
self.resetDeadzones()
self.disableAllAxes()
for axis in ['x', 'y', 'w', 'axis05']
Console.set('input-joy-%s-deadzone' % axis, 0.15)
Console.set('input-joy-%s-factor' % axis, 1)
end
Console.set('input-joy-z-factor', 1)
end
end
record XboxMacGamepad(Gamepad)
# Configures presets suitable for the Xbox One controller used with
# the "360Controller" driver on macOS (driver defaults):
# https://github.com/360Controller/360Controller
def __init__(id, regex): self.Gamepad->__init__(id, regex)
def bind()
# Names for buttons and other controls.
a = 'joy-button1'
b = 'joy-button2'
x = 'joy-button3'
y = 'joy-button4'
leftPress = 'joy-button7'
rightPress = 'joy-button8'
menu = 'joy-button9'
view = 'joy-button10'
xbox = 'joy-button11'
up = 'joy-button12'
down = 'joy-button13'
left = 'joy-button14'
right = 'joy-button15'
LB = 'joy-button5'
RB = 'joy-button6'
LT = 'joy-z'
RT = 'joy-axis06'
leftHoriz = 'joy-x'
leftVert = 'joy-y'
rightHoriz = 'joy-w'
rightVert = 'joy-axis05'
# Common controls, suitable for all games.
event('shortcut', menu, 'menu')
event('shortcut', xbox, 'menu')
event('menu', b, 'menuback')
event('menu', a, 'menuselect')
event('menu', up, 'menuup', repeat=True)
event('menu', down, 'menudown', repeat=True)
event('menu', left, 'menuleft', repeat=True)
event('menu', right, 'menuright', repeat=True)
event('game', LB, 'pause')
event('game', view, 'impulse automap')
event('game', b, 'impulse jump')
event('game', x, 'impulse use')
event('game', up, 'impulse nextweapon')
event('game', down, 'impulse prevweapon')
event('game', rightPress, 'impulse lookcenter', condition='modifier-2-up')
control(RB, 'flymode') # modifier 2
control(rightVert, 'zfly', inverse=True, condition='modifier-2-down')
event('game', rightPress, 'impulse falldown', condition='modifier-2-down')
control(leftHoriz, 'sidestep')
control(leftVert, 'walk', inverse=True)
control(rightHoriz, 'turn')
control(rightVert, 'look', inverse=True, condition='modifier-2-up')
control(a, 'attack')
control(RT, 'attack')
control(LT, 'speed')
event('map', rightPress, 'impulse follow')
event('map', leftPress, 'impulse rotate')
control(rightHoriz, 'mappanx')
control(rightVert, 'mappany', inverse=True)
control(RT, 'mapzoom')
control(RB, 'mapzoom', inverse=True)
# Inventory controls for Heretic and Hexen.
if App.gamePlugin() in ['heretic', 'hexen']
event('game', left, 'impulse previtem')
event('game', right, 'impulse nextitem')
event('game', y, 'impulse useitem')
end
# Deadzones.
self.resetDeadzones()
self.disableAllAxes()
for axis in ['x', 'y', 'w', 'axis05']
Console.set('input-joy-%s-deadzone' % axis, 0.15)
Console.set('input-joy-%s-factor' % axis, 1)
end
# Thrusters are stick axes, but we want them to go from 0 to 1.
Console.set('input-%s-factor' % LT, Input.DEFAULT_STICK_FACTOR/2)
Console.set('input-%s-offset' % LT, 0.5)
Console.set('input-%s-factor' % RT, Input.DEFAULT_STICK_FACTOR/2)
Console.set('input-%s-offset' % RT, 0.5)
end
end
# Platform-independent controllers:
GenericGamepad().register()
PS3Gamepad('PS3', ['PLAYSTATION\(R\)3 Controller']).register()
PS4Gamepad('PS4', ['Wireless Controller']).register()
# Platform-specific configs:
if Version.OS == 'windows'
XboxWindowsGamepad('Xbox One', ['.*Xbox One For Windows.*']).register()
elsif Version.OS == 'macx'
XboxMacGamepad('Xbox One/360 (360Controller)', ['.*Xbox (360|One).*']).register()
end