This repository has been archived by the owner on May 18, 2023. It is now read-only.
forked from gowebapi/webapi
/
gamepad.go
314 lines (272 loc) · 7.47 KB
/
gamepad.go
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
// Code generated by webidl-bind. DO NOT EDIT.
// +build !js
package gamepad
import js "github.com/gowebapi/webapi/core/js"
import (
"github.com/gowebapi/webapi/dom/domcore"
"github.com/gowebapi/webapi/javascript"
)
// using following types:
// domcore.Event
// javascript.FrozenArray
// source idl files:
// gamepad.idl
// transform files:
// gamepad.go.md
// workaround for compiler error
func unused(value interface{}) {
// TODO remove this method
}
type Union struct {
Value js.Value
}
func (u *Union) JSValue() js.Value {
return u.Value
}
func UnionFromJS(value js.Value) *Union {
return &Union{Value: value}
}
// enum: GamepadMappingType
type GamepadMappingType int
const (
EmptyString0GamepadMappingType GamepadMappingType = iota
StandardGamepadMappingType
)
var gamepadMappingTypeToWasmTable = []string{
"", "standard",
}
var gamepadMappingTypeFromWasmTable = map[string]GamepadMappingType{
"": EmptyString0GamepadMappingType, "standard": StandardGamepadMappingType,
}
// JSValue is converting this enum into a javascript object
func (this *GamepadMappingType) JSValue() js.Value {
return js.ValueOf(this.Value())
}
// Value is converting this into javascript defined
// string value
func (this GamepadMappingType) Value() string {
idx := int(this)
if idx >= 0 && idx < len(gamepadMappingTypeToWasmTable) {
return gamepadMappingTypeToWasmTable[idx]
}
panic("unknown input value")
}
// GamepadMappingTypeFromJS is converting a javascript value into
// a GamepadMappingType enum value.
func GamepadMappingTypeFromJS(value js.Value) GamepadMappingType {
key := value.String()
conv, ok := gamepadMappingTypeFromWasmTable[key]
if !ok {
panic("unable to convert '" + key + "'")
}
return conv
}
// dictionary: GamepadEventInit
type GamepadEventInit struct {
Bubbles bool
Cancelable bool
Composed bool
Gamepad *Gamepad
}
// JSValue is allocating a new javasript object and copy
// all values
func (_this *GamepadEventInit) JSValue() js.Value {
out := js.Global().Get("Object").New()
value0 := _this.Bubbles
out.Set("bubbles", value0)
value1 := _this.Cancelable
out.Set("cancelable", value1)
value2 := _this.Composed
out.Set("composed", value2)
value3 := _this.Gamepad.JSValue()
out.Set("gamepad", value3)
return out
}
// GamepadEventInitFromJS is allocating a new
// GamepadEventInit object and copy all values from
// input javascript object
func GamepadEventInitFromJS(value js.Wrapper) *GamepadEventInit {
input := value.JSValue()
var out GamepadEventInit
var (
value0 bool // javascript: boolean {bubbles Bubbles bubbles}
value1 bool // javascript: boolean {cancelable Cancelable cancelable}
value2 bool // javascript: boolean {composed Composed composed}
value3 *Gamepad // javascript: Gamepad {gamepad Gamepad gamepad}
)
value0 = (input.Get("bubbles")).Bool()
out.Bubbles = value0
value1 = (input.Get("cancelable")).Bool()
out.Cancelable = value1
value2 = (input.Get("composed")).Bool()
out.Composed = value2
value3 = GamepadFromJS(input.Get("gamepad"))
out.Gamepad = value3
return &out
}
// class: Gamepad
type Gamepad struct {
// Value_JS holds a reference to a javascript value
Value_JS js.Value
}
func (_this *Gamepad) JSValue() js.Value {
return _this.Value_JS
}
// GamepadFromJS is casting a js.Wrapper into Gamepad.
func GamepadFromJS(value js.Wrapper) *Gamepad {
input := value.JSValue()
if typ := input.Type(); typ == js.TypeNull || typ == js.TypeUndefined {
return nil
}
ret := &Gamepad{}
ret.Value_JS = input
return ret
}
// Id returning attribute 'id' with
// type string (idl: DOMString).
func (_this *Gamepad) Id() string {
var ret string
value := _this.Value_JS.Get("id")
ret = (value).String()
return ret
}
// Index returning attribute 'index' with
// type int (idl: long).
func (_this *Gamepad) Index() int {
var ret int
value := _this.Value_JS.Get("index")
ret = (value).Int()
return ret
}
// Connected returning attribute 'connected' with
// type bool (idl: boolean).
func (_this *Gamepad) Connected() bool {
var ret bool
value := _this.Value_JS.Get("connected")
ret = (value).Bool()
return ret
}
// Timestamp returning attribute 'timestamp' with
// type float64 (idl: double).
func (_this *Gamepad) Timestamp() float64 {
var ret float64
value := _this.Value_JS.Get("timestamp")
ret = (value).Float()
return ret
}
// Mapping returning attribute 'mapping' with
// type GamepadMappingType (idl: GamepadMappingType).
func (_this *Gamepad) Mapping() GamepadMappingType {
var ret GamepadMappingType
value := _this.Value_JS.Get("mapping")
ret = GamepadMappingTypeFromJS(value)
return ret
}
// Axes returning attribute 'axes' with
// type javascript.FrozenArray (idl: FrozenArray).
func (_this *Gamepad) Axes() *javascript.FrozenArray {
var ret *javascript.FrozenArray
value := _this.Value_JS.Get("axes")
ret = javascript.FrozenArrayFromJS(value)
return ret
}
// Buttons returning attribute 'buttons' with
// type javascript.FrozenArray (idl: FrozenArray).
func (_this *Gamepad) Buttons() *javascript.FrozenArray {
var ret *javascript.FrozenArray
value := _this.Value_JS.Get("buttons")
ret = javascript.FrozenArrayFromJS(value)
return ret
}
// DisplayId returning attribute 'displayId' with
// type uint (idl: unsigned long).
func (_this *Gamepad) DisplayId() uint {
var ret uint
value := _this.Value_JS.Get("displayId")
ret = (uint)((value).Int())
return ret
}
// class: GamepadButton
type GamepadButton struct {
// Value_JS holds a reference to a javascript value
Value_JS js.Value
}
func (_this *GamepadButton) JSValue() js.Value {
return _this.Value_JS
}
// GamepadButtonFromJS is casting a js.Wrapper into GamepadButton.
func GamepadButtonFromJS(value js.Wrapper) *GamepadButton {
input := value.JSValue()
if typ := input.Type(); typ == js.TypeNull || typ == js.TypeUndefined {
return nil
}
ret := &GamepadButton{}
ret.Value_JS = input
return ret
}
// Pressed returning attribute 'pressed' with
// type bool (idl: boolean).
func (_this *GamepadButton) Pressed() bool {
var ret bool
value := _this.Value_JS.Get("pressed")
ret = (value).Bool()
return ret
}
// Touched returning attribute 'touched' with
// type bool (idl: boolean).
func (_this *GamepadButton) Touched() bool {
var ret bool
value := _this.Value_JS.Get("touched")
ret = (value).Bool()
return ret
}
// Value returning attribute 'value' with
// type float64 (idl: double).
func (_this *GamepadButton) Value() float64 {
var ret float64
value := _this.Value_JS.Get("value")
ret = (value).Float()
return ret
}
// class: GamepadEvent
type GamepadEvent struct {
domcore.Event
}
// GamepadEventFromJS is casting a js.Wrapper into GamepadEvent.
func GamepadEventFromJS(value js.Wrapper) *GamepadEvent {
input := value.JSValue()
if typ := input.Type(); typ == js.TypeNull || typ == js.TypeUndefined {
return nil
}
ret := &GamepadEvent{}
ret.Value_JS = input
return ret
}
func NewGamepadEvent(_type string, eventInitDict *GamepadEventInit) (_result *GamepadEvent) {
_klass := js.Global().Get("GamepadEvent")
var (
_args [2]interface{}
_end int
)
_p0 := _type
_args[0] = _p0
_end++
_p1 := eventInitDict.JSValue()
_args[1] = _p1
_end++
_returned := _klass.New(_args[0:_end]...)
var (
_converted *GamepadEvent // javascript: GamepadEvent _what_return_name
)
_converted = GamepadEventFromJS(_returned)
_result = _converted
return
}
// Gamepad returning attribute 'gamepad' with
// type Gamepad (idl: Gamepad).
func (_this *GamepadEvent) Gamepad() *Gamepad {
var ret *Gamepad
value := _this.Value_JS.Get("gamepad")
ret = GamepadFromJS(value)
return ret
}