sfml.js 0.0.1-preview.40 → 0.0.1-preview.43
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 +57 -7
- package/binding.gyp +55 -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/render_window.d.ts +36 -10
- package/lib/render_window.js +76 -0
- 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 +6 -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/render_window.cc +177 -0
- package/src/render_window.h +45 -0
- package/src/render_window_async_display.cc +49 -0
- package/src/render_window_async_draw.cc +56 -0
- package/src/resizable_buffer.h +1 -0
- 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/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
|
+
}
|
package/lib/vector3.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const util = require('util');
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
Vector3I: _Vector3I,
|
|
7
|
+
Vector3F: _Vector3F,
|
|
8
|
+
Vector3U: _Vector3U,
|
|
9
|
+
} = require('../build/Release/binding.node');
|
|
10
|
+
const { validateTypeOf } = require('./common');
|
|
11
|
+
|
|
12
|
+
function createClass(name, BaseClz, checkRange, formatBaseValue = v => v) {
|
|
13
|
+
return class Vector3 extends BaseClz {
|
|
14
|
+
[util.inspect.custom](depth, opts) {
|
|
15
|
+
return `${name} ${util.inspect({
|
|
16
|
+
...this.toJSON(),
|
|
17
|
+
}, opts)}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
toJSON() {
|
|
21
|
+
return { x: this.x, y: this.y, z: this.z };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
constructor(xOrVector, y, z) {
|
|
25
|
+
if (arguments.length === 3) {
|
|
26
|
+
validateTypeOf(xOrVector, 'x', 'number');
|
|
27
|
+
validateTypeOf(y, 'y', 'number');
|
|
28
|
+
validateTypeOf(z, 'z', 'number');
|
|
29
|
+
|
|
30
|
+
checkRange(xOrVector);
|
|
31
|
+
checkRange(y);
|
|
32
|
+
checkRange(z);
|
|
33
|
+
|
|
34
|
+
xOrVector = formatBaseValue(xOrVector);
|
|
35
|
+
y = formatBaseValue(y);
|
|
36
|
+
z = formatBaseValue(z);
|
|
37
|
+
|
|
38
|
+
super(xOrVector, y, z);
|
|
39
|
+
} else if (arguments.length === 1) {
|
|
40
|
+
validateTypeOf(xOrVector, 'vector', BaseClz);
|
|
41
|
+
super(xOrVector);
|
|
42
|
+
} else if (arguments.length === 0) {
|
|
43
|
+
super();
|
|
44
|
+
} else {
|
|
45
|
+
throw new Error(`Invalid parameter count ${arguments.length}.`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get x() {
|
|
50
|
+
return super.x;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
set x(val) {
|
|
54
|
+
validateTypeOf(val, 'x', 'number');
|
|
55
|
+
checkRange(val);
|
|
56
|
+
super.x = formatBaseValue(val);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
get y() {
|
|
60
|
+
return super.y;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
set y(val) {
|
|
64
|
+
validateTypeOf(val, 'y', 'number');
|
|
65
|
+
checkRange(val);
|
|
66
|
+
super.y = formatBaseValue(val);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
get z() {
|
|
70
|
+
return super.z;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
set z(val) {
|
|
74
|
+
validateTypeOf(val, 'z', 'number');
|
|
75
|
+
checkRange(val);
|
|
76
|
+
super.z = formatBaseValue(val);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static subtract(a, b) {
|
|
80
|
+
if (!(a instanceof Vector3) || !(b instanceof Vector3)) {
|
|
81
|
+
throw new Error('Invalid parameter type.');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return BaseClz.subtract(a, b);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
static add(a, b) {
|
|
88
|
+
if (!(a instanceof Vector3) || !(b instanceof Vector3)) {
|
|
89
|
+
throw new Error('Invalid parameter type.');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return BaseClz.add(a, b);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
static multiply(a, b) {
|
|
96
|
+
if (!(a instanceof Vector3)) {
|
|
97
|
+
throw new Error('Invalid left parameter type.');
|
|
98
|
+
}
|
|
99
|
+
validateTypeOf(b, 'b', 'number');
|
|
100
|
+
checkRange(b);
|
|
101
|
+
|
|
102
|
+
return BaseClz.multiply(a, formatBaseValue(b));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
static div(a, b) {
|
|
106
|
+
if (!(a instanceof Vector3)) {
|
|
107
|
+
throw new Error('Invalid left parameter type.');
|
|
108
|
+
}
|
|
109
|
+
validateTypeOf(b, 'b', 'number');
|
|
110
|
+
checkRange(b);
|
|
111
|
+
|
|
112
|
+
return BaseClz.div(a, formatBaseValue(b));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
static equals(a, b) {
|
|
116
|
+
if (!(a instanceof Vector3) || !(b instanceof Vector3)) {
|
|
117
|
+
throw new Error('Invalid parameter type.');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return BaseClz.equals(a, b);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
static notEequals(a, b) {
|
|
124
|
+
if (!(a instanceof Vector3) || !(b instanceof Vector3)) {
|
|
125
|
+
throw new Error('Invalid parameter type.');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return BaseClz.notEequals(a, b);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const Vector3I = createClass(
|
|
134
|
+
'Vector3I',
|
|
135
|
+
_Vector3I,
|
|
136
|
+
() => true,
|
|
137
|
+
v => parseInt(v));
|
|
138
|
+
_Vector3I.setRealConstructor((...args) => new Vector3I(...args));
|
|
139
|
+
|
|
140
|
+
const Vector3U = createClass(
|
|
141
|
+
'Vector3U',
|
|
142
|
+
_Vector3U,
|
|
143
|
+
v => {
|
|
144
|
+
if (v < 0) {
|
|
145
|
+
throw new Error('Value should greater than or equal to 0.');
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
v => parseInt(v));
|
|
149
|
+
_Vector3U.setRealConstructor((...args) => new Vector3U(...args));
|
|
150
|
+
|
|
151
|
+
const Vector3F = createClass('Vector3F', _Vector3F, () => true);
|
|
152
|
+
_Vector3F.setRealConstructor((...args) => new Vector3F(...args));
|
|
153
|
+
|
|
154
|
+
module.exports = { Vector3I, Vector3U, Vector3F };
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sfml.js",
|
|
3
|
-
"version": "0.0.1-preview.
|
|
3
|
+
"version": "0.0.1-preview.43",
|
|
4
4
|
"description": "SFML's Node.js binding.",
|
|
5
5
|
"main": "lib/sfml.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build-dummy-debug": "node-gyp rebuild --debug && mv build/Debug build/Release",
|
|
8
8
|
"generate_compile_commands": "node-gyp -- configure -f=gyp.generator.compile_commands_json.py && mv Release/compile_commands.json compile_commands.json && rm -rf Release && rm -rf Debug",
|
|
9
9
|
"clang-format": "./tools/clang_format.js --style=file -i ./src/*.cc ./src/*.h ./src/drawable/*.cc ./src/drawable/*.h ./src/sound/*.cc ./src/sound/*.h ./src/workers/*.h",
|
|
10
|
+
"postinstall": "rm -f package-lock.json",
|
|
10
11
|
"preinstall": "node tools/symlinks.js",
|
|
11
|
-
"cpplint": "./third_party/cpplint/cpplint.py src/**/*",
|
|
12
|
+
"cpplint": "./third_party/cpplint/cpplint.py src/*.* src/**/*",
|
|
12
13
|
"jslint": "./node_modules/.bin/eslint ./**/*.js",
|
|
13
14
|
"install": "node-gyp rebuild"
|
|
14
15
|
},
|
|
@@ -30,11 +31,14 @@
|
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@types/node": "^16.11.6",
|
|
32
33
|
"@typescript-eslint/eslint-plugin": "^5.4.0",
|
|
34
|
+
"all-contributors-cli": "^6.20.0",
|
|
33
35
|
"eslint": "^7.0.0",
|
|
34
36
|
"eslint-config-egg": "^9.0.0",
|
|
35
37
|
"eslint-plugin-import": "^2.25.2",
|
|
36
38
|
"eslint-plugin-jsdoc": "^37.0.3",
|
|
37
39
|
"eslint-plugin-node": "^11.1.0",
|
|
40
|
+
"typedoc": "^0.20.14",
|
|
41
|
+
"typedoc-deno-theme": "^1.3.3",
|
|
38
42
|
"typescript": "~4.0.0"
|
|
39
43
|
},
|
|
40
44
|
"files": [
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#include <map>
|
|
2
|
+
#include <string>
|
|
3
|
+
|
|
4
|
+
namespace node_sfml {
|
|
5
|
+
namespace gen {
|
|
6
|
+
|
|
7
|
+
std::map<int, std::string> joystick_axis_itoa;
|
|
8
|
+
std::map<std::string, int> joystick_axis_atoi;
|
|
9
|
+
|
|
10
|
+
void InitJoystickAxis() {
|
|
11
|
+
joystick_axis_itoa[0] = "X";
|
|
12
|
+
joystick_axis_atoi["X"] = 0;
|
|
13
|
+
joystick_axis_itoa[1] = "Y";
|
|
14
|
+
joystick_axis_atoi["Y"] = 1;
|
|
15
|
+
joystick_axis_itoa[2] = "Z";
|
|
16
|
+
joystick_axis_atoi["Z"] = 2;
|
|
17
|
+
joystick_axis_itoa[3] = "R";
|
|
18
|
+
joystick_axis_atoi["R"] = 3;
|
|
19
|
+
joystick_axis_itoa[4] = "U";
|
|
20
|
+
joystick_axis_atoi["U"] = 4;
|
|
21
|
+
joystick_axis_itoa[5] = "V";
|
|
22
|
+
joystick_axis_atoi["V"] = 5;
|
|
23
|
+
joystick_axis_itoa[6] = "PovX";
|
|
24
|
+
joystick_axis_atoi["PovX"] = 6;
|
|
25
|
+
joystick_axis_itoa[7] = "PovY";
|
|
26
|
+
joystick_axis_atoi["PovY"] = 7;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
} // namespace gen
|
|
30
|
+
} // namespace node_sfml
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#include <map>
|
|
2
|
+
#include <string>
|
|
3
|
+
|
|
4
|
+
namespace node_sfml {
|
|
5
|
+
namespace gen {
|
|
6
|
+
|
|
7
|
+
std::map<int, std::string> sensor_type_itoa;
|
|
8
|
+
std::map<std::string, int> sensor_type_atoi;
|
|
9
|
+
|
|
10
|
+
void InitSensorType() {
|
|
11
|
+
sensor_type_itoa[0] = "Accelerometer";
|
|
12
|
+
sensor_type_atoi["Accelerometer"] = 0;
|
|
13
|
+
sensor_type_itoa[1] = "Gyroscope";
|
|
14
|
+
sensor_type_atoi["Gyroscope"] = 1;
|
|
15
|
+
sensor_type_itoa[2] = "Magnetometer";
|
|
16
|
+
sensor_type_atoi["Magnetometer"] = 2;
|
|
17
|
+
sensor_type_itoa[3] = "Gravity";
|
|
18
|
+
sensor_type_atoi["Gravity"] = 3;
|
|
19
|
+
sensor_type_itoa[4] = "UserAcceleration";
|
|
20
|
+
sensor_type_atoi["UserAcceleration"] = 4;
|
|
21
|
+
sensor_type_itoa[5] = "Orientation";
|
|
22
|
+
sensor_type_atoi["Orientation"] = 5;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
} // namespace gen
|
|
26
|
+
} // namespace node_sfml
|
package/src/joystick.cc
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#include "joystick.h"
|
|
2
|
+
|
|
3
|
+
namespace node_sfml {
|
|
4
|
+
namespace gen {
|
|
5
|
+
extern void InitJoystickAxis();
|
|
6
|
+
} // namespace gen
|
|
7
|
+
|
|
8
|
+
namespace joystick {
|
|
9
|
+
|
|
10
|
+
using std::map;
|
|
11
|
+
using std::string;
|
|
12
|
+
using v8::Local;
|
|
13
|
+
using v8::MaybeLocal;
|
|
14
|
+
using v8::Object;
|
|
15
|
+
using v8::String;
|
|
16
|
+
using v8::Value;
|
|
17
|
+
|
|
18
|
+
NAN_MODULE_INIT(Init) {
|
|
19
|
+
gen::InitJoystickAxis();
|
|
20
|
+
|
|
21
|
+
Nan::SetMethod(target, "joystickIsConnected", IsConnected);
|
|
22
|
+
Nan::SetMethod(target, "joystickGetButtonCount", GetButtonCount);
|
|
23
|
+
Nan::SetMethod(target, "joystickHasAxis", HasAxis);
|
|
24
|
+
Nan::SetMethod(target, "joystickIsButtonPressed", IsButtonPressed);
|
|
25
|
+
Nan::SetMethod(target, "joystickGetAxisPosition", GetAxisPosition);
|
|
26
|
+
Nan::SetMethod(target, "joystickGetIdentification", GetIdentification);
|
|
27
|
+
Nan::SetMethod(target, "joystickUpdate", Update);
|
|
28
|
+
|
|
29
|
+
Local<Object> axis = Nan::New<Object>();
|
|
30
|
+
for (auto it = gen::joystick_axis_atoi.begin();
|
|
31
|
+
it != gen::joystick_axis_atoi.end();
|
|
32
|
+
it++) {
|
|
33
|
+
Nan::Set(axis,
|
|
34
|
+
Nan::New<String>(it->first).ToLocalChecked(),
|
|
35
|
+
Nan::New(it->second));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
Nan::Set(target, Nan::New<String>("joystickAxis").ToLocalChecked(), axis);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
NAN_METHOD(IsConnected) {
|
|
42
|
+
if (info.Length() != 1) {
|
|
43
|
+
Nan::ThrowError("Invalid arguments count.");
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
sf::Uint32 joystick_id =
|
|
48
|
+
Nan::To<sf::Uint32>(info[0].As<v8::Uint32>()).FromJust();
|
|
49
|
+
info.GetReturnValue().Set(sf::Joystick::isConnected(joystick_id));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
NAN_METHOD(GetButtonCount) {
|
|
53
|
+
if (info.Length() != 1) {
|
|
54
|
+
Nan::ThrowError("Invalid arguments count.");
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
sf::Uint32 joystick_id =
|
|
59
|
+
Nan::To<sf::Uint32>(info[0].As<v8::Uint32>()).FromJust();
|
|
60
|
+
info.GetReturnValue().Set(sf::Joystick::getButtonCount(joystick_id));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
NAN_METHOD(HasAxis) {
|
|
64
|
+
if (info.Length() != 2) {
|
|
65
|
+
Nan::ThrowError("Invalid arguments count.");
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
sf::Uint32 joystick_id =
|
|
70
|
+
Nan::To<sf::Uint32>(info[0].As<v8::Uint32>()).FromJust();
|
|
71
|
+
sf::Joystick::Axis axis = static_cast<sf::Joystick::Axis>(
|
|
72
|
+
Nan::To<sf::Int32>(info[1].As<v8::Int32>()).FromJust());
|
|
73
|
+
info.GetReturnValue().Set(sf::Joystick::hasAxis(joystick_id, axis));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
NAN_METHOD(IsButtonPressed) {
|
|
77
|
+
if (info.Length() != 2) {
|
|
78
|
+
Nan::ThrowError("Invalid arguments count.");
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
sf::Uint32 joystick_id =
|
|
83
|
+
Nan::To<sf::Uint32>(info[0].As<v8::Uint32>()).FromJust();
|
|
84
|
+
sf::Uint32 button = Nan::To<sf::Uint32>(info[0].As<v8::Uint32>()).FromJust();
|
|
85
|
+
info.GetReturnValue().Set(sf::Joystick::isButtonPressed(joystick_id, button));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
NAN_METHOD(GetAxisPosition) {
|
|
89
|
+
if (info.Length() != 2) {
|
|
90
|
+
Nan::ThrowError("Invalid arguments count.");
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
sf::Uint32 joystick_id =
|
|
95
|
+
Nan::To<sf::Uint32>(info[0].As<v8::Uint32>()).FromJust();
|
|
96
|
+
sf::Joystick::Axis axis = static_cast<sf::Joystick::Axis>(
|
|
97
|
+
Nan::To<sf::Int32>(info[1].As<v8::Int32>()).FromJust());
|
|
98
|
+
info.GetReturnValue().Set(sf::Joystick::getAxisPosition(joystick_id, axis));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
NAN_METHOD(GetIdentification) {
|
|
102
|
+
if (info.Length() != 1) {
|
|
103
|
+
Nan::ThrowError("Invalid arguments count.");
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
sf::Uint32 joystick_id =
|
|
108
|
+
Nan::To<sf::Uint32>(info[0].As<v8::Uint32>()).FromJust();
|
|
109
|
+
sf::Joystick::Identification identification =
|
|
110
|
+
sf::Joystick::getIdentification(joystick_id);
|
|
111
|
+
|
|
112
|
+
std::basic_string<sf::Uint16> name = identification.name.toUtf16();
|
|
113
|
+
Local<String> v8_name =
|
|
114
|
+
Nan::New<String>(name.c_str(), name.size()).ToLocalChecked();
|
|
115
|
+
|
|
116
|
+
Local<Object> ret = Nan::New<Object>();
|
|
117
|
+
Nan::Set(ret, Nan::New<String>("name").ToLocalChecked(), v8_name);
|
|
118
|
+
Nan::Set(ret,
|
|
119
|
+
Nan::New<String>("vendorId").ToLocalChecked(),
|
|
120
|
+
Nan::New(identification.vendorId));
|
|
121
|
+
Nan::Set(ret,
|
|
122
|
+
Nan::New<String>("productId").ToLocalChecked(),
|
|
123
|
+
Nan::New(identification.productId));
|
|
124
|
+
info.GetReturnValue().Set(ret);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
NAN_METHOD(Update) {
|
|
128
|
+
sf::Joystick::update();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
} // namespace joystick
|
|
132
|
+
} // namespace node_sfml
|
package/src/joystick.h
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#ifndef SRC_JOYSTICK_H_
|
|
2
|
+
#define SRC_JOYSTICK_H_
|
|
3
|
+
|
|
4
|
+
#include <nan.h>
|
|
5
|
+
|
|
6
|
+
#include <map>
|
|
7
|
+
#include <string>
|
|
8
|
+
|
|
9
|
+
#include <SFML/Window/Joystick.hpp>
|
|
10
|
+
|
|
11
|
+
namespace node_sfml {
|
|
12
|
+
namespace gen {
|
|
13
|
+
extern std::map<int, std::string> joystick_axis_itoa;
|
|
14
|
+
extern std::map<std::string, int> joystick_axis_atoi;
|
|
15
|
+
} // namespace gen
|
|
16
|
+
|
|
17
|
+
namespace joystick {
|
|
18
|
+
|
|
19
|
+
NAN_MODULE_INIT(Init);
|
|
20
|
+
|
|
21
|
+
NAN_METHOD(IsConnected);
|
|
22
|
+
NAN_METHOD(GetButtonCount);
|
|
23
|
+
NAN_METHOD(HasAxis);
|
|
24
|
+
NAN_METHOD(IsButtonPressed);
|
|
25
|
+
NAN_METHOD(GetAxisPosition);
|
|
26
|
+
NAN_METHOD(GetIdentification);
|
|
27
|
+
NAN_METHOD(Update);
|
|
28
|
+
|
|
29
|
+
} // namespace joystick
|
|
30
|
+
} // namespace node_sfml
|
|
31
|
+
|
|
32
|
+
#endif // SRC_JOYSTICK_H_
|
package/src/poll_event.cc
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
#include <map>
|
|
2
2
|
|
|
3
|
+
#include "joystick.h"
|
|
3
4
|
#include "keyboard.h"
|
|
4
5
|
#include "mouse.h"
|
|
5
6
|
#include "poll_event.h"
|
|
7
|
+
#include "sensor.h"
|
|
6
8
|
|
|
7
9
|
namespace node_sfml {
|
|
8
10
|
namespace poll_event {
|
|
@@ -225,7 +227,78 @@ MaybeLocal<Object> EventToV8Object(Isolate* isolate, const sf::Event& event) {
|
|
|
225
227
|
break;
|
|
226
228
|
}
|
|
227
229
|
|
|
228
|
-
|
|
230
|
+
case sf::Event::JoystickButtonPressed:
|
|
231
|
+
case sf::Event::JoystickButtonReleased: {
|
|
232
|
+
Local<Object> joystick_button = Nan::New<Object>();
|
|
233
|
+
Nan::Set(joystick_button,
|
|
234
|
+
GetCachedColumn(isolate, "joystickId"),
|
|
235
|
+
Nan::New(event.joystickButton.joystickId));
|
|
236
|
+
Nan::Set(joystick_button,
|
|
237
|
+
GetCachedColumn(isolate, "button"),
|
|
238
|
+
Nan::New(event.joystickButton.button));
|
|
239
|
+
Nan::Set(
|
|
240
|
+
ret, GetCachedColumn(isolate, "joystickButton"), joystick_button);
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
case sf::Event::JoystickConnected:
|
|
245
|
+
case sf::Event::JoystickDisconnected: {
|
|
246
|
+
Local<Object> joystick_connect = Nan::New<Object>();
|
|
247
|
+
Nan::Set(joystick_connect,
|
|
248
|
+
GetCachedColumn(isolate, "joystickId"),
|
|
249
|
+
Nan::New(event.joystickConnect.joystickId));
|
|
250
|
+
Nan::Set(
|
|
251
|
+
ret, GetCachedColumn(isolate, "joystickConnect"), joystick_connect);
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
case sf::Event::JoystickMoved: {
|
|
256
|
+
Local<Object> joystick_move = Nan::New<Object>();
|
|
257
|
+
Nan::Set(joystick_move,
|
|
258
|
+
GetCachedColumn(isolate, "joystickId"),
|
|
259
|
+
Nan::New(event.joystickMove.joystickId));
|
|
260
|
+
Nan::Set(joystick_move,
|
|
261
|
+
GetCachedColumn(isolate, "axis"),
|
|
262
|
+
Nan::New(event.joystickMove.axis));
|
|
263
|
+
Nan::Set(joystick_move,
|
|
264
|
+
GetCachedColumn(isolate, "axisStr"),
|
|
265
|
+
Nan::New(gen::joystick_axis_itoa[event.joystickMove.axis])
|
|
266
|
+
.ToLocalChecked());
|
|
267
|
+
Nan::Set(joystick_move,
|
|
268
|
+
GetCachedColumn(isolate, "position"),
|
|
269
|
+
Nan::New(event.joystickMove.position));
|
|
270
|
+
Nan::Set(ret, GetCachedColumn(isolate, "joystickMove"), joystick_move);
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
case sf::Event::TouchBegan:
|
|
275
|
+
case sf::Event::TouchMoved:
|
|
276
|
+
case sf::Event::TouchEnded: {
|
|
277
|
+
Local<Object> touch = Nan::New<Object>();
|
|
278
|
+
Nan::Set(touch,
|
|
279
|
+
GetCachedColumn(isolate, "finger"),
|
|
280
|
+
Nan::New(event.touch.finger));
|
|
281
|
+
Nan::Set(touch, GetCachedColumn(isolate, "x"), Nan::New(event.touch.x));
|
|
282
|
+
Nan::Set(touch, GetCachedColumn(isolate, "y"), Nan::New(event.touch.y));
|
|
283
|
+
Nan::Set(ret, GetCachedColumn(isolate, "touch"), touch);
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
case sf::Event::SensorChanged: {
|
|
288
|
+
Local<Object> sensor = Nan::New<Object>();
|
|
289
|
+
Nan::Set(sensor,
|
|
290
|
+
GetCachedColumn(isolate, "type"),
|
|
291
|
+
Nan::New(event.sensor.type));
|
|
292
|
+
Nan::Set(
|
|
293
|
+
sensor,
|
|
294
|
+
GetCachedColumn(isolate, "typeStr"),
|
|
295
|
+
Nan::New(gen::sensor_type_itoa[event.sensor.type]).ToLocalChecked());
|
|
296
|
+
Nan::Set(sensor, GetCachedColumn(isolate, "x"), Nan::New(event.sensor.x));
|
|
297
|
+
Nan::Set(sensor, GetCachedColumn(isolate, "y"), Nan::New(event.sensor.x));
|
|
298
|
+
Nan::Set(sensor, GetCachedColumn(isolate, "z"), Nan::New(event.sensor.x));
|
|
299
|
+
Nan::Set(ret, GetCachedColumn(isolate, "sensor"), sensor);
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
229
302
|
|
|
230
303
|
default:
|
|
231
304
|
break;
|