summaryrefslogtreecommitdiff
path: root/meta/3rd/love2d/library/love.joystick.lua
blob: 29e21cd89fc9beddbd1186600eae5fe54c9a17d2 (plain)
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
---@meta

---
---Provides an interface to the user's joystick.
---
---@class love.joystick
love.joystick = {}

---
---Gets the full gamepad mapping string of the Joysticks which have the given GUID, or nil if the GUID isn't recognized as a gamepad.
---
---The mapping string contains binding information used to map the Joystick's buttons an axes to the standard gamepad layout, and can be used later with love.joystick.loadGamepadMappings.
---
---@param guid string # The GUID value to get the mapping string for.
---@return string mappingstring # A string containing the Joystick's gamepad mappings, or nil if the GUID is not recognized as a gamepad.
function love.joystick.getGamepadMappingString(guid) end

---
---Gets the number of connected joysticks.
---
---@return number joystickcount # The number of connected joysticks.
function love.joystick.getJoystickCount() end

---
---Gets a list of connected Joysticks.
---
---@return table joysticks # The list of currently connected Joysticks.
function love.joystick.getJoysticks() end

---
---Loads a gamepad mappings string or file created with love.joystick.saveGamepadMappings.
---
---It also recognizes any SDL gamecontroller mapping string, such as those created with Steam's Big Picture controller configure interface, or this nice database. If a new mapping is loaded for an already known controller GUID, the later version will overwrite the one currently loaded.
---
---@overload fun(mappings: string)
---@param filename string # The filename to load the mappings string from.
function love.joystick.loadGamepadMappings(filename) end

---
---Saves the virtual gamepad mappings of all recognized as gamepads and have either been recently used or their gamepad bindings have been modified.
---
---The mappings are stored as a string for use with love.joystick.loadGamepadMappings.
---
---@overload fun():string
---@param filename string # The filename to save the mappings string to.
---@return string mappings # The mappings string that was written to the file.
function love.joystick.saveGamepadMappings(filename) end

---
---Binds a virtual gamepad input to a button, axis or hat for all Joysticks of a certain type. For example, if this function is used with a GUID returned by a Dualshock 3 controller in OS X, the binding will affect Joystick:getGamepadAxis and Joystick:isGamepadDown for ''all'' Dualshock 3 controllers used with the game when run in OS X.
---
---LÖVE includes built-in gamepad bindings for many common controllers. This function lets you change the bindings or add new ones for types of Joysticks which aren't recognized as gamepads by default.
---
---The virtual gamepad buttons and axes are designed around the Xbox 360 controller layout.
---
---@overload fun(guid: string, axis: love.GamepadAxis, inputtype: love.JoystickInputType, inputindex: number, hatdir: love.JoystickHat):boolean
---@param guid string # The OS-dependent GUID for the type of Joystick the binding will affect.
---@param button love.GamepadButton # The virtual gamepad button to bind.
---@param inputtype love.JoystickInputType # The type of input to bind the virtual gamepad button to.
---@param inputindex number # The index of the axis, button, or hat to bind the virtual gamepad button to.
---@param hatdir? love.JoystickHat # The direction of the hat, if the virtual gamepad button will be bound to a hat. nil otherwise.
---@return boolean success # Whether the virtual gamepad button was successfully bound.
function love.joystick.setGamepadMapping(guid, button, inputtype, inputindex, hatdir) end

---
---Represents a physical joystick.
---
---@class love.Joystick: love.Object
local Joystick = {}

---
---Gets the direction of each axis.
---
---@return number axisDir1 # Direction of axis1.
---@return number axisDir2 # Direction of axis2.
---@return number axisDirN # Direction of axisN.
function Joystick:getAxes() end

---
---Gets the direction of an axis.
---
---@param axis number # The index of the axis to be checked.
---@return number direction # Current value of the axis.
function Joystick:getAxis(axis) end

---
---Gets the number of axes on the joystick.
---
---@return number axes # The number of axes available.
function Joystick:getAxisCount() end

---
---Gets the number of buttons on the joystick.
---
---@return number buttons # The number of buttons available.
function Joystick:getButtonCount() end

---
---Gets the USB vendor ID, product ID, and product version numbers of joystick which consistent across operating systems.
---
---Can be used to show different icons, etc. for different gamepads.
---
---@return number vendorID # The USB vendor ID of the joystick.
---@return number productID # The USB product ID of the joystick.
---@return number productVersion # The product version of the joystick.
function Joystick:getDeviceInfo() end

---
---Gets a stable GUID unique to the type of the physical joystick which does not change over time. For example, all Sony Dualshock 3 controllers in OS X have the same GUID. The value is platform-dependent.
---
---@return string guid # The Joystick type's OS-dependent unique identifier.
function Joystick:getGUID() end

---
---Gets the direction of a virtual gamepad axis. If the Joystick isn't recognized as a gamepad or isn't connected, this function will always return 0.
---
---@param axis love.GamepadAxis # The virtual axis to be checked.
---@return number direction # Current value of the axis.
function Joystick:getGamepadAxis(axis) end

---
---Gets the button, axis or hat that a virtual gamepad input is bound to.
---
---@overload fun(self: love.Joystick, button: love.GamepadButton):love.JoystickInputType, number, love.JoystickHat
---@param axis love.GamepadAxis # The virtual gamepad axis to get the binding for.
---@return love.JoystickInputType inputtype # The type of input the virtual gamepad axis is bound to.
---@return number inputindex # The index of the Joystick's button, axis or hat that the virtual gamepad axis is bound to.
---@return love.JoystickHat hatdirection # The direction of the hat, if the virtual gamepad axis is bound to a hat. nil otherwise.
function Joystick:getGamepadMapping(axis) end

---
---Gets the full gamepad mapping string of this Joystick, or nil if it's not recognized as a gamepad.
---
---The mapping string contains binding information used to map the Joystick's buttons an axes to the standard gamepad layout, and can be used later with love.joystick.loadGamepadMappings.
---
---@return string mappingstring # A string containing the Joystick's gamepad mappings, or nil if the Joystick is not recognized as a gamepad.
function Joystick:getGamepadMappingString() end

---
---Gets the direction of the Joystick's hat.
---
---@param hat number # The index of the hat to be checked.
---@return love.JoystickHat direction # The direction the hat is pushed.
function Joystick:getHat(hat) end

---
---Gets the number of hats on the joystick.
---
---@return number hats # How many hats the joystick has.
function Joystick:getHatCount() end

---
---Gets the joystick's unique identifier. The identifier will remain the same for the life of the game, even when the Joystick is disconnected and reconnected, but it '''will''' change when the game is re-launched.
---
---@return number id # The Joystick's unique identifier. Remains the same as long as the game is running.
---@return number instanceid # Unique instance identifier. Changes every time the Joystick is reconnected. nil if the Joystick is not connected.
function Joystick:getID() end

---
---Gets the name of the joystick.
---
---@return string name # The name of the joystick.
function Joystick:getName() end

---
---Gets the current vibration motor strengths on a Joystick with rumble support.
---
---@return number left # Current strength of the left vibration motor on the Joystick.
---@return number right # Current strength of the right vibration motor on the Joystick.
function Joystick:getVibration() end

---
---Gets whether the Joystick is connected.
---
---@return boolean connected # True if the Joystick is currently connected, false otherwise.
function Joystick:isConnected() end

---
---Checks if a button on the Joystick is pressed.
---
---LÖVE 0.9.0 had a bug which required the button indices passed to Joystick:isDown to be 0-based instead of 1-based, for example button 1 would be 0 for this function. It was fixed in 0.9.1.
---
---@param buttonN number # The index of a button to check.
---@return boolean anyDown # True if any supplied button is down, false if not.
function Joystick:isDown(buttonN) end

---
---Gets whether the Joystick is recognized as a gamepad. If this is the case, the Joystick's buttons and axes can be used in a standardized manner across different operating systems and joystick models via Joystick:getGamepadAxis, Joystick:isGamepadDown, love.gamepadpressed, and related functions.
---
---LÖVE automatically recognizes most popular controllers with a similar layout to the Xbox 360 controller as gamepads, but you can add more with love.joystick.setGamepadMapping.
---
---@return boolean isgamepad # True if the Joystick is recognized as a gamepad, false otherwise.
function Joystick:isGamepad() end

---
---Checks if a virtual gamepad button on the Joystick is pressed. If the Joystick is not recognized as a Gamepad or isn't connected, then this function will always return false.
---
---@param buttonN love.GamepadButton # The gamepad button to check.
---@return boolean anyDown # True if any supplied button is down, false if not.
function Joystick:isGamepadDown(buttonN) end

---
---Gets whether the Joystick supports vibration.
---
---@return boolean supported # True if rumble / force feedback vibration is supported on this Joystick, false if not.
function Joystick:isVibrationSupported() end

---
---Sets the vibration motor speeds on a Joystick with rumble support. Most common gamepads have this functionality, although not all drivers give proper support. Use Joystick:isVibrationSupported to check.
---
---@overload fun(self: love.Joystick):boolean
---@overload fun(self: love.Joystick, left: number, right: number, duration: number):boolean
---@param left number # Strength of the left vibration motor on the Joystick. Must be in the range of 1.
---@param right number # Strength of the right vibration motor on the Joystick. Must be in the range of 1.
---@return boolean success # True if the vibration was successfully applied, false if not.
function Joystick:setVibration(left, right) end

---
---Virtual gamepad axes.
---
---@alias love.GamepadAxis
---
---The x-axis of the left thumbstick.
---
---| '"leftx"'
---
---The y-axis of the left thumbstick.
---
---| '"lefty"'
---
---The x-axis of the right thumbstick.
---
---| '"rightx"'
---
---The y-axis of the right thumbstick.
---
---| '"righty"'
---
---Left analog trigger.
---
---| '"triggerleft"'
---
---Right analog trigger.
---
---| '"triggerright"'

---
---Virtual gamepad buttons.
---
---@alias love.GamepadButton
---
---Bottom face button (A).
---
---| '"a"'
---
---Right face button (B).
---
---| '"b"'
---
---Left face button (X).
---
---| '"x"'
---
---Top face button (Y).
---
---| '"y"'
---
---Back button.
---
---| '"back"'
---
---Guide button.
---
---| '"guide"'
---
---Start button.
---
---| '"start"'
---
---Left stick click button.
---
---| '"leftstick"'
---
---Right stick click button.
---
---| '"rightstick"'
---
---Left bumper.
---
---| '"leftshoulder"'
---
---Right bumper.
---
---| '"rightshoulder"'
---
---D-pad up.
---
---| '"dpup"'
---
---D-pad down.
---
---| '"dpdown"'
---
---D-pad left.
---
---| '"dpleft"'
---
---D-pad right.
---
---| '"dpright"'

---
---Joystick hat positions.
---
---@alias love.JoystickHat
---
---Centered
---
---| '"c"'
---
---Down
---
---| '"d"'
---
---Left
---
---| '"l"'
---
---Left+Down
---
---| '"ld"'
---
---Left+Up
---
---| '"lu"'
---
---Right
---
---| '"r"'
---
---Right+Down
---
---| '"rd"'
---
---Right+Up
---
---| '"ru"'
---
---Up
---
---| '"u"'

---
---Types of Joystick inputs.
---
---@alias love.JoystickInputType
---
---Analog axis.
---
---| '"axis"'
---
---Button.
---
---| '"button"'
---
---8-direction hat value.
---
---| '"hat"'