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/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,6 +1,6 @@
1
1
  {
2
2
  "name": "sfml.js",
3
- "version": "0.0.1-preview.41",
3
+ "version": "0.0.1-preview.42",
4
4
  "description": "SFML's Node.js binding.",
5
5
  "main": "lib/sfml.js",
6
6
  "scripts": {
@@ -8,7 +8,7 @@
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
10
  "preinstall": "node tools/symlinks.js",
11
- "cpplint": "./third_party/cpplint/cpplint.py src/**/*",
11
+ "cpplint": "./third_party/cpplint/cpplint.py src/*.* src/**/*",
12
12
  "jslint": "./node_modules/.bin/eslint ./**/*.js",
13
13
  "install": "node-gyp rebuild"
14
14
  },
@@ -30,6 +30,7 @@
30
30
  "devDependencies": {
31
31
  "@types/node": "^16.11.6",
32
32
  "@typescript-eslint/eslint-plugin": "^5.4.0",
33
+ "all-contributors-cli": "^6.20.0",
33
34
  "eslint": "^7.0.0",
34
35
  "eslint-config-egg": "^9.0.0",
35
36
  "eslint-plugin-import": "^2.25.2",
@@ -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
@@ -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
- // TODO(XadillaX): Joystick / Touch / Sensor events.
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;
package/src/sensor.cc ADDED
@@ -0,0 +1,82 @@
1
+ #include "sensor.h"
2
+ #include "vector3-inl.h"
3
+
4
+ namespace node_sfml {
5
+ namespace gen {
6
+ extern void InitSensorType();
7
+ } // namespace gen
8
+
9
+ namespace sensor {
10
+
11
+ using std::map;
12
+ using std::string;
13
+ using v8::Local;
14
+ using v8::MaybeLocal;
15
+ using v8::Object;
16
+ using v8::String;
17
+ using v8::Value;
18
+
19
+ NAN_MODULE_INIT(Init) {
20
+ gen::InitSensorType();
21
+
22
+ Nan::SetMethod(target, "sensorIsAvailable", IsAvailable);
23
+ Nan::SetMethod(target, "sensorSetEnabled", SetEnabled);
24
+ Nan::SetMethod(target, "sensorGetValue", GetValue);
25
+
26
+ Local<Object> type = Nan::New<Object>();
27
+ for (auto it = gen::sensor_type_atoi.begin();
28
+ it != gen::sensor_type_atoi.end();
29
+ it++) {
30
+ Nan::Set(type,
31
+ Nan::New<String>(it->first).ToLocalChecked(),
32
+ Nan::New(it->second));
33
+ }
34
+
35
+ Nan::Set(target, Nan::New<String>("sensorType").ToLocalChecked(), type);
36
+ }
37
+
38
+ NAN_METHOD(IsAvailable) {
39
+ if (info.Length() != 1) {
40
+ Nan::ThrowError("Invalid arguments count.");
41
+ return;
42
+ }
43
+
44
+ sf::Sensor::Type sensor_type = static_cast<sf::Sensor::Type>(
45
+ Nan::To<sf::Uint32>(info[0].As<v8::Uint32>()).FromJust());
46
+ info.GetReturnValue().Set(sf::Sensor::isAvailable(sensor_type));
47
+ }
48
+
49
+ NAN_METHOD(SetEnabled) {
50
+ if (info.Length() != 2) {
51
+ Nan::ThrowError("Invalid arguments count.");
52
+ return;
53
+ }
54
+
55
+ sf::Sensor::Type sensor_type = static_cast<sf::Sensor::Type>(
56
+ Nan::To<sf::Uint32>(info[0].As<v8::Uint32>()).FromJust());
57
+ bool enabled = Nan::To<bool>(info[1].As<v8::Boolean>()).FromJust();
58
+ sf::Sensor::setEnabled(sensor_type, enabled);
59
+ }
60
+
61
+ NAN_METHOD(GetValue) {
62
+ if (info.Length() != 1) {
63
+ Nan::ThrowError("Invalid arguments count.");
64
+ return;
65
+ }
66
+
67
+ sf::Sensor::Type sensor_type = static_cast<sf::Sensor::Type>(
68
+ Nan::To<sf::Uint32>(info[0].As<v8::Uint32>()).FromJust());
69
+ sf::Vector3f value = sf::Sensor::getValue(sensor_type);
70
+
71
+ MaybeLocal<Value> maybe_temp;
72
+ Nan::TryCatch try_catch;
73
+ maybe_temp = vector3::Vector3F::NewRealInstance(info.GetIsolate(), value);
74
+ if (maybe_temp.IsEmpty()) {
75
+ try_catch.ReThrow();
76
+ return;
77
+ }
78
+ info.GetReturnValue().Set(maybe_temp.ToLocalChecked());
79
+ }
80
+
81
+ } // namespace sensor
82
+ } // namespace node_sfml
package/src/sensor.h ADDED
@@ -0,0 +1,28 @@
1
+ #ifndef SRC_SENSOR_H_
2
+ #define SRC_SENSOR_H_
3
+
4
+ #include <nan.h>
5
+
6
+ #include <map>
7
+ #include <string>
8
+
9
+ #include <SFML/Window/Sensor.hpp>
10
+
11
+ namespace node_sfml {
12
+ namespace gen {
13
+ extern std::map<int, std::string> sensor_type_itoa;
14
+ extern std::map<std::string, int> sensor_type_atoi;
15
+ } // namespace gen
16
+
17
+ namespace sensor {
18
+
19
+ NAN_MODULE_INIT(Init);
20
+
21
+ NAN_METHOD(IsAvailable);
22
+ NAN_METHOD(SetEnabled);
23
+ NAN_METHOD(GetValue);
24
+
25
+ } // namespace sensor
26
+ } // namespace node_sfml
27
+
28
+ #endif // SRC_SENSOR_H_
package/src/sfml.cc CHANGED
@@ -4,13 +4,17 @@
4
4
  #include "color.h"
5
5
  #include "font.h"
6
6
  #include "image.h"
7
+ #include "joystick.h"
7
8
  #include "keyboard.h"
8
9
  #include "mouse.h"
9
10
  #include "rect.h"
10
11
  #include "render_window.h"
12
+ #include "sensor.h"
11
13
  #include "texture.h"
12
14
  #include "time.h"
15
+ #include "touch.h"
13
16
  #include "vector2.h"
17
+ #include "vector3.h"
14
18
  #include "vertex.h"
15
19
  #include "video_mode.h"
16
20
 
@@ -31,6 +35,9 @@ namespace node_sfml {
31
35
  void Init(v8::Local<v8::Object> target) {
32
36
  keyboard::Init(target);
33
37
  mouse::Init(target);
38
+ joystick::Init(target);
39
+ sensor::Init(target);
40
+ touch::Init(target);
34
41
 
35
42
  clock::Clock::Init(target);
36
43
  color::Color::Init(target);
@@ -64,6 +71,11 @@ void Init(v8::Local<v8::Object> target) {
64
71
  vector2::Vector2U::Init(target);
65
72
  vector2::Vector2F::Init(target);
66
73
 
74
+ // vector3
75
+ vector3::Vector3I::Init(target);
76
+ vector3::Vector3U::Init(target);
77
+ vector3::Vector3F::Init(target);
78
+
67
79
  node::AddEnvironmentCleanupHook(
68
80
  target->GetIsolate(), sound::SoundSource::AtExit, nullptr);
69
81
  }
package/src/touch.cc ADDED
@@ -0,0 +1,54 @@
1
+ #include "touch.h"
2
+ #include "render_window.h"
3
+ #include "vector2-inl.h"
4
+
5
+ namespace node_sfml {
6
+ namespace touch {
7
+
8
+ using std::map;
9
+ using std::string;
10
+ using v8::Local;
11
+ using v8::MaybeLocal;
12
+ using v8::Object;
13
+ using v8::String;
14
+ using v8::Value;
15
+
16
+ NAN_MODULE_INIT(Init) {
17
+ Nan::SetMethod(target, "touchIsDown", IsDown);
18
+ Nan::SetMethod(target, "touchGetPosition", GetPosition);
19
+ }
20
+
21
+ NAN_METHOD(IsDown) {
22
+ sf::Uint32 finger = Nan::To<sf::Uint32>(info[0]).FromJust();
23
+
24
+ info.GetReturnValue().Set(sf::Touch::isDown(finger));
25
+ return;
26
+ }
27
+
28
+ NAN_METHOD(GetPosition) {
29
+ sf::Uint32 finger = Nan::To<sf::Uint32>(info[0]).FromJust();
30
+ sf::Vector2i pos;
31
+ if (info.Length() == 1) {
32
+ pos = sf::Touch::getPosition(finger);
33
+ } else {
34
+ Local<Object> window_object = info[1].As<Object>();
35
+ render_window::RenderWindow* render_window =
36
+ Nan::ObjectWrap::Unwrap<render_window::RenderWindow>(window_object);
37
+ sf::RenderWindow* window = render_window->window();
38
+
39
+ pos = sf::Touch::getPosition(finger, *window);
40
+ }
41
+
42
+ Nan::TryCatch try_catch;
43
+ MaybeLocal<Value> ret =
44
+ vector2::Vector2I::NewRealInstance(info.GetIsolate(), pos);
45
+ if (ret.IsEmpty()) {
46
+ try_catch.ReThrow();
47
+ return;
48
+ }
49
+
50
+ info.GetReturnValue().Set(ret.ToLocalChecked());
51
+ }
52
+
53
+ } // namespace touch
54
+ } // namespace node_sfml