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 CHANGED
@@ -1,13 +1,63 @@
1
- # Node SFML
1
+ <p align="center">
2
+ <img src="https://github.com/XadillaX/node-sfml/blob/main/assets/sfml.js.png?raw=true" />
3
+ </p>
2
4
 
3
- ![](https://www.sfml-dev.org/images/logo.png)
5
+ <p align="center">
6
+ Node.js binding for <a href="https://www.sfml-dev.org/">SFML</a> - a Simple and Fast cross-platform Multimedia Library.
7
+ </p>
4
8
 
5
- A cross-platform SFML's Node.js binding.
6
-
7
- > Under developing.
9
+ <p align="center">
10
+ <a href="https://www.npmjs.org/package/sfml.js">
11
+ <img src="http://img.shields.io/npm/v/sfml.js.svg?style=for-the-badge&colorA=FF7800&colorB=CC5600&label=NPM" />
12
+ </a>
13
+ <a href="https://www.npmjs.org/package/sfml.js">
14
+ <img src="http://img.shields.io/npm/dm/sfml.js.svg?style=for-the-badge&colorA=5DDB61&colorB=4BC74F&label=DOWNLOADS" />
15
+ </a>
16
+ <!-- [![License](https://img.shields.io/npm/l/sfml.js.svg?style=flat)](https://www.npmjs.org/package/sfml.js) -->
17
+ <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
18
+ <a href="#contributors-"><img src="https://img.shields.io/badge/2-ALL%20CONTRIBUTORS?style=for-the-badge&colorA=FF69b4&colorB=cc47a4&label=ALL%20CONTRIBUTORS" />
19
+ <!-- ALL-CONTRIBUTORS-BADGE:END -->
20
+ <a href="https://github.com/XadillaX/node-sfml">
21
+ <img src="https://img.shields.io/github/stars/XadillaX/node-sfml.svg?style=for-the-badge&colorA=FBBD30&colorB=F2AA08&label=STAR" />
22
+ </a>
23
+ </p>
8
24
 
9
25
  ## Installation
10
26
 
11
27
  ```bash
12
- $ node-gyp rebuild
13
- ```
28
+ $ npm install --save sfml.js
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ - Refer to TypeDoc: [https://sfml.js.org/](https://sfml.js.org/);
34
+ - 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);
35
+ - And SFML's official documentation: [https://www.sfml-dev.org/documentation/2.5.1/](https://www.sfml-dev.org/documentation/2.5.1/).
36
+
37
+ ## Examples
38
+
39
+ + [node-sfml-demos](https://github.com/XadillaX/node-sfml-demos): Several small example games;
40
+ + [play-nes](https://github.com/XadillaX/play-nes): A cross-platform desktop NES emulator powered by OpenGL in Node.js.
41
+
42
+ > PR is welcomed. You can add your own sfml.js example.
43
+
44
+ ## Contributors ✨
45
+
46
+ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
47
+
48
+ <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
49
+ <!-- prettier-ignore-start -->
50
+ <!-- markdownlint-disable -->
51
+ <table>
52
+ <tr>
53
+ <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>
54
+ <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>
55
+ </tr>
56
+ </table>
57
+
58
+ <!-- markdownlint-restore -->
59
+ <!-- prettier-ignore-end -->
60
+
61
+ <!-- ALL-CONTRIBUTORS-LIST:END -->
62
+
63
+ 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": [
@@ -55,6 +97,9 @@
55
97
  "../third_party/sfml/platform/linux/lib/libsfml-window.so",
56
98
  "../third_party/sfml/platform/linux/lib/libsfml-network.so",
57
99
  "../third_party/sfml/platform/linux/lib/libsfml-graphics.so"
100
+ ],
101
+ "ldflags": [
102
+ "-Wl,-rpath='$$ORIGIN/../../third_party/sfml/platform/linux/lib'"
58
103
  ]
59
104
  }],
60
105
  ["OS==\"win\"", {
@@ -112,14 +157,20 @@
112
157
  "./src/color.cc",
113
158
  "./src/font.cc",
114
159
  "./src/image.cc",
160
+ "./src/joystick.cc",
115
161
  "./src/keyboard.cc",
116
162
  "./src/mouse.cc",
117
163
  "./src/poll_event.cc",
118
164
  "./src/rect.cc",
119
165
  "./src/render_window.cc",
166
+ "./src/render_window_async_display.cc",
167
+ "./src/render_window_async_draw.cc",
168
+ "./src/sensor.cc",
169
+ "./src/touch.cc",
120
170
  "./src/texture.cc",
121
171
  "./src/time.cc",
122
172
  "./src/vector2.cc",
173
+ "./src/vector3.cc",
123
174
  "./src/vertex.cc",
124
175
  "./src/video_mode.cc",
125
176
 
@@ -132,8 +183,10 @@
132
183
  "./src/drawable/text.cc",
133
184
  "./src/drawable/vertex_array.cc",
134
185
 
186
+ "./src/gen/joystick_axis.cc",
135
187
  "./src/gen/keycode.cc",
136
188
  "./src/gen/mouse_button.cc",
189
+ "./src/gen/sensor_type.cc",
137
190
 
138
191
  "./src/sound/music.cc",
139
192
  "./src/sound/sound.cc",
@@ -142,6 +195,8 @@
142
195
  ],
143
196
  "dependencies": [
144
197
  "keycode.cc",
198
+ "joystick_axis.cc",
199
+ "sensor_type.cc",
145
200
  "mouse_button.cc"
146
201
  ]
147
202
  }]
@@ -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;
@@ -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
@@ -104,3 +104,4 @@ export enum Keys {
104
104
  Y = 24,
105
105
  Z = 25,
106
106
  }
107
+ export type KeysStr = keyof typeof Keys;
package/lib/mouse.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { PointType, Vector2I } from './vector2';
2
- import * as RenderWindow from './render_window';
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;
@@ -1,7 +1,14 @@
1
+ import { Keys, KeysStr } from './keyboard';
2
+ import * as Joystick from './joystick';
3
+ import * as Sensor from './sensor';
4
+
1
5
  interface OtherEvent {
2
- type: 'Closed' | 'LostFocus' | 'GainedFocus' | 'MouseLeft' | 'JoystickButtonPressed' | 'JoystickButtonReleased' |
3
- 'JoystickMoved' | 'JoystickConnected' | 'JoystickDisconnected' | 'TouchBegan' | 'TouchMoved' | 'TouchEnded' |
4
- 'SensorChanged';
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: number;
19
- codeStr: string;
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: string;
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: string;
76
+ wheelStr: 'VerticalWheel' | 'HorizontalWheel';
70
77
  };
71
78
  }
72
79
 
73
- export type Event = OtherEvent | SizeEvent | KeyEvent | TextEvent | MouseMoveEvent | MouseButtonEvent |
74
- MouseWheelEvent | MouseWheelScrollEvent;
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
@@ -1,6 +1,6 @@
1
1
  import { PointType, Vector2F, Vector2I } from './vector2';
2
2
 
3
- class Rect<Vector_T> {
3
+ declare class Rect<Vector_T> {
4
4
  constructor(left: number, top: number, width: number, height: number);
5
5
  constructor(position: PointType<Vector2I>, size: PointType<Vector2I>);
6
6
 
@@ -4,30 +4,56 @@ import { Event } from './poll_event';
4
4
  import { Image } from './image';
5
5
  import { VideoMode } from './video_mode';
6
6
  import { Vector2U } from './vector2';
7
+ import { Vector2I } from '..';
8
+
9
+ type ContextSettings = {
10
+ depthBits: number;
11
+ stencilBits: number;
12
+ antialiasingLevel: number;
13
+ majorVersion: number;
14
+ minorVersion: number;
15
+ attributeFlags: number;
16
+ sRgbCapable: boolean;
17
+ };
7
18
 
8
19
  export class RenderWindow {
9
- constructor(videoMode?: VideoMode, title?: string, style?: RenderWindow.Style);
20
+ constructor(
21
+ videoMode?: VideoMode,
22
+ title?: string,
23
+ style?: RenderWindow.Style
24
+ );
10
25
 
26
+ create(windowHandle: number): void;
27
+ create(videoMode: VideoMode, title: string, style?: RenderWindow.Style): void;
11
28
  capture(): Image;
12
29
  clear(color: number | Color): void;
13
30
  close(): void;
14
31
  draw(content: Drawable): void;
32
+ drawAsync(content: Drawable): Promise<void>;
15
33
  display(): void;
34
+ displayAsync(): Promise<void>;
35
+
36
+ getPosition(): Vector2I;
37
+ getSettings(): ContextSettings;
38
+ getSize(): Vector2U;
39
+
40
+ hasFocus(): boolean;
16
41
  isOpen(): boolean;
17
42
 
18
43
  pollEvent(): Event;
44
+ requestFocus(): void;
19
45
 
20
- setVisible(visible: boolean): void;
21
- setVerticalSyncEnabled(enabled: boolean): void;
46
+ setActive(active?: boolean): void;
47
+ setFramerateLimit(limit: number): void;
48
+ setIcon(width: number, height: number, icon: Buffer): void;
49
+ setJoystickThreshold(threshold: number): void;
50
+ setKeyRepeatEnabled(enabled: boolean): void;
22
51
  setMouseCursorVisible(visible: boolean): void;
23
52
  setMouseCursorGrabbed(grabbed: boolean): void;
24
- setKeyRepeatEnabled(enabled: boolean): void;
25
- setFramerateLimit(limit: number): void;
26
- setActive(active?: boolean): void;
27
-
28
- getSize(): Vector2U;
29
-
30
- hasFocus(): boolean;
53
+ setPosition(position: Vector2I): void;
54
+ setTitle(title: string): void;
55
+ setVisible(visible: boolean): void;
56
+ setVerticalSyncEnabled(enabled: boolean): void;
31
57
  }
32
58
  export namespace RenderWindow {
33
59
  enum Style {
@@ -7,6 +7,7 @@ const {
7
7
  } = require('../build/Release/binding.node');
8
8
  const { validateTypeOf } = require('./common');
9
9
  const { VideoMode } = require('./video_mode');
10
+ const { Vector2I } = require('./vector2');
10
11
 
11
12
  const DRAW_DRAWABLE = Symbol('RenderWindow::drawDrawable');
12
13
  const RAW_RENDER_WINDOW = Symbol('RenderWindow::rawRenderWindow');
@@ -28,6 +29,23 @@ class RenderWindow {
28
29
  }
29
30
  }
30
31
 
32
+ create(videoMode, title, style) {
33
+ if (Number.isInteger(videoMode) && videoMode >= 0) {
34
+ this[RAW_RENDER_WINDOW].create(videoMode);
35
+ } else {
36
+ validateTypeOf(videoMode, 'videoMode', VideoMode, false);
37
+ validateTypeOf(title, 'title', 'string', false);
38
+ validateTypeOf(style, 'style', 'number', true);
39
+
40
+ videoMode = videoMode[VideoMode.RAW_VIDEO_MODE];
41
+ if (style === undefined) {
42
+ this[RAW_RENDER_WINDOW].create(videoMode, title);
43
+ } else {
44
+ this[RAW_RENDER_WINDOW].create(videoMode, title, style);
45
+ }
46
+ }
47
+ }
48
+
31
49
  capture() {
32
50
  return this[RAW_RENDER_WINDOW].capture();
33
51
  }
@@ -54,10 +72,37 @@ class RenderWindow {
54
72
  this[RAW_RENDER_WINDOW].drawDrawable(content._raw());
55
73
  }
56
74
 
75
+ drawAsync(content) {
76
+ if (content instanceof Drawable) {
77
+ return new Promise((resolve, reject) => {
78
+ this[RAW_RENDER_WINDOW].drawDrawableAsync((err, res) => {
79
+ err ? reject(new Error(err)) : resolve(res);
80
+ }, content._raw());
81
+ });
82
+ }
83
+ return Promise.reject(new Error('Expected Drawable Instance'));
84
+ }
85
+
57
86
  display() {
58
87
  this[RAW_RENDER_WINDOW].display();
59
88
  }
60
89
 
90
+ displayAsync() {
91
+ return new Promise((resolve, reject) => {
92
+ this[RAW_RENDER_WINDOW].displayAsync((err, res) => {
93
+ err ? reject(new Error(err)) : resolve(res);
94
+ });
95
+ });
96
+ }
97
+
98
+ getPosition() {
99
+ return this[RAW_RENDER_WINDOW].getPosition();
100
+ }
101
+
102
+ getSettings() {
103
+ return this[RAW_RENDER_WINDOW].getSettings();
104
+ }
105
+
61
106
  isOpen() {
62
107
  return this[RAW_RENDER_WINDOW].isOpen();
63
108
  }
@@ -66,6 +111,10 @@ class RenderWindow {
66
111
  return this[RAW_RENDER_WINDOW].pollEvent();
67
112
  }
68
113
 
114
+ requestFocus() {
115
+ this[RAW_RENDER_WINDOW].requestFocus();
116
+ }
117
+
69
118
  setVisible(visible) {
70
119
  validateTypeOf(visible, 'visible', 'boolean');
71
120
  this[RAW_RENDER_WINDOW].setVisible(visible);
@@ -106,6 +155,33 @@ class RenderWindow {
106
155
  this[RAW_RENDER_WINDOW].setActive(active);
107
156
  }
108
157
 
158
+ setIcon(width, height, icon) {
159
+ validateTypeOf(width, 'width', 'number', false);
160
+ validateTypeOf(height, 'height', 'number', false);
161
+ validateTypeOf(icon, 'icon', Buffer, false);
162
+
163
+ if (icon.byteLength !== 4 * width * height) {
164
+ throw new Error('Invalid icon size, must be 4 * width * height');
165
+ }
166
+
167
+ this[RAW_RENDER_WINDOW].setIcon(width, height, icon);
168
+ }
169
+
170
+ setJoystickThreshold(threshold) {
171
+ validateTypeOf(threshold, 'threshold', 'number', false);
172
+ this[RAW_RENDER_WINDOW].setJoystickThreshold(threshold);
173
+ }
174
+
175
+ setPosition(position) {
176
+ validateTypeOf(position, 'position', Vector2I, false);
177
+ this[RAW_RENDER_WINDOW].setPosition(position);
178
+ }
179
+
180
+ setTitle(title) {
181
+ validateTypeOf(title, 'title', 'string', false);
182
+ this[RAW_RENDER_WINDOW].setTitle(title);
183
+ }
184
+
109
185
  getSize() {
110
186
  return this[RAW_RENDER_WINDOW].getSize();
111
187
  }
@@ -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;