sfml.js 0.0.1-preview.41 → 0.0.1-preview.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -5
- package/binding.gyp +50 -0
- package/lib/joystick.d.ts +21 -0
- package/lib/joystick.js +72 -0
- package/lib/keyboard.d.ts +1 -0
- package/lib/mouse.d.ts +1 -1
- package/lib/poll_event.d.ts +73 -9
- package/lib/rect.d.ts +1 -1
- package/lib/sensor.d.ts +12 -0
- package/lib/sensor.js +34 -0
- package/lib/sfml.d.ts +4 -0
- package/lib/sfml.js +4 -0
- package/lib/touch.d.ts +7 -0
- package/lib/touch.js +34 -0
- package/lib/vector3.d.ts +47 -0
- package/lib/vector3.js +154 -0
- package/package.json +3 -2
- package/src/gen/joystick_axis.cc +30 -0
- package/src/gen/sensor_type.cc +26 -0
- package/src/joystick.cc +132 -0
- package/src/joystick.h +32 -0
- package/src/poll_event.cc +74 -1
- package/src/sensor.cc +82 -0
- package/src/sensor.h +28 -0
- package/src/sfml.cc +12 -0
- package/src/touch.cc +54 -0
- package/src/touch.h +23 -0
- package/src/vector3-inl.h +200 -0
- package/src/vector3.cc +36 -0
- package/src/vector3.h +134 -0
- package/tools/joystick_axis.js +62 -0
- package/tools/keycode.js +5 -3
- package/tools/mouse_button.js +9 -5
- package/tools/sensor_type.js +62 -0
package/README.md
CHANGED
|
@@ -1,13 +1,52 @@
|
|
|
1
|
-
#
|
|
1
|
+
# sfml.js
|
|
2
|
+
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
3
|
+
[](#contributors-)
|
|
4
|
+
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
5
|
+
[](https://www.npmjs.org/package/sfml.js)
|
|
6
|
+
[](https://www.npmjs.org/package/sfml.js)
|
|
7
|
+
[](https://www.npmjs.org/package/sfml.js)
|
|
8
|
+
[](https://github.com/XadillaX/node-sfml)
|
|
2
9
|
|
|
3
10
|

|
|
4
11
|
|
|
5
12
|
A cross-platform SFML's Node.js binding.
|
|
6
13
|
|
|
7
|
-
> Under developing.
|
|
8
|
-
|
|
9
14
|
## Installation
|
|
10
15
|
|
|
11
16
|
```bash
|
|
12
|
-
$
|
|
13
|
-
```
|
|
17
|
+
$ npm install --save sfml.js
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
Refer to Typing Definitions: [https://github.com/XadillaX/node-sfml/blob/main/index.d.ts](https://github.com/XadillaX/node-sfml/blob/main/index.d.ts).
|
|
23
|
+
|
|
24
|
+
And SFML's official documentation: [https://www.sfml-dev.org/documentation/2.5.1/](https://www.sfml-dev.org/documentation/2.5.1/).
|
|
25
|
+
|
|
26
|
+
## Examples
|
|
27
|
+
|
|
28
|
+
+ [node-sfml-demos](https://github.com/XadillaX/node-sfml-demos): Several small example games;
|
|
29
|
+
+ [play-nes](https://github.com/XadillaX/play-nes): A cross-platform desktop NES emulator powered by OpenGL in Node.js.
|
|
30
|
+
|
|
31
|
+
> PR is welcomed. You can add your own sfml.js example.
|
|
32
|
+
|
|
33
|
+
## Contributors ✨
|
|
34
|
+
|
|
35
|
+
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
|
36
|
+
|
|
37
|
+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
|
38
|
+
<!-- prettier-ignore-start -->
|
|
39
|
+
<!-- markdownlint-disable -->
|
|
40
|
+
<table>
|
|
41
|
+
<tr>
|
|
42
|
+
<td align="center"><a href="https://xcoder.in/"><img src="https://avatars.githubusercontent.com/u/2842176?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Khaidi Chu</b></sub></a><br /><a href="#maintenance-XadillaX" title="Maintenance">🚧</a> <a href="https://github.com/XadillaX/node-sfml/commits?author=XadillaX" title="Code">💻</a></td>
|
|
43
|
+
<td align="center"><a href="https://pokemonworkshop.com/forum"><img src="https://avatars.githubusercontent.com/u/7335788?v=4?s=100" width="100px;" alt=""/><br /><sub><b>NuriYuri</b></sub></a><br /><a href="https://github.com/XadillaX/node-sfml/commits?author=NuriYuri" title="Code">💻</a></td>
|
|
44
|
+
</tr>
|
|
45
|
+
</table>
|
|
46
|
+
|
|
47
|
+
<!-- markdownlint-restore -->
|
|
48
|
+
<!-- prettier-ignore-end -->
|
|
49
|
+
|
|
50
|
+
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
51
|
+
|
|
52
|
+
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
|
package/binding.gyp
CHANGED
|
@@ -41,6 +41,48 @@
|
|
|
41
41
|
"./tools/keycode.js"
|
|
42
42
|
]
|
|
43
43
|
}]
|
|
44
|
+
}, {
|
|
45
|
+
"target_name": "joystick_axis.cc",
|
|
46
|
+
"type": "none",
|
|
47
|
+
"sources": [
|
|
48
|
+
"./third_party/sfml/include/SFML/Window/Joystick.hpp",
|
|
49
|
+
"./tools/joystick_axis.js"
|
|
50
|
+
],
|
|
51
|
+
"actions": [{
|
|
52
|
+
"action_name": "gen_joystick_axis",
|
|
53
|
+
"inputs": [
|
|
54
|
+
"./third_party/sfml/include/SFML/Window/Joystick.hpp",
|
|
55
|
+
"./tools/joystick_axis.js"
|
|
56
|
+
],
|
|
57
|
+
"outputs": [
|
|
58
|
+
"./src/gen/joystick_axis.cc"
|
|
59
|
+
],
|
|
60
|
+
"action": [
|
|
61
|
+
"node",
|
|
62
|
+
"./tools/joystick_axis.js"
|
|
63
|
+
]
|
|
64
|
+
}]
|
|
65
|
+
}, {
|
|
66
|
+
"target_name": "sensor_type.cc",
|
|
67
|
+
"type": "none",
|
|
68
|
+
"sources": [
|
|
69
|
+
"./third_party/sfml/include/SFML/Window/Sensor.hpp",
|
|
70
|
+
"./tools/sensor_type.js"
|
|
71
|
+
],
|
|
72
|
+
"actions": [{
|
|
73
|
+
"action_name": "gen_sensor_type",
|
|
74
|
+
"inputs": [
|
|
75
|
+
"./third_party/sfml/include/SFML/Window/Sensor.hpp",
|
|
76
|
+
"./tools/sensor_type.js"
|
|
77
|
+
],
|
|
78
|
+
"outputs": [
|
|
79
|
+
"./src/gen/sensor_type.cc"
|
|
80
|
+
],
|
|
81
|
+
"action": [
|
|
82
|
+
"node",
|
|
83
|
+
"./tools/sensor_type.js"
|
|
84
|
+
]
|
|
85
|
+
}]
|
|
44
86
|
}, {
|
|
45
87
|
"target_name": "binding",
|
|
46
88
|
"include_dirs": [
|
|
@@ -115,14 +157,18 @@
|
|
|
115
157
|
"./src/color.cc",
|
|
116
158
|
"./src/font.cc",
|
|
117
159
|
"./src/image.cc",
|
|
160
|
+
"./src/joystick.cc",
|
|
118
161
|
"./src/keyboard.cc",
|
|
119
162
|
"./src/mouse.cc",
|
|
120
163
|
"./src/poll_event.cc",
|
|
121
164
|
"./src/rect.cc",
|
|
122
165
|
"./src/render_window.cc",
|
|
166
|
+
"./src/sensor.cc",
|
|
167
|
+
"./src/touch.cc",
|
|
123
168
|
"./src/texture.cc",
|
|
124
169
|
"./src/time.cc",
|
|
125
170
|
"./src/vector2.cc",
|
|
171
|
+
"./src/vector3.cc",
|
|
126
172
|
"./src/vertex.cc",
|
|
127
173
|
"./src/video_mode.cc",
|
|
128
174
|
|
|
@@ -135,8 +181,10 @@
|
|
|
135
181
|
"./src/drawable/text.cc",
|
|
136
182
|
"./src/drawable/vertex_array.cc",
|
|
137
183
|
|
|
184
|
+
"./src/gen/joystick_axis.cc",
|
|
138
185
|
"./src/gen/keycode.cc",
|
|
139
186
|
"./src/gen/mouse_button.cc",
|
|
187
|
+
"./src/gen/sensor_type.cc",
|
|
140
188
|
|
|
141
189
|
"./src/sound/music.cc",
|
|
142
190
|
"./src/sound/sound.cc",
|
|
@@ -145,6 +193,8 @@
|
|
|
145
193
|
],
|
|
146
194
|
"dependencies": [
|
|
147
195
|
"keycode.cc",
|
|
196
|
+
"joystick_axis.cc",
|
|
197
|
+
"sensor_type.cc",
|
|
148
198
|
"mouse_button.cc"
|
|
149
199
|
]
|
|
150
200
|
}]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export enum Axis {
|
|
2
|
+
X = 0, Y = 1, Z = 2, R = 3,
|
|
3
|
+
U = 4, V = 5, PovX = 6, PovY = 7
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export type AxisStr = keyof typeof Axis;
|
|
7
|
+
type UnsignedInteger = number;
|
|
8
|
+
|
|
9
|
+
type Identification = {
|
|
10
|
+
name: string;
|
|
11
|
+
vendorId: number;
|
|
12
|
+
productId: number;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function isConnected(joystickId: UnsignedInteger): boolean;
|
|
16
|
+
export function getButtonCount(joystickId: UnsignedInteger): number;
|
|
17
|
+
export function hasAxis(joystickId: UnsignedInteger, axis: Axis): boolean;
|
|
18
|
+
export function isButtonPressed(joystickId: UnsignedInteger, button: UnsignedInteger): boolean;
|
|
19
|
+
export function getAxisPosition(joystickId: UnsignedInteger, axis: Axis): number;
|
|
20
|
+
export function getIdentification(joystickId: UnsignedInteger): Identification;
|
|
21
|
+
export function update(): void;
|
package/lib/joystick.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
joystickIsConnected: _isConnected,
|
|
5
|
+
joystickGetButtonCount: _getButtonCount,
|
|
6
|
+
joystickHasAxis: _hasAxis,
|
|
7
|
+
joystickIsJoystickButtonPressed: _isButtonPressed,
|
|
8
|
+
joystickGetAxisPosition: _getAxisPosition,
|
|
9
|
+
joystickGetIdentification: _getIdentification,
|
|
10
|
+
joystickUpdate: update,
|
|
11
|
+
joystickAxis: Axis,
|
|
12
|
+
} = require('../build/Release/binding.node');
|
|
13
|
+
|
|
14
|
+
const AxisValues = Object.values(Axis);
|
|
15
|
+
|
|
16
|
+
const validateJoystickId = joystickId => {
|
|
17
|
+
if (!Number.isInteger(joystickId) || Math.sign(joystickId) < 0) {
|
|
18
|
+
throw new TypeError(
|
|
19
|
+
`Unexpected value ${joystickId} for joystickId, expected usigned integer.`
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const validateButton = button => {
|
|
25
|
+
if (!Number.isInteger(button) || Math.sign(button) < 0) {
|
|
26
|
+
throw new TypeError(
|
|
27
|
+
`Unexpected value ${button} for button, expected usigned integer.`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const validateAxis = axis => {
|
|
33
|
+
if (!AxisValues.includes(axis)) {
|
|
34
|
+
throw new TypeError('Invalid Axis value.');
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
module.exports.isConnected = joystickId => {
|
|
39
|
+
validateJoystickId(joystickId);
|
|
40
|
+
return _isConnected(joystickId);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
module.exports.getButtonCount = joystickId => {
|
|
44
|
+
validateJoystickId(joystickId);
|
|
45
|
+
return _getButtonCount(joystickId);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
module.exports.hasAxis = (joystickId, axis) => {
|
|
49
|
+
validateJoystickId(joystickId);
|
|
50
|
+
validateAxis(axis);
|
|
51
|
+
return _hasAxis(joystickId, axis);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
module.exports.isButtonPressed = (joystickId, button) => {
|
|
55
|
+
validateJoystickId(joystickId);
|
|
56
|
+
validateButton(button);
|
|
57
|
+
return _isButtonPressed(joystickId, button);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
module.exports.getAxisPosition = (joystickId, axis) => {
|
|
61
|
+
validateJoystickId(joystickId);
|
|
62
|
+
validateAxis(axis);
|
|
63
|
+
return _getAxisPosition(joystickId, axis);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
module.exports.getIdentification = joystickId => {
|
|
67
|
+
validateJoystickId(joystickId);
|
|
68
|
+
return _getIdentification(joystickId);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
module.exports.update = update;
|
|
72
|
+
module.exports.Axis = Axis;
|
package/lib/keyboard.d.ts
CHANGED
package/lib/mouse.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PointType, Vector2I } from './vector2';
|
|
2
|
-
import
|
|
2
|
+
import { RenderWindow } from './render_window';
|
|
3
3
|
|
|
4
4
|
export function isButtonPressed(button: number | string): boolean;
|
|
5
5
|
export function getPosition(window?: RenderWindow): Vector2I;
|
package/lib/poll_event.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
import { Sensor } from './sensor';
|
|
2
|
+
import { Joystick } from './joystick';
|
|
3
|
+
import { Keys, KeysStr } from './keyboard';
|
|
4
|
+
|
|
1
5
|
interface OtherEvent {
|
|
2
|
-
type:
|
|
3
|
-
|
|
4
|
-
|
|
6
|
+
type:
|
|
7
|
+
| 'Closed'
|
|
8
|
+
| 'LostFocus'
|
|
9
|
+
| 'GainedFocus'
|
|
10
|
+
| 'MouseLeft'
|
|
11
|
+
| 'MouseEntered';
|
|
5
12
|
}
|
|
6
13
|
|
|
7
14
|
interface SizeEvent {
|
|
@@ -15,8 +22,8 @@ interface SizeEvent {
|
|
|
15
22
|
interface KeyEvent {
|
|
16
23
|
type: 'KeyPressed' | 'KeyReleased';
|
|
17
24
|
key: {
|
|
18
|
-
code:
|
|
19
|
-
codeStr:
|
|
25
|
+
code: Keys;
|
|
26
|
+
codeStr: KeysStr;
|
|
20
27
|
alt: boolean;
|
|
21
28
|
shift: boolean;
|
|
22
29
|
control: boolean;
|
|
@@ -46,7 +53,7 @@ interface MouseButtonEvent {
|
|
|
46
53
|
x: number;
|
|
47
54
|
y: number;
|
|
48
55
|
button: number;
|
|
49
|
-
buttonStr:
|
|
56
|
+
buttonStr: 'Left' | 'Right' | 'Middle' | 'XButton1' | 'XButton2';
|
|
50
57
|
};
|
|
51
58
|
}
|
|
52
59
|
|
|
@@ -66,9 +73,66 @@ interface MouseWheelScrollEvent {
|
|
|
66
73
|
y: number;
|
|
67
74
|
delta: number;
|
|
68
75
|
wheel: number;
|
|
69
|
-
wheelStr:
|
|
76
|
+
wheelStr: 'VerticalWheel' | 'HorizontalWheel';
|
|
70
77
|
};
|
|
71
78
|
}
|
|
72
79
|
|
|
73
|
-
|
|
74
|
-
|
|
80
|
+
interface JoystickButtonEvent {
|
|
81
|
+
type: 'JoystickButtonPressed' | 'JoystickButtonReleased';
|
|
82
|
+
joystickButton: {
|
|
83
|
+
joystickId: number;
|
|
84
|
+
button: number;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
interface JoystickConnectEvent {
|
|
89
|
+
type: 'JoystickConnected' | 'JoystickDisconnected';
|
|
90
|
+
joystickConnect: {
|
|
91
|
+
joystickId: number;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
interface JoystickMoveEvent {
|
|
96
|
+
type: 'JoystickMoved',
|
|
97
|
+
joystickMove: {
|
|
98
|
+
joystickId: number;
|
|
99
|
+
axis: Joystick.Axis;
|
|
100
|
+
axisStr: Joystick.AxisStr;
|
|
101
|
+
position: number;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
interface TouchEvent {
|
|
106
|
+
type: 'TouchBegan' | 'TouchMoved' | 'TouchEnded';
|
|
107
|
+
touch: {
|
|
108
|
+
finger: number;
|
|
109
|
+
x: number;
|
|
110
|
+
y: number;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
interface SensorEvent {
|
|
115
|
+
type: 'SensorChanged',
|
|
116
|
+
sensor: {
|
|
117
|
+
type: Sensor.Type;
|
|
118
|
+
typeStr: Sensor.TypeStr;
|
|
119
|
+
x: number;
|
|
120
|
+
y: number;
|
|
121
|
+
z: number;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export type Event =
|
|
126
|
+
| OtherEvent
|
|
127
|
+
| SizeEvent
|
|
128
|
+
| KeyEvent
|
|
129
|
+
| TextEvent
|
|
130
|
+
| MouseMoveEvent
|
|
131
|
+
| MouseButtonEvent
|
|
132
|
+
| MouseWheelEvent
|
|
133
|
+
| MouseWheelScrollEvent
|
|
134
|
+
| JoystickButtonEvent
|
|
135
|
+
| JoystickConnectEvent
|
|
136
|
+
| JoystickMoveEvent
|
|
137
|
+
| TouchEvent
|
|
138
|
+
| SensorEvent;
|
package/lib/rect.d.ts
CHANGED
package/lib/sensor.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Vector3F } from './vector3';
|
|
2
|
+
|
|
3
|
+
export enum Type {
|
|
4
|
+
Accelerometer = 0, Gyroscope = 1, Magnetometer = 2, Gravity = 3,
|
|
5
|
+
UserAcceleration = 4, Orientation = 5
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type TypeStr = keyof typeof Type;
|
|
9
|
+
|
|
10
|
+
export function isAvailable(sensor: Type): boolean;
|
|
11
|
+
export function setEnabled(sensor: Type, enabled: boolean): void;
|
|
12
|
+
export function getValue(sensor: Type): Vector3F;
|
package/lib/sensor.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
sensorIsAvailable: _isAvailable,
|
|
5
|
+
sensorSetEnabled: _setEnabled,
|
|
6
|
+
sensorGetValue: _getValue,
|
|
7
|
+
sensorType: Type,
|
|
8
|
+
} = require('../build/Release/binding.node');
|
|
9
|
+
|
|
10
|
+
const SensorTypeValues = Object.values(Type);
|
|
11
|
+
|
|
12
|
+
const validateSensorType = sensor => {
|
|
13
|
+
if (!SensorTypeValues.includes(sensor)) {
|
|
14
|
+
throw new TypeError('Invalid Sensor::Type value.');
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
module.exports.isAvailable = sensor => {
|
|
19
|
+
validateSensorType(sensor);
|
|
20
|
+
return _isAvailable(sensor);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
module.exports.setEnabled = (sensor, enabled) => {
|
|
24
|
+
validateSensorType(sensor);
|
|
25
|
+
_setEnabled(sensor, !!enabled);
|
|
26
|
+
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
module.exports.getValue = sensor => {
|
|
30
|
+
validateSensorType(sensor);
|
|
31
|
+
return _getValue(sensor);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
module.exports.Type = Type;
|
package/lib/sfml.d.ts
CHANGED
|
@@ -4,6 +4,9 @@ export * from './font';
|
|
|
4
4
|
export * from './image';
|
|
5
5
|
export * as Keyboard from './keyboard';
|
|
6
6
|
export * as Mouse from './mouse';
|
|
7
|
+
export * as Joystick from './joystick';
|
|
8
|
+
export * as Sensor from './sensor';
|
|
9
|
+
export * as Touch from './touch';
|
|
7
10
|
export * from './rect';
|
|
8
11
|
export * from './render_window';
|
|
9
12
|
export * from './texture';
|
|
@@ -11,6 +14,7 @@ export * from './texture';
|
|
|
11
14
|
export * as Time from './time';
|
|
12
15
|
|
|
13
16
|
export * from './vector2';
|
|
17
|
+
export * from './vector3';
|
|
14
18
|
export * from './vertex';
|
|
15
19
|
export * from './video_mode';
|
|
16
20
|
|
package/lib/sfml.js
CHANGED
|
@@ -7,6 +7,9 @@ module.exports = {
|
|
|
7
7
|
...require('./image'),
|
|
8
8
|
Keyboard: require('./keyboard'),
|
|
9
9
|
Mouse: require('./mouse'),
|
|
10
|
+
Joystick: require('./joystick'),
|
|
11
|
+
Sensor: require('./sensor'),
|
|
12
|
+
Touch: require('./touch'),
|
|
10
13
|
...require('./render_window'),
|
|
11
14
|
...require('./texture'),
|
|
12
15
|
...require('./vertex'),
|
|
@@ -16,6 +19,7 @@ module.exports = {
|
|
|
16
19
|
|
|
17
20
|
...require('./rect'),
|
|
18
21
|
...require('./vector2'),
|
|
22
|
+
...require('./vector3'),
|
|
19
23
|
|
|
20
24
|
// drawable
|
|
21
25
|
...require('./drawable/circle_shape'),
|
package/lib/touch.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Vector2I } from './vector2';
|
|
2
|
+
import { RenderWindow } from './render_window';
|
|
3
|
+
|
|
4
|
+
type UnsignedInteger = number;
|
|
5
|
+
|
|
6
|
+
export function isDown(finger: UnsignedInteger): boolean;
|
|
7
|
+
export function getPosition(finger: UnsignedInteger, window?: RenderWindow): Vector2I;
|
package/lib/touch.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
touchGetPosition: _getPosition,
|
|
5
|
+
touchIsDown: _isDown,
|
|
6
|
+
} = require('../build/Release/binding.node');
|
|
7
|
+
const { RenderWindow } = require('./render_window');
|
|
8
|
+
|
|
9
|
+
const validateFinger = finger => {
|
|
10
|
+
if (!Number.isInteger(finger) || Math.sign(finger) < 0) {
|
|
11
|
+
throw new TypeError(
|
|
12
|
+
`Unexpected value ${finger} for finger, expected usigned integer.`
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
exports.isDown = finger => {
|
|
18
|
+
validateFinger(finger);
|
|
19
|
+
return _isDown(finger);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.getPosition = function getPosition(finger, window) {
|
|
23
|
+
validateFinger(finger);
|
|
24
|
+
|
|
25
|
+
if (arguments.length === 1) {
|
|
26
|
+
return _getPosition(finger);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!(window instanceof RenderWindow)) {
|
|
30
|
+
throw new TypeError('Parameter is not a RenderWindow instance.');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return _getPosition(finger, window[RenderWindow.RAW_RENDER_WINDOW]);
|
|
34
|
+
};
|
package/lib/vector3.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export class Vector3I {
|
|
2
|
+
constructor(x: number, y: number, z: number);
|
|
3
|
+
constructor(vec: Vector3I);
|
|
4
|
+
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
|
|
8
|
+
static add(a: Vector3I, b: Vector3I): Vector3I;
|
|
9
|
+
static subtract(a: Vector3I, b: Vector3I): Vector3I;
|
|
10
|
+
static multiply(a: Vector3I, b: number): Vector3I;
|
|
11
|
+
static div(a: Vector3I, b: number): Vector3I;
|
|
12
|
+
|
|
13
|
+
static equals(a: Vector3I, b: Vector3I): boolean;
|
|
14
|
+
static notEequals(a: Vector3I, b: Vector3I): boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class Vector3U {
|
|
18
|
+
constructor(x: number, y: number, z: number);
|
|
19
|
+
constructor(vec: Vector3U);
|
|
20
|
+
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
|
|
24
|
+
static add(a: Vector3U, b: Vector3U): Vector3U;
|
|
25
|
+
static subtract(a: Vector3U, b: Vector3U): Vector3U;
|
|
26
|
+
static multiply(a: Vector3U, b: number): Vector3U;
|
|
27
|
+
static div(a: Vector3U, b: number): Vector3U;
|
|
28
|
+
|
|
29
|
+
static equals(a: Vector3U, b: Vector3U): boolean;
|
|
30
|
+
static notEequals(a: Vector3U, b: Vector3U): boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class Vector3F {
|
|
34
|
+
constructor(x: number, y: number, z: number);
|
|
35
|
+
constructor(vec: Vector3F);
|
|
36
|
+
|
|
37
|
+
x: number;
|
|
38
|
+
y: number;
|
|
39
|
+
|
|
40
|
+
static add(a: Vector3F, b: Vector3F): Vector3F;
|
|
41
|
+
static subtract(a: Vector3F, b: Vector3F): Vector3F;
|
|
42
|
+
static multiply(a: Vector3F, b: number): Vector3F;
|
|
43
|
+
static div(a: Vector3F, b: number): Vector3F;
|
|
44
|
+
|
|
45
|
+
static equals(a: Vector3F, b: Vector3F): boolean;
|
|
46
|
+
static notEequals(a: Vector3F, b: Vector3F): boolean;
|
|
47
|
+
}
|