sfml.js 0.0.1-preview.31 → 0.0.1-preview.35

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.
@@ -10,6 +10,8 @@ type SpritePluginPackage = Transformable & PluginPackageTexture & PluginPackageB
10
10
  export interface Sprite extends SpritePluginPackage {}
11
11
  export class Sprite extends Drawable {
12
12
  constructor(texture?: Texture, rect?: IntRect);
13
+ constructor(srcSprite: Sprite);
14
+
13
15
  setColor(color: number | Color): void;
14
16
  getColor(): Color;
15
17
  }
@@ -9,19 +9,24 @@ const { Texture } = require('../texture');
9
9
  const { validateTypeOf } = require('../common');
10
10
 
11
11
  class Sprite extends Drawable {
12
- constructor(texture, rectangle) {
12
+ constructor(textureOrSprite, rectangle) {
13
13
  if (arguments.length === 0) {
14
14
  super('Sprite');
15
15
  this[setPluginPackageTexture.TEXTURE] = null;
16
16
  } else if (arguments.length === 1) {
17
- validateTypeOf(texture, 'texture', Texture);
18
- super('Sprite', texture);
19
- this[setPluginPackageTexture.TEXTURE] = texture;
17
+ validateTypeOf(textureOrSprite, 'textureOrSprite', [ Texture, Sprite ]);
18
+ if (textureOrSprite instanceof Texture) {
19
+ super('Sprite', textureOrSprite);
20
+ this[setPluginPackageTexture.TEXTURE] = textureOrSprite;
21
+ } else {
22
+ super('Sprite', 'Sprite', textureOrSprite._raw());
23
+ this[setPluginPackageTexture.TEXTURE] = this._raw().getTexture();
24
+ }
20
25
  } else {
21
- validateTypeOf(texture, 'texture', Texture);
26
+ validateTypeOf(textureOrSprite, 'texture', Texture);
22
27
  validateTypeOf(rectangle, 'rectangle', IntRect);
23
- super('Sprite', texture, rectangle);
24
- this[setPluginPackageTexture.TEXTURE] = texture;
28
+ super('Sprite', textureOrSprite, rectangle);
29
+ this[setPluginPackageTexture.TEXTURE] = textureOrSprite;
25
30
  }
26
31
 
27
32
  delete this.setPointCount;
package/lib/font.d.ts CHANGED
@@ -14,6 +14,7 @@ export class Font {
14
14
  constructor();
15
15
  loadFromFileSync(filename: string): boolean;
16
16
  loadFromFile(filename: string): Promise<void>;
17
+ loadFromMemory(buff: Buffer): boolean;
17
18
  getInfo(): Info;
18
19
  getGlyph(codePoint: number, characterSize: number, bold: boolean, outlineThickness?: number): Glyph;
19
20
  getKerning(first: number, second: number, characterSize: number): number;
package/lib/font.js CHANGED
@@ -39,6 +39,11 @@ class Font extends _Font {
39
39
  return promise;
40
40
  }
41
41
 
42
+ loadFromMemory(buff) {
43
+ validateTypeOf(buff, 'buff', Buffer);
44
+ return super.loadFromMemory(buff);
45
+ }
46
+
42
47
  loadFromFileSync(filename) {
43
48
  validateTypeOf(filename, 'filename', 'string');
44
49
  filename = path.resolve(process.cwd(), filename);
package/lib/keyboard.d.ts CHANGED
@@ -1,2 +1,106 @@
1
1
  export function isKeyPressed(key: number | string): boolean;
2
2
  export function setVirtualKeyboardVisible(visible: boolean): void;
3
+ export enum Keys {
4
+ A = 0,
5
+ Add = 67,
6
+ B = 1,
7
+ Backslash = 53,
8
+ Backspace = 59,
9
+ C = 2,
10
+ Comma = 49,
11
+ D = 3,
12
+ Delete = 66,
13
+ Divide = 70,
14
+ Down = 74,
15
+ E = 4,
16
+ End = 63,
17
+ Enter = 58,
18
+ Equal = 55,
19
+ Escape = 36,
20
+ F = 5,
21
+ F1 = 85,
22
+ F10 = 94,
23
+ F11 = 95,
24
+ F12 = 96,
25
+ F13 = 97,
26
+ F14 = 98,
27
+ F15 = 99,
28
+ F2 = 86,
29
+ F3 = 87,
30
+ F4 = 88,
31
+ F5 = 89,
32
+ F6 = 90,
33
+ F7 = 91,
34
+ F8 = 92,
35
+ F9 = 93,
36
+ G = 6,
37
+ H = 7,
38
+ Home = 64,
39
+ Hyphen = 56,
40
+ I = 8,
41
+ Insert = 65,
42
+ J = 9,
43
+ K = 10,
44
+ L = 11,
45
+ LAlt = 39,
46
+ LBracket = 46,
47
+ LControl = 37,
48
+ LShift = 38,
49
+ LSystem = 40,
50
+ Left = 71,
51
+ M = 12,
52
+ Menu = 45,
53
+ Multiply = 69,
54
+ N = 13,
55
+ Num0 = 26,
56
+ Num1 = 27,
57
+ Num2 = 28,
58
+ Num3 = 29,
59
+ Num4 = 30,
60
+ Num5 = 31,
61
+ Num6 = 32,
62
+ Num7 = 33,
63
+ Num8 = 34,
64
+ Num9 = 35,
65
+ Numpad0 = 75,
66
+ Numpad1 = 76,
67
+ Numpad2 = 77,
68
+ Numpad3 = 78,
69
+ Numpad4 = 79,
70
+ Numpad5 = 80,
71
+ Numpad6 = 81,
72
+ Numpad7 = 82,
73
+ Numpad8 = 83,
74
+ Numpad9 = 84,
75
+ O = 14,
76
+ P = 15,
77
+ PageDown = 62,
78
+ PageUp = 61,
79
+ Pause = 100,
80
+ Period = 50,
81
+ Q = 16,
82
+ Quote = 51,
83
+ R = 17,
84
+ RAlt = 43,
85
+ RBracket = 47,
86
+ RControl = 41,
87
+ RShift = 42,
88
+ RSystem = 44,
89
+ Right = 72,
90
+ S = 18,
91
+ Semicolon = 48,
92
+ Slash = 52,
93
+ Space = 57,
94
+ Subtract = 68,
95
+ T = 19,
96
+ Tab = 60,
97
+ Tilde = 54,
98
+ U = 20,
99
+ Unknown = -1,
100
+ Up = 73,
101
+ V = 21,
102
+ W = 22,
103
+ X = 23,
104
+ Y = 24,
105
+ Z = 25,
106
+ }
package/lib/keyboard.js CHANGED
@@ -3,6 +3,7 @@
3
3
  const {
4
4
  isKeyPressed: _isKeyPressed,
5
5
  setVirtualKeyboardVisible: _setVirtualKeyboardVisible,
6
+ Keys,
6
7
  } = require('../build/Release/binding.node');
7
8
 
8
9
  exports.setVirtualKeyboardVisible = function setVirtualKeyboardVisible(visible) {
@@ -10,3 +11,5 @@ exports.setVirtualKeyboardVisible = function setVirtualKeyboardVisible(visible)
10
11
  };
11
12
 
12
13
  exports.isKeyPressed = _isKeyPressed;
14
+
15
+ exports.Keys = Keys;
@@ -26,6 +26,8 @@ export class RenderWindow {
26
26
  setActive(active?: boolean): void;
27
27
 
28
28
  getSize(): Vector2U;
29
+
30
+ hasFocus(): boolean;
29
31
  }
30
32
  export namespace RenderWindow {
31
33
  enum Style {
@@ -107,6 +107,10 @@ class RenderWindow {
107
107
  getSize() {
108
108
  return this[RAW_RENDER_WINDOW].getSize();
109
109
  }
110
+
111
+ hasFocus() {
112
+ return this[RAW_RENDER_WINDOW].hasFocus();
113
+ }
110
114
  }
111
115
 
112
116
  RenderWindow.Style = _RenderWindow.Style;
@@ -4,6 +4,7 @@ export class Music extends SoundSource {
4
4
  constructor();
5
5
  openFromFileSync(filename: string): boolean;
6
6
  openFromFile(filename: string): Promise<void>;
7
+ openFromMemory(buff: Buffer): boolean;
7
8
 
8
9
  setLoop(loop: boolean): void;
9
10
  getLoop(): boolean;
@@ -53,6 +53,12 @@ class Music extends SoundSource {
53
53
  filename = path.resolve(process.cwd(), filename);
54
54
  return this._raw().openFromFileSync(filename);
55
55
  }
56
+
57
+ openFromMemory(buff) {
58
+ validateTypeOf(buff, 'buff', Buffer);
59
+ return this._raw().openFromMemory(buff);
60
+ }
61
+
56
62
  }
57
63
 
58
64
  Music.Status = SoundSource.Status;
package/lib/texture.d.ts CHANGED
@@ -7,6 +7,7 @@ export class Texture {
7
7
 
8
8
  create(x: number, y: number): void;
9
9
 
10
+ loadFromMemory(buff: Buffer, area?: IntRect): boolean;
10
11
  loadFromFile(filename: string, area?: IntRect): Promise<void>;
11
12
  loadFromFileSync(filename: string, area?: IntRect): boolean;
12
13
  update(texture: Texture): void;
package/lib/texture.js CHANGED
@@ -35,6 +35,12 @@ class Texture extends _Texture {
35
35
  return promise;
36
36
  }
37
37
 
38
+ loadFromMemory(buff, area) {
39
+ validateTypeOf(buff, 'buff', Buffer);
40
+ validateTypeOf(area, 'area', IntRect, true);
41
+ return super.loadFromMemory(buff, area);
42
+ }
43
+
38
44
  create(x, y) {
39
45
  validateTypeOf(x, 'x', 'number');
40
46
  validateTypeOf(y, 'y', 'number');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sfml.js",
3
- "version": "0.0.1-preview.31",
3
+ "version": "0.0.1-preview.35",
4
4
  "description": "SFML's Node.js binding.",
5
5
  "main": "lib/sfml.js",
6
6
  "scripts": {
@@ -9,6 +9,7 @@
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
11
  "cpplint": "./third_party/cpplint/cpplint.py src/**/*",
12
+ "jslint": "eslint .",
12
13
  "install": "node-gyp rebuild"
13
14
  },
14
15
  "repository": {
@@ -28,8 +29,10 @@
28
29
  },
29
30
  "devDependencies": {
30
31
  "@types/node": "^16.11.6",
31
- "eslint": "^8.0.0",
32
- "eslint-config-egg": "^9.0.0"
32
+ "eslint": "^6.0.0",
33
+ "eslint-config-egg": "^9.0.0",
34
+ "eslint-plugin-import": "^2.25.2",
35
+ "typescript": "~4.0.0"
33
36
  },
34
37
  "files": [
35
38
  "binding.gyp",
@@ -51,4 +54,4 @@
51
54
  "tools/*",
52
55
  "tsconfig.json"
53
56
  ]
54
- }
57
+ }
@@ -39,6 +39,15 @@ NAN_METHOD(Sprite::New) {
39
39
  return;
40
40
  }
41
41
 
42
+ if (info.Length() == 2 && info[0]->IsString()) {
43
+ Sprite* src = Nan::ObjectWrap::Unwrap<Sprite>(info[1].As<Object>());
44
+ MaybeLocal<Object> texture_object = src->GetTexture();
45
+ Sprite* sprite = new Sprite(src, texture_object);
46
+ sprite->Wrap(info.This());
47
+ info.GetReturnValue().Set(info.This());
48
+ return;
49
+ }
50
+
42
51
  texture::Texture* texture =
43
52
  Nan::ObjectWrap::Unwrap<texture::Texture>(info[0].As<Object>());
44
53
  if (info.Length() == 1) {
@@ -82,6 +91,12 @@ NAN_METHOD(Sprite::GetColor) {
82
91
 
83
92
  Sprite::Sprite() : DrawableWithTexture(new sf::Sprite()) {}
84
93
 
94
+ Sprite::Sprite(Sprite* sprite, MaybeLocal<Object> texture_object)
95
+ : DrawableWithTexture(new sf::Sprite(sprite->raw<sf::Sprite>())) {
96
+ if (!texture_object.IsEmpty())
97
+ DrawableWithTexture::SetTexture(texture_object.ToLocalChecked());
98
+ }
99
+
85
100
  Sprite::Sprite(Local<Object> texture_object, const texture::Texture& texture)
86
101
  : DrawableWithTexture(new sf::Sprite(texture.texture())) {
87
102
  DrawableWithTexture::SetTexture(texture_object);
@@ -31,14 +31,12 @@ class Sprite : public DrawableWithTexture {
31
31
 
32
32
  private:
33
33
  Sprite();
34
+ Sprite(Sprite* sprite, v8::MaybeLocal<v8::Object> texture_object);
34
35
  Sprite(v8::Local<v8::Object> texture_object, const texture::Texture& texture);
35
36
  Sprite(v8::Local<v8::Object> texture_object,
36
37
  const texture::Texture& texture,
37
38
  const rect::IntRect& rect);
38
39
  virtual ~Sprite();
39
-
40
- private:
41
- Nan::Persistent<v8::Object> _texture;
42
40
  };
43
41
 
44
42
  } // namespace drawable
package/src/font.cc CHANGED
@@ -21,6 +21,7 @@ NAN_MODULE_INIT(Font::Init) {
21
21
 
22
22
  Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
23
23
 
24
+ Nan::SetPrototypeMethod(tpl, "loadFromMemory", LoadFromMemory);
24
25
  Nan::SetPrototypeMethod(tpl, "loadFromFileSync", LoadFromFileSync);
25
26
  Nan::SetPrototypeMethod(tpl, "loadFromFile", LoadFromFile);
26
27
  Nan::SetPrototypeMethod(tpl, "getInfo", GetInfo);
@@ -81,6 +82,18 @@ NAN_METHOD(Font::LoadFromFileSync) {
81
82
  info.GetReturnValue().Set(font->_font->loadFromFile(*filename));
82
83
  }
83
84
 
85
+ NAN_METHOD(Font::LoadFromMemory) {
86
+ Font* fnt = Nan::ObjectWrap::Unwrap<Font>(info.Holder());
87
+ if (fnt->_loading) {
88
+ Nan::ThrowError("Font is loading.");
89
+ return;
90
+ }
91
+
92
+ const char* buff = node::Buffer::Data(info[0]);
93
+ size_t length = node::Buffer::Length(info[0]);
94
+ info.GetReturnValue().Set(fnt->_font->loadFromMemory(buff, length));
95
+ }
96
+
84
97
  NAN_METHOD(Font::GetInfo) {
85
98
  Font* font = Nan::ObjectWrap::Unwrap<Font>(info.Holder());
86
99
  sf::Font::Info font_info = font->_font->getInfo();
package/src/font.h CHANGED
@@ -18,6 +18,7 @@ class Font : public Nan::ObjectWrap, public BaseClassWithLoading {
18
18
 
19
19
  private:
20
20
  static NAN_METHOD(New);
21
+ static NAN_METHOD(LoadFromMemory);
21
22
  static NAN_METHOD(LoadFromFile);
22
23
  static NAN_METHOD(LoadFromFileSync);
23
24
  static NAN_METHOD(GetInfo);
package/src/image.cc CHANGED
@@ -142,7 +142,6 @@ NAN_METHOD(Image::SaveToFile) {
142
142
  Nan::Utf8String utf8_filename(v8_filename);
143
143
  Nan::Callback* callback = new Nan::Callback(info[1].As<Function>());
144
144
 
145
- Image* img = Nan::ObjectWrap::Unwrap<Image>(info.Holder());
146
145
  save_to_file_worker::SaveToFileWorker<Image, void>* worker =
147
146
  new save_to_file_worker::SaveToFileWorker<Image, void>(
148
147
  info.Holder(),
package/src/keyboard.cc CHANGED
@@ -10,6 +10,7 @@ namespace keyboard {
10
10
  using std::map;
11
11
  using std::string;
12
12
  using v8::Local;
13
+ using v8::Object;
13
14
  using v8::String;
14
15
 
15
16
  NAN_MODULE_INIT(Init) {
@@ -18,6 +19,16 @@ NAN_MODULE_INIT(Init) {
18
19
  Nan::SetMethod(target, "isKeyPressed", IsKeyPressed);
19
20
  Nan::SetMethod(
20
21
  target, "setVirtualKeyboardVisible", SetVirtualKeyboardVisible);
22
+
23
+ Local<Object> key_codes = Nan::New<Object>();
24
+ for (auto it = gen::keycode_atoi.begin(); it != gen::keycode_atoi.end();
25
+ it++) {
26
+ Nan::Set(key_codes,
27
+ Nan::New<String>(it->first).ToLocalChecked(),
28
+ Nan::New(it->second));
29
+ }
30
+
31
+ Nan::Set(target, Nan::New<String>("Keys").ToLocalChecked(), key_codes);
21
32
  }
22
33
 
23
34
  NAN_METHOD(IsKeyPressed) {
@@ -32,6 +32,7 @@ NAN_MODULE_INIT(RenderWindow::Init) {
32
32
  Nan::SetPrototypeMethod(tpl, "isOpen", IsOpen);
33
33
  Nan::SetPrototypeMethod(tpl, "pollEvent", PollEvent);
34
34
  Nan::SetPrototypeMethod(tpl, "getSize", GetSize);
35
+ Nan::SetPrototypeMethod(tpl, "hasFocus", HasFocus);
35
36
 
36
37
  #define PRIMITIVE_VALUE_PROTOTYPE_METHOD(name, _) \
37
38
  Nan::SetPrototypeMethod(tpl, "set" #name, Set##name);
@@ -199,6 +200,11 @@ NAN_METHOD(RenderWindow::GetSize) {
199
200
  info.GetReturnValue().Set(maybe_vec.ToLocalChecked());
200
201
  }
201
202
 
203
+ NAN_METHOD(RenderWindow::HasFocus) {
204
+ RenderWindow* window = Nan::ObjectWrap::Unwrap<RenderWindow>(info.Holder());
205
+ info.GetReturnValue().Set(window->_window->hasFocus());
206
+ }
207
+
202
208
  #define SET_PRIMITIVE_VALUE(name, type) \
203
209
  NAN_METHOD(RenderWindow::Set##name) { \
204
210
  RenderWindow* window = \
@@ -26,6 +26,7 @@ class RenderWindow : public Nan::ObjectWrap {
26
26
  static NAN_METHOD(IsOpen);
27
27
  static NAN_METHOD(PollEvent);
28
28
  static NAN_METHOD(GetSize);
29
+ static NAN_METHOD(HasFocus);
29
30
 
30
31
  #define PRIMITIVE_VALUES(V) \
31
32
  V(Visible, bool) \
@@ -26,6 +26,7 @@ NAN_MODULE_INIT(Music::Init) {
26
26
 
27
27
  Nan::SetPrototypeMethod(tpl, "openFromFileSync", OpenFromFileSync);
28
28
  Nan::SetPrototypeMethod(tpl, "openFromFile", OpenFromFile);
29
+ Nan::SetPrototypeMethod(tpl, "openFromMemory", OpenFromMemory);
29
30
 
30
31
  sound::SoundSource::SetCommonPrototype(&tpl);
31
32
 
@@ -93,6 +94,18 @@ NAN_METHOD(Music::OpenFromFileSync) {
93
94
  info.GetReturnValue().Set(music->music().openFromFile(*filename));
94
95
  }
95
96
 
97
+ NAN_METHOD(Music::OpenFromMemory) {
98
+ Music* msc = Nan::ObjectWrap::Unwrap<Music>(info.Holder());
99
+ if (msc->_loading) {
100
+ Nan::ThrowError("Music is loading.");
101
+ return;
102
+ }
103
+
104
+ const char* buff = node::Buffer::Data(info[0]);
105
+ size_t length = node::Buffer::Length(info[0]);
106
+ info.GetReturnValue().Set(msc->music().openFromMemory(buff, length));
107
+ }
108
+
96
109
  Music::Music() : SoundSource(SoundSource::SoundType::kMusic, new sf::Music()) {}
97
110
  Music::~Music() {}
98
111
 
package/src/sound/music.h CHANGED
@@ -15,6 +15,7 @@ class Music : public SoundSource, public BaseClassWithLoading {
15
15
 
16
16
  public:
17
17
  static NAN_METHOD(New);
18
+ static NAN_METHOD(OpenFromMemory);
18
19
  static NAN_METHOD(OpenFromFile);
19
20
  static NAN_METHOD(OpenFromFileSync);
20
21
  static NAN_METHOD(SetLoop);
package/src/texture.cc CHANGED
@@ -25,6 +25,7 @@ NAN_MODULE_INIT(Texture::Init) {
25
25
 
26
26
  Nan::SetPrototypeMethod(tpl, "create", Create);
27
27
  Nan::SetPrototypeMethod(tpl, "loadFromFile", LoadFromFile);
28
+ Nan::SetPrototypeMethod(tpl, "loadFromMemory", LoadFromMemory);
28
29
  Nan::SetPrototypeMethod(tpl, "loadFromFileSync", LoadFromFileSync);
29
30
  Nan::SetPrototypeMethod(tpl, "getSize", GetSize);
30
31
 
@@ -90,6 +91,24 @@ NAN_METHOD(Texture::LoadFromFile) {
90
91
  Nan::AsyncQueueWorker(worker);
91
92
  }
92
93
 
94
+ NAN_METHOD(Texture::LoadFromMemory) {
95
+ Texture* txt = Nan::ObjectWrap::Unwrap<Texture>(info.Holder());
96
+ if (txt->_loading) {
97
+ Nan::ThrowError("Texture is loading.");
98
+ return;
99
+ }
100
+
101
+ const char* buff = node::Buffer::Data(info[0]);
102
+ size_t length = node::Buffer::Length(info[0]);
103
+
104
+ sf::IntRect area;
105
+ if (!info[1]->IsUndefined()) {
106
+ area = Nan::ObjectWrap::Unwrap<rect::IntRect>(info[1].As<Object>())->rect();
107
+ }
108
+
109
+ info.GetReturnValue().Set(txt->_texture.loadFromMemory(buff, length, area));
110
+ }
111
+
93
112
  NAN_METHOD(Texture::LoadFromFileSync) {
94
113
  Texture* texture = Nan::ObjectWrap::Unwrap<Texture>(info.Holder());
95
114
  if (texture->_loading) {
package/src/texture.h CHANGED
@@ -18,6 +18,7 @@ class Texture : public Nan::ObjectWrap, public BaseClassWithLoading {
18
18
  static NAN_METHOD(New);
19
19
  static NAN_METHOD(Create);
20
20
  static NAN_METHOD(LoadFromFile);
21
+ static NAN_METHOD(LoadFromMemory);
21
22
  static NAN_METHOD(LoadFromFileSync);
22
23
  static NAN_METHOD(GetSize);
23
24
 
@@ -76,4 +76,4 @@ class LoadFromFileWorker : public Nan::AsyncWorker {
76
76
  } // namespace load_from_file_worker
77
77
  } // namespace node_sfml
78
78
 
79
- #endif // SRC_LOAD_FROM_FILE_WORKER_H_
79
+ #endif // SRC_WORKERS_LOAD_FROM_FILE_WORKER_H_
@@ -76,4 +76,4 @@ class SaveToFileWorker : public Nan::AsyncWorker {
76
76
  } // namespace save_to_file_worker
77
77
  } // namespace node_sfml
78
78
 
79
- #endif // SRC_SAVE_TO_FILE_WORKER_H_
79
+ #endif // SRC_WORKERS_SAVE_TO_FILE_WORKER_H_