sfml.js 1.0.0 → 1.2.1

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.
Files changed (313) hide show
  1. package/README.ja.md +10 -9
  2. package/README.ko.md +10 -9
  3. package/README.md +10 -9
  4. package/README.zh-CN.md +10 -9
  5. package/binding.gyp +23 -16
  6. package/dist/audio/effect-processor.js +9 -3
  7. package/dist/audio/input-sound-file.js +41 -15
  8. package/dist/audio/listener.js +33 -11
  9. package/dist/audio/music.js +41 -18
  10. package/dist/audio/output-sound-file.js +4 -2
  11. package/dist/audio/playback-device.js +11 -3
  12. package/dist/audio/sound-buffer-recorder.js +8 -5
  13. package/dist/audio/sound-buffer.js +40 -17
  14. package/dist/audio/sound-file-factory.js +21 -9
  15. package/dist/audio/sound-file-reader.js +21 -7
  16. package/dist/audio/sound-recorder.js +36 -15
  17. package/dist/audio/sound-source.js +117 -40
  18. package/dist/audio/sound-stream.js +14 -5
  19. package/dist/audio/sound.js +9 -4
  20. package/dist/audio/value.js +42 -16
  21. package/dist/graphics/blend-mode.js +2 -1
  22. package/dist/graphics/boolean-vector.d.ts +1 -2
  23. package/dist/graphics/boolean-vector.js +19 -9
  24. package/dist/graphics/color.js +2 -1
  25. package/dist/graphics/convex-shape.js +7 -3
  26. package/dist/graphics/font.js +52 -23
  27. package/dist/graphics/glsl-matrix.js +8 -3
  28. package/dist/graphics/glsl.js +47 -16
  29. package/dist/graphics/glyph.js +27 -10
  30. package/dist/graphics/image.js +30 -14
  31. package/dist/graphics/rect.js +15 -8
  32. package/dist/graphics/render-states.js +18 -9
  33. package/dist/graphics/render-target.js +49 -23
  34. package/dist/graphics/render-texture.js +24 -12
  35. package/dist/graphics/render-window.js +6 -3
  36. package/dist/graphics/shader.js +67 -32
  37. package/dist/graphics/shape.js +25 -13
  38. package/dist/graphics/sprite.js +19 -9
  39. package/dist/graphics/stencil-mode.js +10 -6
  40. package/dist/graphics/swap.js +2 -1
  41. package/dist/graphics/text.js +123 -48
  42. package/dist/graphics/texture.js +48 -24
  43. package/dist/graphics/transform.js +29 -13
  44. package/dist/graphics/transformable.js +2 -1
  45. package/dist/graphics/vertex-array.js +40 -18
  46. package/dist/graphics/vertex-buffer.js +39 -19
  47. package/dist/graphics/vertex.js +6 -3
  48. package/dist/graphics/view.js +30 -14
  49. package/dist/index.d.ts +4 -4
  50. package/dist/internal/audio-codec-registry.js +12 -6
  51. package/dist/internal/audio-input-stream.js +2 -1
  52. package/dist/internal/audio-music-pump.js +58 -24
  53. package/dist/internal/audio-recorder-session.js +17 -7
  54. package/dist/internal/audio-worker-session.js +28 -10
  55. package/dist/internal/audio-worker.js +40 -21
  56. package/dist/internal/glsl-value.d.ts +3 -1
  57. package/dist/internal/glsl-value.js +18 -8
  58. package/dist/internal/graphics-state.js +29 -15
  59. package/dist/internal/input-stream.d.ts +3 -1
  60. package/dist/internal/input-stream.js +16 -7
  61. package/dist/internal/numeric-properties.js +2 -1
  62. package/dist/internal/render-states.js +2 -1
  63. package/dist/internal/scalar.js +22 -13
  64. package/dist/internal/shaped-glyph.d.ts +3 -1
  65. package/dist/internal/shaped-glyph.js +12 -4
  66. package/dist/internal/struct-view.d.ts +3 -1
  67. package/dist/internal/struct-view.js +3 -1
  68. package/dist/internal/transformable.js +2 -1
  69. package/dist/network/common.js +23 -11
  70. package/dist/network/dns.js +25 -17
  71. package/dist/network/ftp.js +43 -18
  72. package/dist/network/http.js +126 -56
  73. package/dist/network/ip-address.js +50 -25
  74. package/dist/network/packet.js +63 -25
  75. package/dist/network/sftp.js +175 -74
  76. package/dist/network/socket-selector.js +28 -14
  77. package/dist/network/socket.js +71 -30
  78. package/dist/network/tcp-listener.js +42 -19
  79. package/dist/network/tcp-socket.js +111 -53
  80. package/dist/network/tls-material.js +2 -1
  81. package/dist/network/udp-socket.js +68 -33
  82. package/dist/system/angle.js +2 -1
  83. package/dist/system/clock.js +4 -2
  84. package/dist/system/err.js +5 -2
  85. package/dist/system/file-input-stream.js +8 -4
  86. package/dist/system/input-stream.js +6 -3
  87. package/dist/system/operators.d.ts +1 -1
  88. package/dist/system/operators.js +90 -50
  89. package/dist/system/sleep.js +4 -2
  90. package/dist/system/time.js +12 -6
  91. package/dist/system/vector2.js +6 -7
  92. package/dist/system/vector3.js +11 -6
  93. package/dist/window/clipboard.js +2 -1
  94. package/dist/window/context.js +10 -5
  95. package/dist/window/cursor.js +2 -1
  96. package/dist/window/event.js +9 -5
  97. package/dist/window/mouse.js +4 -2
  98. package/dist/window/video-mode.js +2 -1
  99. package/dist/window/window.js +19 -12
  100. package/native/addon.cc +25 -12
  101. package/native/audio-binding.cc +266 -126
  102. package/native/audio-codec-binding.cc +147 -77
  103. package/native/audio-device-binding.cc +76 -49
  104. package/native/audio-file-binding.cc +116 -67
  105. package/native/audio-recorder-binding.cc +147 -98
  106. package/native/audio-recorder.h +1 -1
  107. package/native/audio-state.h +53 -30
  108. package/native/audio-stream-binding.cc +148 -94
  109. package/native/audio-stream.h +5 -4
  110. package/native/audio-worker-binding.cc +163 -81
  111. package/native/audio-worker.h +35 -19
  112. package/native/batch-drawable.cc +29 -16
  113. package/native/batch-drawable.h +11 -8
  114. package/native/context-binding.cc +40 -27
  115. package/native/context-settings.h +15 -8
  116. package/native/deferred-delete.cc +9 -6
  117. package/native/deferred-delete.h +7 -8
  118. package/native/error-stream-binding.cc +42 -28
  119. package/native/font-binding.cc +89 -48
  120. package/native/graphics-binding.cc +122 -72
  121. package/native/graphics-state.h +50 -36
  122. package/native/image-binding.cc +38 -24
  123. package/native/image-state.h +26 -18
  124. package/native/input-binding.cc +42 -27
  125. package/native/render-window-binding.cc +38 -23
  126. package/native/shader-binding.cc +115 -50
  127. package/native/shape-binding.cc +94 -49
  128. package/native/shape-state.h +18 -9
  129. package/native/shaped-glyph-storage.h +9 -5
  130. package/native/stream-binding.cc +143 -117
  131. package/native/system-binding.cc +17 -12
  132. package/native/text-binding.cc +68 -35
  133. package/native/text-state.h +25 -18
  134. package/native/texture-binding.cc +42 -33
  135. package/native/texture-resource.h +20 -12
  136. package/native/time-value.h +3 -1
  137. package/native/transformable-binding.cc +12 -6
  138. package/native/transformable-state.h +6 -6
  139. package/native/value-binding.h +46 -28
  140. package/native/value-layout.h +10 -10
  141. package/native/values-binding.cc +29 -23
  142. package/native/vertex-binding.cc +18 -12
  143. package/native/vertex-buffer-binding.cc +38 -24
  144. package/native/vertex-storage.h +2 -2
  145. package/native/view-data.h +4 -3
  146. package/native/window-binding.cc +75 -45
  147. package/native/window-event.h +20 -11
  148. package/native/window-owner.h +15 -12
  149. package/package.json +44 -51
  150. package/src/audio/effect-processor.ts +9 -3
  151. package/src/audio/input-sound-file.ts +108 -36
  152. package/src/audio/listener.ts +39 -13
  153. package/src/audio/music.ts +112 -47
  154. package/src/audio/output-sound-file.ts +40 -11
  155. package/src/audio/playback-device.ts +23 -8
  156. package/src/audio/sound-buffer-recorder.ts +35 -13
  157. package/src/audio/sound-buffer.ts +166 -58
  158. package/src/audio/sound-file-factory.ts +127 -49
  159. package/src/audio/sound-file-reader.ts +49 -15
  160. package/src/audio/sound-recorder.ts +100 -34
  161. package/src/audio/sound-source.ts +142 -45
  162. package/src/audio/sound-stream.ts +15 -5
  163. package/src/audio/sound.ts +12 -4
  164. package/src/audio/value.ts +89 -26
  165. package/src/graphics/blend-mode.ts +3 -1
  166. package/src/graphics/boolean-vector.ts +56 -26
  167. package/src/graphics/color.ts +3 -1
  168. package/src/graphics/convex-shape.ts +10 -3
  169. package/src/graphics/font.ts +171 -50
  170. package/src/graphics/glsl-matrix.ts +9 -3
  171. package/src/graphics/glsl.ts +81 -35
  172. package/src/graphics/glyph.ts +67 -26
  173. package/src/graphics/image.ts +119 -45
  174. package/src/graphics/rect.ts +56 -24
  175. package/src/graphics/render-states.ts +31 -14
  176. package/src/graphics/render-target.ts +197 -81
  177. package/src/graphics/render-texture.ts +36 -12
  178. package/src/graphics/render-window.ts +9 -3
  179. package/src/graphics/shader.ts +186 -61
  180. package/src/graphics/shape.ts +93 -35
  181. package/src/graphics/sprite.ts +64 -25
  182. package/src/graphics/stencil-mode.ts +12 -6
  183. package/src/graphics/swap.ts +3 -2
  184. package/src/graphics/text.ts +229 -74
  185. package/src/graphics/texture.ts +180 -61
  186. package/src/graphics/transform.ts +132 -47
  187. package/src/graphics/transformable.ts +3 -1
  188. package/src/graphics/vertex-array.ts +87 -35
  189. package/src/graphics/vertex-buffer.ts +97 -33
  190. package/src/graphics/vertex.ts +9 -3
  191. package/src/graphics/view.ts +59 -21
  192. package/src/index.ts +101 -23
  193. package/src/internal/audio-codec-registry.ts +18 -6
  194. package/src/internal/audio-input-stream.ts +6 -2
  195. package/src/internal/audio-music-pump.ts +116 -41
  196. package/src/internal/audio-native.ts +249 -96
  197. package/src/internal/audio-recorder-session.ts +68 -24
  198. package/src/internal/audio-worker-session.ts +65 -21
  199. package/src/internal/audio-worker.ts +85 -41
  200. package/src/internal/glsl-value.ts +26 -11
  201. package/src/internal/graphics-state.ts +57 -20
  202. package/src/internal/input-stream.ts +23 -10
  203. package/src/internal/native.ts +252 -99
  204. package/src/internal/numeric-properties.ts +2 -1
  205. package/src/internal/render-states.ts +3 -1
  206. package/src/internal/scalar.ts +33 -14
  207. package/src/internal/shaped-glyph.ts +25 -12
  208. package/src/internal/struct-view.ts +40 -13
  209. package/src/internal/transformable.ts +3 -1
  210. package/src/network/common.ts +35 -11
  211. package/src/network/dns.ts +95 -38
  212. package/src/network/ftp.ts +129 -47
  213. package/src/network/http.ts +232 -77
  214. package/src/network/ip-address.ts +118 -48
  215. package/src/network/packet.ts +161 -54
  216. package/src/network/sftp.ts +498 -168
  217. package/src/network/socket-selector.ts +66 -26
  218. package/src/network/socket.ts +133 -46
  219. package/src/network/tcp-listener.ts +78 -29
  220. package/src/network/tcp-socket.ts +240 -95
  221. package/src/network/tls-material.ts +6 -2
  222. package/src/network/udp-socket.ts +147 -53
  223. package/src/system/angle.ts +3 -1
  224. package/src/system/clock.ts +12 -4
  225. package/src/system/err.ts +5 -2
  226. package/src/system/file-input-stream.ts +12 -4
  227. package/src/system/input-stream.ts +9 -3
  228. package/src/system/operators.ts +290 -115
  229. package/src/system/sleep.ts +6 -2
  230. package/src/system/time.ts +18 -6
  231. package/src/system/timeout-with-predicate.ts +19 -8
  232. package/src/system/vector2.ts +101 -49
  233. package/src/system/vector3.ts +85 -36
  234. package/src/window/clipboard.ts +3 -1
  235. package/src/window/context.ts +15 -5
  236. package/src/window/cursor.ts +3 -1
  237. package/src/window/event.ts +26 -12
  238. package/src/window/mouse.ts +6 -2
  239. package/src/window/video-mode.ts +3 -1
  240. package/src/window/window.ts +119 -37
  241. package/test/native/audio-probes.cc +74 -36
  242. package/test/native/deferred-delete-probes.cc +17 -11
  243. package/test/native/drawable-probes.cc +70 -36
  244. package/test/native/exception-probes.cc +14 -9
  245. package/test/native/image-probes.cc +20 -10
  246. package/test/native/matrix-probes.cc +8 -4
  247. package/test/native/network-oracle.cc +17 -11
  248. package/test/native/render-texture-probes.cc +33 -24
  249. package/test/native/shader-probes.cc +9 -9
  250. package/test/native/shape-probes.cc +37 -23
  251. package/test/native/sprite-probes.cc +41 -25
  252. package/test/native/system-probes.cc +58 -35
  253. package/test/native/text-probes.cc +77 -44
  254. package/test/native/texture-probes.cc +43 -26
  255. package/test/native/time-probes.cc +18 -12
  256. package/test/native/transform-probes.cc +15 -10
  257. package/test/native/transformable-probes.cc +23 -17
  258. package/test/native/value-oracle.h +9 -4
  259. package/test/native/value-probes.cc +31 -23
  260. package/test/native/vertex-array-probes.cc +22 -14
  261. package/test/native/vertex-buffer-probes.cc +28 -17
  262. package/test/native/view-probes.cc +29 -17
  263. package/test/native/window-probes.cc +66 -33
  264. package/tools/ensure-sfml.cjs +9 -0
  265. package/tools/generate-network-constants.cjs +11 -6
  266. package/tools/generate-window-constants.cjs +31 -12
  267. package/docs/README.ja.md +0 -30
  268. package/docs/README.ko.md +0 -30
  269. package/docs/README.md +0 -30
  270. package/docs/README.zh-CN.md +0 -30
  271. package/docs/api.ja.md +0 -84
  272. package/docs/api.ko.md +0 -84
  273. package/docs/api.md +0 -81
  274. package/docs/api.zh-CN.md +0 -81
  275. package/docs/audio.ja.md +0 -249
  276. package/docs/audio.ko.md +0 -251
  277. package/docs/audio.md +0 -252
  278. package/docs/audio.zh-CN.md +0 -252
  279. package/docs/concepts.ja.md +0 -130
  280. package/docs/concepts.ko.md +0 -130
  281. package/docs/concepts.md +0 -131
  282. package/docs/concepts.zh-CN.md +0 -131
  283. package/docs/development.ja.md +0 -144
  284. package/docs/development.ko.md +0 -144
  285. package/docs/development.md +0 -146
  286. package/docs/development.zh-CN.md +0 -146
  287. package/docs/getting-started.ja.md +0 -154
  288. package/docs/getting-started.ko.md +0 -154
  289. package/docs/getting-started.md +0 -156
  290. package/docs/getting-started.zh-CN.md +0 -156
  291. package/docs/graphics.ja.md +0 -256
  292. package/docs/graphics.ko.md +0 -254
  293. package/docs/graphics.md +0 -255
  294. package/docs/graphics.zh-CN.md +0 -257
  295. package/docs/network.ja.md +0 -214
  296. package/docs/network.ko.md +0 -216
  297. package/docs/network.md +0 -218
  298. package/docs/network.zh-CN.md +0 -218
  299. package/docs/system.ja.md +0 -169
  300. package/docs/system.ko.md +0 -171
  301. package/docs/system.md +0 -173
  302. package/docs/system.zh-CN.md +0 -173
  303. package/docs/window.ja.md +0 -138
  304. package/docs/window.ko.md +0 -140
  305. package/docs/window.md +0 -141
  306. package/docs/window.zh-CN.md +0 -141
  307. package/native/exception-boundary.h +0 -97
  308. package/native/numeric-fields.h +0 -96
  309. package/native/shared-handle.h +0 -107
  310. package/test/tsconfig.json +0 -8
  311. package/tools/configure-lsp.cjs +0 -23
  312. package/tools/lib_downloader.cjs +0 -92
  313. package/tools/lib_downloader_urls.cjs +0 -23
@@ -1,9 +1,15 @@
1
1
  import {
2
- native, type NativeGraphicsHandle, type NativeTextureInfo,
2
+ native,
3
+ type NativeGraphicsHandle,
4
+ type NativeTextureInfo,
3
5
  type NativeTextureMapping,
4
6
  } from '../internal/native';
5
7
  import {
6
- graphicsContext, graphicsNative, flushGraphics, textureId, textureOwner,
8
+ graphicsContext,
9
+ graphicsNative,
10
+ flushGraphics,
11
+ textureId,
12
+ textureOwner,
7
13
  type PendingTarget,
8
14
  } from '../internal/graphics-state';
9
15
  import { type ReadonlyValue } from '../internal/value-storage';
@@ -22,10 +28,20 @@ import { CoordinateType } from './render-states';
22
28
  * @ja 同一テクスチャリソースへのコンパイル時 const 参照。
23
29
  * @ko 동일한 텍스처 리소스에 대한 컴파일 시점의 const 참조입니다.
24
30
  */
25
- export type ReadonlyTexture = Readonly<Pick<Texture,
26
- typeof graphicsNative | typeof textureId | typeof textureOwner |
27
- 'getSize' | 'copyToImage' | 'isSmooth' | 'isRepeated' | 'isSrgb' |
28
- 'getNativeHandle'>>;
31
+ export type ReadonlyTexture = Readonly<
32
+ Pick<
33
+ Texture,
34
+ | typeof graphicsNative
35
+ | typeof textureId
36
+ | typeof textureOwner
37
+ | 'getSize'
38
+ | 'copyToImage'
39
+ | 'isSmooth'
40
+ | 'isRepeated'
41
+ | 'isSrgb'
42
+ | 'getNativeHandle'
43
+ >
44
+ >;
29
45
 
30
46
  /**
31
47
  * Internal factory for a render target's borrowed GPU texture.
@@ -34,11 +50,13 @@ typeof graphicsNative | typeof textureId | typeof textureOwner |
34
50
  * @ko 렌더 대상에서 빌린 GPU 텍스처를 위한 내부 팩토리입니다.
35
51
  */
36
52
  export let textureFromMapping: (
37
- mapping: NativeTextureMapping, owner: PendingTarget,
53
+ mapping: NativeTextureMapping,
54
+ owner: PendingTarget,
38
55
  ) => ReadonlyTexture;
39
56
 
40
57
  export let fontTextureFromMapping: (
41
- mapping: NativeTextureMapping, owner: object,
58
+ mapping: NativeTextureMapping,
59
+ owner: object,
42
60
  ) => ReadonlyTexture;
43
61
 
44
62
  function coordinates(value: Readonly<Vector2u>): void {
@@ -48,12 +66,18 @@ function coordinates(value: Readonly<Vector2u>): void {
48
66
  }
49
67
 
50
68
  function flag(value: boolean): void {
51
- if (typeof value !== 'boolean') throw new TypeError('Expected a boolean');
69
+ if (typeof value !== 'boolean') {
70
+ throw new TypeError('Expected a boolean');
71
+ }
52
72
  }
53
73
 
54
74
  function areaSnapshot(area?: ReadonlyValue<IntRect>): IntRect | undefined {
55
- if (area === undefined) return undefined;
56
- if (!(area instanceof IntRect)) throw new TypeError('Expected an IntRect');
75
+ if (area === undefined) {
76
+ return undefined;
77
+ }
78
+ if (!(area instanceof IntRect)) {
79
+ throw new TypeError('Expected an IntRect');
80
+ }
57
81
  return new IntRect(area);
58
82
  }
59
83
 
@@ -137,12 +161,18 @@ export class Texture {
137
161
  */
138
162
  constructor(image: Image, sRgb?: boolean, area?: ReadonlyValue<IntRect>);
139
163
  constructor(
140
- source?: Readonly<Vector2u> | ReadonlyTexture | Image, sRgb = false,
164
+ source?: Readonly<Vector2u> | ReadonlyTexture | Image,
165
+ sRgb = false,
141
166
  area?: ReadonlyValue<IntRect>,
142
167
  ) {
143
168
  flag(sRgb);
144
- if (source !== undefined && !(source instanceof Texture) &&
145
- !(source instanceof Image)) coordinates(source as Readonly<Vector2u>);
169
+ if (
170
+ source !== undefined &&
171
+ !(source instanceof Texture) &&
172
+ !(source instanceof Image)
173
+ ) {
174
+ coordinates(source as Readonly<Vector2u>);
175
+ }
146
176
  if (area !== undefined && !(area instanceof IntRect)) {
147
177
  throw new TypeError('Expected an IntRect');
148
178
  }
@@ -159,8 +189,13 @@ export class Texture {
159
189
  this[graphicsNative] = mapping.handle;
160
190
  this[textureId] = mapping.id;
161
191
  this.state = nativeStruct<NativeTextureInfo>(mapping.info);
162
- if (source instanceof Image && !this.loadFromImage(source, sRgb, area)) {
163
- throw new SFMLError('SFML could not create the texture from the image');
192
+ if (
193
+ source instanceof Image &&
194
+ !this.loadFromImage(source, sRgb, area)
195
+ ) {
196
+ throw new SFMLError(
197
+ 'SFML could not create the texture from the image',
198
+ );
164
199
  }
165
200
  }
166
201
 
@@ -224,7 +259,10 @@ export class Texture {
224
259
  flag(sRgb);
225
260
  flushGraphics();
226
261
  const state = native.resizeTexture(
227
- this[graphicsNative], size.x, size.y, sRgb,
262
+ this[graphicsNative],
263
+ size.x,
264
+ size.y,
265
+ sRgb,
228
266
  );
229
267
  return state !== undefined;
230
268
  }
@@ -236,7 +274,9 @@ export class Texture {
236
274
  * @ko GPU에서 독립적인 네이티브 소유 Image로 동기적으로 읽어옵니다.
237
275
  */
238
276
  copyToImage(): Image {
239
- return imageFromMapping(native.copyTextureToImage(this[graphicsNative]));
277
+ return imageFromMapping(
278
+ native.copyTextureToImage(this[graphicsNative]),
279
+ );
240
280
  }
241
281
 
242
282
  /**
@@ -261,13 +301,15 @@ export class Texture {
261
301
  */
262
302
  swap(other: Texture): void {
263
303
  this.checkWritable();
264
- if (!(other instanceof Texture)) throw new TypeError('Expected a Texture');
304
+ if (!(other instanceof Texture)) {
305
+ throw new TypeError('Expected a Texture');
306
+ }
265
307
  other.checkWritable();
266
- if (other === this) return;
308
+ if (other === this) {
309
+ return;
310
+ }
267
311
  flushGraphics();
268
- native.swapTextures(
269
- this[graphicsNative], other[graphicsNative],
270
- );
312
+ native.swapTextures(this[graphicsNative], other[graphicsNative]);
271
313
  }
272
314
 
273
315
  /**
@@ -279,8 +321,12 @@ export class Texture {
279
321
  */
280
322
  assign(source: ReadonlyTexture): this {
281
323
  this.checkWritable();
282
- if (!(source instanceof Texture)) throw new TypeError('Expected a Texture');
283
- if (source === this) return this;
324
+ if (!(source instanceof Texture)) {
325
+ throw new TypeError('Expected a Texture');
326
+ }
327
+ if (source === this) {
328
+ return this;
329
+ }
284
330
  flushGraphics();
285
331
  native.assignTexture(this[graphicsNative], source[graphicsNative]);
286
332
  return this;
@@ -294,13 +340,17 @@ export class Texture {
294
340
  * @ko 파일을 비동기로 디코딩한 후 픽셀을 업로드하고 성공 여부를 반환합니다. area는 픽셀 좌표이며 기본값은 전체 이미지입니다.
295
341
  */
296
342
  async loadFromFile(
297
- filename: string, sRgb = false, area?: ReadonlyValue<IntRect>,
343
+ filename: string,
344
+ sRgb = false,
345
+ area?: ReadonlyValue<IntRect>,
298
346
  ): Promise<boolean> {
299
347
  this.checkWritable();
300
348
  flag(sRgb);
301
349
  const snapshot = areaSnapshot(area);
302
350
  const image = new Image();
303
- if (!await image.loadFromFile(filename)) return false;
351
+ if (!(await image.loadFromFile(filename))) {
352
+ return false;
353
+ }
304
354
  return this.loadFromImage(image, sRgb, snapshot);
305
355
  }
306
356
 
@@ -312,13 +362,17 @@ export class Texture {
312
362
  * @ko 인코딩된 이미지 바이트를 비동기로 디코딩한 후 픽셀을 업로드하고 성공 여부를 반환합니다. sRgb의 기본값은 false입니다.
313
363
  */
314
364
  async loadFromMemory(
315
- data: Uint8Array, sRgb = false, area?: ReadonlyValue<IntRect>,
365
+ data: Uint8Array,
366
+ sRgb = false,
367
+ area?: ReadonlyValue<IntRect>,
316
368
  ): Promise<boolean> {
317
369
  this.checkWritable();
318
370
  flag(sRgb);
319
371
  const snapshot = areaSnapshot(area);
320
372
  const image = new Image();
321
- if (!await image.loadFromMemory(data)) return false;
373
+ if (!(await image.loadFromMemory(data))) {
374
+ return false;
375
+ }
322
376
  return this.loadFromImage(image, sRgb, snapshot);
323
377
  }
324
378
 
@@ -331,13 +385,17 @@ export class Texture {
331
385
  * 거부합니다.
332
386
  */
333
387
  async loadFromStream(
334
- stream: InputStream, sRgb = false, area?: ReadonlyValue<IntRect>,
388
+ stream: InputStream,
389
+ sRgb = false,
390
+ area?: ReadonlyValue<IntRect>,
335
391
  ): Promise<boolean> {
336
392
  this.checkWritable();
337
393
  flag(sRgb);
338
394
  const snapshot = areaSnapshot(area);
339
395
  const image = new Image();
340
- if (!await image.loadFromStream(stream)) return false;
396
+ if (!(await image.loadFromStream(stream))) {
397
+ return false;
398
+ }
341
399
  return this.loadFromImage(image, sRgb, snapshot);
342
400
  }
343
401
 
@@ -349,19 +407,27 @@ export class Texture {
349
407
  * @ko Image의 지정한 픽셀 영역을 동기적으로 업로드하고 성공 여부를 반환합니다. 기본값은 전체 이미지입니다.
350
408
  */
351
409
  loadFromImage(
352
- image: Image, sRgb = false, area?: ReadonlyValue<IntRect>,
410
+ image: Image,
411
+ sRgb = false,
412
+ area?: ReadonlyValue<IntRect>,
353
413
  ): boolean {
354
414
  this.checkWritable();
355
- if (!(image instanceof Image)) throw new TypeError('Expected an Image');
415
+ if (!(image instanceof Image)) {
416
+ throw new TypeError('Expected an Image');
417
+ }
356
418
  flag(sRgb);
357
419
  if (area !== undefined && !(area instanceof IntRect)) {
358
420
  throw new TypeError('Expected an IntRect');
359
421
  }
360
422
  flushGraphics();
361
423
  const state = native.loadTextureImage(
362
- this[graphicsNative], image[graphicsNative], sRgb,
363
- area?.position.x ?? 0, area?.position.y ?? 0,
364
- area?.size.x ?? 0, area?.size.y ?? 0,
424
+ this[graphicsNative],
425
+ image[graphicsNative],
426
+ sRgb,
427
+ area?.position.x ?? 0,
428
+ area?.position.y ?? 0,
429
+ area?.size.x ?? 0,
430
+ area?.size.y ?? 0,
365
431
  );
366
432
  return state !== undefined;
367
433
  }
@@ -382,7 +448,9 @@ export class Texture {
382
448
  * @ko size 크기의 RGBA8 픽셀 블록을 dest에 업로드합니다. 모든 좌표와 크기는 픽셀 단위입니다.
383
449
  */
384
450
  update(
385
- pixels: Uint8Array, size: Readonly<Vector2u>, dest: Readonly<Vector2u>,
451
+ pixels: Uint8Array,
452
+ size: Readonly<Vector2u>,
453
+ dest: Readonly<Vector2u>,
386
454
  ): void;
387
455
  /**
388
456
  * Copies image, texture or window contents to dest (default origin); the
@@ -392,18 +460,26 @@ export class Texture {
392
460
  * @ko 이미지, 텍스처 또는 창 내용을 dest(기본값은 원점)에 복사합니다. 대상 영역은 전체 소스를 담을 수 있어야 합니다.
393
461
  */
394
462
  update(
395
- source: Image | ReadonlyTexture | Window, dest?: Readonly<Vector2u>,
463
+ source: Image | ReadonlyTexture | Window,
464
+ dest?: Readonly<Vector2u>,
396
465
  ): void;
397
466
  update(
398
467
  source: Uint8Array | Image | ReadonlyTexture | Window,
399
- sizeOrDest?: Readonly<Vector2u>, dest?: Readonly<Vector2u>,
468
+ sizeOrDest?: Readonly<Vector2u>,
469
+ dest?: Readonly<Vector2u>,
400
470
  ): void {
401
471
  this.checkWritable();
402
- if (sizeOrDest !== undefined) coordinates(sizeOrDest);
403
- if (dest !== undefined) coordinates(dest);
472
+ if (sizeOrDest !== undefined) {
473
+ coordinates(sizeOrDest);
474
+ }
475
+ if (dest !== undefined) {
476
+ coordinates(dest);
477
+ }
404
478
  if (source instanceof Uint8Array) {
405
479
  if ((sizeOrDest === undefined) !== (dest === undefined)) {
406
- throw new TypeError('Pixel region requires both size and destination');
480
+ throw new TypeError(
481
+ 'Pixel region requires both size and destination',
482
+ );
407
483
  }
408
484
  const width = sizeOrDest?.x ?? this.state.width;
409
485
  const height = sizeOrDest?.y ?? this.state.height;
@@ -414,31 +490,59 @@ export class Texture {
414
490
  throw new RangeError('Pixel length must equal width * height * 4');
415
491
  }
416
492
  flushGraphics();
417
- native.updateTexture(this[graphicsNative], source, width, height, x, y);
493
+ native.updateTexture(
494
+ this[graphicsNative],
495
+ source,
496
+ width,
497
+ height,
498
+ x,
499
+ y,
500
+ );
418
501
  return;
419
502
  }
420
- if (!(source instanceof Image) && !(source instanceof Texture) &&
421
- !(source instanceof Window)) {
422
- throw new TypeError('Expected RGBA Uint8Array, Image, Texture or Window');
503
+ if (
504
+ !(source instanceof Image) &&
505
+ !(source instanceof Texture) &&
506
+ !(source instanceof Window)
507
+ ) {
508
+ throw new TypeError(
509
+ 'Expected RGBA Uint8Array, Image, Texture or Window',
510
+ );
423
511
  }
424
512
  if (dest !== undefined) {
425
- throw new TypeError('Image, Texture or Window update only accepts a destination');
513
+ throw new TypeError(
514
+ 'Image, Texture or Window update only accepts a destination',
515
+ );
516
+ }
517
+ if (source instanceof Window && !source.isOpen()) {
518
+ return;
426
519
  }
427
- if (source instanceof Window && !source.isOpen()) return;
428
520
  const size = source.getSize();
429
521
  const x = sizeOrDest?.x ?? 0;
430
522
  const y = sizeOrDest?.y ?? 0;
431
523
  this.checkRegion(size.x, size.y, x, y);
432
524
  flushGraphics();
433
525
  if (source instanceof Image) {
434
- native.updateTextureImage(this[graphicsNative], source[graphicsNative],
435
- x, y);
526
+ native.updateTextureImage(
527
+ this[graphicsNative],
528
+ source[graphicsNative],
529
+ x,
530
+ y,
531
+ );
436
532
  } else if (source instanceof Window) {
437
- native.updateTextureWindow(this[graphicsNative], source[graphicsNative],
438
- x, y);
533
+ native.updateTextureWindow(
534
+ this[graphicsNative],
535
+ source[graphicsNative],
536
+ x,
537
+ y,
538
+ );
439
539
  } else {
440
- native.updateTextureTexture(this[graphicsNative], source[graphicsNative],
441
- x, y);
540
+ native.updateTextureTexture(
541
+ this[graphicsNative],
542
+ source[graphicsNative],
543
+ x,
544
+ y,
545
+ );
442
546
  }
443
547
  }
444
548
 
@@ -451,7 +555,9 @@ export class Texture {
451
555
  setSmooth(smooth: boolean): void {
452
556
  this.checkWritable();
453
557
  flag(smooth);
454
- if (smooth === this.state.smooth) return;
558
+ if (smooth === this.state.smooth) {
559
+ return;
560
+ }
455
561
  flushGraphics();
456
562
  native.setTextureSmooth(this[graphicsNative], smooth);
457
563
  }
@@ -476,7 +582,9 @@ export class Texture {
476
582
  setRepeated(repeated: boolean): void {
477
583
  this.checkWritable();
478
584
  flag(repeated);
479
- if (repeated === this.state.repeated) return;
585
+ if (repeated === this.state.repeated) {
586
+ return;
587
+ }
480
588
  flushGraphics();
481
589
  native.setTextureRepeated(this[graphicsNative], repeated);
482
590
  }
@@ -508,8 +616,12 @@ export class Texture {
508
616
  * @ko 텍스처가 읽기 전용으로 빌린 뷰이면 쓰기를 거부합니다.
509
617
  */
510
618
  private checkWritable(): void {
511
- if (this[textureOwner]) throw new TypeError('Cannot modify a RenderTexture texture view');
512
- if (this.resourceOwner) throw new TypeError('Cannot modify a Font texture view');
619
+ if (this[textureOwner]) {
620
+ throw new TypeError('Cannot modify a RenderTexture texture view');
621
+ }
622
+ if (this.resourceOwner) {
623
+ throw new TypeError('Cannot modify a Font texture view');
624
+ }
513
625
  }
514
626
 
515
627
  /**
@@ -519,10 +631,17 @@ export class Texture {
519
631
  * @ko 갱신 영역이 텍스처 범위 안에 있는지 검증합니다.
520
632
  */
521
633
  private checkRegion(
522
- width: number, height: number, x: number, y: number,
634
+ width: number,
635
+ height: number,
636
+ x: number,
637
+ y: number,
523
638
  ): void {
524
- if (x > this.state.width || y > this.state.height ||
525
- width > this.state.width - x || height > this.state.height - y) {
639
+ if (
640
+ x > this.state.width ||
641
+ y > this.state.height ||
642
+ width > this.state.width - x ||
643
+ height > this.state.height - y
644
+ ) {
526
645
  throw new RangeError('Update region is outside the texture');
527
646
  }
528
647
  }