sfml.js 1.0.0-rc.2 → 1.1.0

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 (314) hide show
  1. package/README.ja.md +16 -11
  2. package/README.ko.md +16 -11
  3. package/README.md +16 -11
  4. package/README.zh-CN.md +16 -11
  5. package/assets/breakout.png +0 -0
  6. package/binding.gyp +23 -16
  7. package/dist/audio/effect-processor.js +9 -3
  8. package/dist/audio/input-sound-file.js +41 -15
  9. package/dist/audio/listener.js +33 -11
  10. package/dist/audio/music.js +41 -18
  11. package/dist/audio/output-sound-file.js +4 -2
  12. package/dist/audio/playback-device.js +11 -3
  13. package/dist/audio/sound-buffer-recorder.js +8 -5
  14. package/dist/audio/sound-buffer.js +40 -17
  15. package/dist/audio/sound-file-factory.js +21 -9
  16. package/dist/audio/sound-file-reader.js +21 -7
  17. package/dist/audio/sound-recorder.js +36 -15
  18. package/dist/audio/sound-source.js +117 -40
  19. package/dist/audio/sound-stream.js +14 -5
  20. package/dist/audio/sound.js +9 -4
  21. package/dist/audio/value.js +42 -16
  22. package/dist/graphics/blend-mode.js +2 -1
  23. package/dist/graphics/boolean-vector.d.ts +1 -2
  24. package/dist/graphics/boolean-vector.js +19 -9
  25. package/dist/graphics/color.js +2 -1
  26. package/dist/graphics/convex-shape.js +7 -3
  27. package/dist/graphics/font.js +52 -23
  28. package/dist/graphics/glsl-matrix.js +8 -3
  29. package/dist/graphics/glsl.js +47 -16
  30. package/dist/graphics/glyph.js +27 -10
  31. package/dist/graphics/image.js +30 -14
  32. package/dist/graphics/rect.js +15 -8
  33. package/dist/graphics/render-states.js +18 -9
  34. package/dist/graphics/render-target.js +49 -23
  35. package/dist/graphics/render-texture.js +24 -12
  36. package/dist/graphics/render-window.js +6 -3
  37. package/dist/graphics/shader.js +67 -32
  38. package/dist/graphics/shape.js +25 -13
  39. package/dist/graphics/sprite.js +19 -9
  40. package/dist/graphics/stencil-mode.js +10 -6
  41. package/dist/graphics/swap.js +2 -1
  42. package/dist/graphics/text.js +123 -48
  43. package/dist/graphics/texture.js +48 -24
  44. package/dist/graphics/transform.js +29 -13
  45. package/dist/graphics/transformable.js +2 -1
  46. package/dist/graphics/vertex-array.js +40 -18
  47. package/dist/graphics/vertex-buffer.js +39 -19
  48. package/dist/graphics/vertex.js +6 -3
  49. package/dist/graphics/view.js +30 -14
  50. package/dist/index.d.ts +4 -4
  51. package/dist/internal/audio-codec-registry.js +12 -6
  52. package/dist/internal/audio-input-stream.js +2 -1
  53. package/dist/internal/audio-music-pump.js +58 -24
  54. package/dist/internal/audio-recorder-session.js +17 -7
  55. package/dist/internal/audio-worker-session.js +28 -10
  56. package/dist/internal/audio-worker.js +40 -21
  57. package/dist/internal/glsl-value.d.ts +3 -1
  58. package/dist/internal/glsl-value.js +18 -8
  59. package/dist/internal/graphics-state.js +29 -15
  60. package/dist/internal/input-stream.d.ts +3 -1
  61. package/dist/internal/input-stream.js +16 -7
  62. package/dist/internal/numeric-properties.js +2 -1
  63. package/dist/internal/render-states.js +2 -1
  64. package/dist/internal/scalar.js +22 -13
  65. package/dist/internal/shaped-glyph.d.ts +3 -1
  66. package/dist/internal/shaped-glyph.js +12 -4
  67. package/dist/internal/struct-view.d.ts +3 -1
  68. package/dist/internal/struct-view.js +3 -1
  69. package/dist/internal/transformable.js +2 -1
  70. package/dist/network/common.js +23 -11
  71. package/dist/network/dns.js +25 -17
  72. package/dist/network/ftp.js +43 -18
  73. package/dist/network/http.js +126 -56
  74. package/dist/network/ip-address.js +50 -25
  75. package/dist/network/packet.js +63 -25
  76. package/dist/network/sftp.js +175 -74
  77. package/dist/network/socket-selector.js +28 -14
  78. package/dist/network/socket.js +71 -30
  79. package/dist/network/tcp-listener.js +42 -19
  80. package/dist/network/tcp-socket.js +111 -53
  81. package/dist/network/tls-material.js +2 -1
  82. package/dist/network/udp-socket.js +68 -33
  83. package/dist/system/angle.js +2 -1
  84. package/dist/system/clock.js +4 -2
  85. package/dist/system/err.js +5 -2
  86. package/dist/system/file-input-stream.js +8 -4
  87. package/dist/system/input-stream.js +6 -3
  88. package/dist/system/operators.d.ts +1 -1
  89. package/dist/system/operators.js +90 -50
  90. package/dist/system/sleep.js +4 -2
  91. package/dist/system/time.js +12 -6
  92. package/dist/system/vector2.js +6 -7
  93. package/dist/system/vector3.js +11 -6
  94. package/dist/window/clipboard.js +2 -1
  95. package/dist/window/context.js +10 -5
  96. package/dist/window/cursor.js +2 -1
  97. package/dist/window/event.js +9 -5
  98. package/dist/window/mouse.js +4 -2
  99. package/dist/window/video-mode.js +2 -1
  100. package/dist/window/window.js +19 -12
  101. package/native/addon.cc +25 -12
  102. package/native/audio-binding.cc +266 -126
  103. package/native/audio-codec-binding.cc +147 -77
  104. package/native/audio-device-binding.cc +76 -49
  105. package/native/audio-file-binding.cc +116 -67
  106. package/native/audio-recorder-binding.cc +147 -98
  107. package/native/audio-recorder.h +1 -1
  108. package/native/audio-state.h +53 -30
  109. package/native/audio-stream-binding.cc +148 -94
  110. package/native/audio-stream.h +5 -4
  111. package/native/audio-worker-binding.cc +163 -81
  112. package/native/audio-worker.h +35 -19
  113. package/native/batch-drawable.cc +29 -16
  114. package/native/batch-drawable.h +11 -8
  115. package/native/context-binding.cc +40 -27
  116. package/native/context-settings.h +15 -8
  117. package/native/deferred-delete.cc +9 -6
  118. package/native/deferred-delete.h +7 -8
  119. package/native/error-stream-binding.cc +42 -28
  120. package/native/font-binding.cc +89 -48
  121. package/native/graphics-binding.cc +122 -72
  122. package/native/graphics-state.h +50 -36
  123. package/native/image-binding.cc +38 -24
  124. package/native/image-state.h +26 -18
  125. package/native/input-binding.cc +42 -27
  126. package/native/render-window-binding.cc +38 -23
  127. package/native/shader-binding.cc +115 -50
  128. package/native/shape-binding.cc +94 -49
  129. package/native/shape-state.h +18 -9
  130. package/native/shaped-glyph-storage.h +9 -5
  131. package/native/stream-binding.cc +143 -117
  132. package/native/system-binding.cc +17 -12
  133. package/native/text-binding.cc +68 -35
  134. package/native/text-state.h +25 -18
  135. package/native/texture-binding.cc +42 -33
  136. package/native/texture-resource.h +20 -12
  137. package/native/time-value.h +3 -1
  138. package/native/transformable-binding.cc +12 -6
  139. package/native/transformable-state.h +6 -6
  140. package/native/value-binding.h +46 -28
  141. package/native/value-layout.h +10 -10
  142. package/native/values-binding.cc +29 -23
  143. package/native/vertex-binding.cc +18 -12
  144. package/native/vertex-buffer-binding.cc +38 -24
  145. package/native/vertex-storage.h +2 -2
  146. package/native/view-data.h +4 -3
  147. package/native/window-binding.cc +75 -45
  148. package/native/window-event.h +20 -11
  149. package/native/window-owner.h +15 -12
  150. package/package.json +43 -50
  151. package/src/audio/effect-processor.ts +9 -3
  152. package/src/audio/input-sound-file.ts +108 -36
  153. package/src/audio/listener.ts +39 -13
  154. package/src/audio/music.ts +112 -47
  155. package/src/audio/output-sound-file.ts +40 -11
  156. package/src/audio/playback-device.ts +23 -8
  157. package/src/audio/sound-buffer-recorder.ts +35 -13
  158. package/src/audio/sound-buffer.ts +166 -58
  159. package/src/audio/sound-file-factory.ts +127 -49
  160. package/src/audio/sound-file-reader.ts +49 -15
  161. package/src/audio/sound-recorder.ts +100 -34
  162. package/src/audio/sound-source.ts +142 -45
  163. package/src/audio/sound-stream.ts +15 -5
  164. package/src/audio/sound.ts +12 -4
  165. package/src/audio/value.ts +89 -26
  166. package/src/graphics/blend-mode.ts +3 -1
  167. package/src/graphics/boolean-vector.ts +56 -26
  168. package/src/graphics/color.ts +3 -1
  169. package/src/graphics/convex-shape.ts +10 -3
  170. package/src/graphics/font.ts +171 -50
  171. package/src/graphics/glsl-matrix.ts +9 -3
  172. package/src/graphics/glsl.ts +81 -35
  173. package/src/graphics/glyph.ts +67 -26
  174. package/src/graphics/image.ts +119 -45
  175. package/src/graphics/rect.ts +56 -24
  176. package/src/graphics/render-states.ts +31 -14
  177. package/src/graphics/render-target.ts +197 -81
  178. package/src/graphics/render-texture.ts +36 -12
  179. package/src/graphics/render-window.ts +9 -3
  180. package/src/graphics/shader.ts +186 -61
  181. package/src/graphics/shape.ts +93 -35
  182. package/src/graphics/sprite.ts +64 -25
  183. package/src/graphics/stencil-mode.ts +12 -6
  184. package/src/graphics/swap.ts +3 -2
  185. package/src/graphics/text.ts +229 -74
  186. package/src/graphics/texture.ts +180 -61
  187. package/src/graphics/transform.ts +132 -47
  188. package/src/graphics/transformable.ts +3 -1
  189. package/src/graphics/vertex-array.ts +87 -35
  190. package/src/graphics/vertex-buffer.ts +97 -33
  191. package/src/graphics/vertex.ts +9 -3
  192. package/src/graphics/view.ts +59 -21
  193. package/src/index.ts +101 -23
  194. package/src/internal/audio-codec-registry.ts +18 -6
  195. package/src/internal/audio-input-stream.ts +6 -2
  196. package/src/internal/audio-music-pump.ts +116 -41
  197. package/src/internal/audio-native.ts +249 -96
  198. package/src/internal/audio-recorder-session.ts +68 -24
  199. package/src/internal/audio-worker-session.ts +65 -21
  200. package/src/internal/audio-worker.ts +85 -41
  201. package/src/internal/glsl-value.ts +26 -11
  202. package/src/internal/graphics-state.ts +57 -20
  203. package/src/internal/input-stream.ts +23 -10
  204. package/src/internal/native.ts +252 -99
  205. package/src/internal/numeric-properties.ts +2 -1
  206. package/src/internal/render-states.ts +3 -1
  207. package/src/internal/scalar.ts +33 -14
  208. package/src/internal/shaped-glyph.ts +25 -12
  209. package/src/internal/struct-view.ts +40 -13
  210. package/src/internal/transformable.ts +3 -1
  211. package/src/network/common.ts +35 -11
  212. package/src/network/dns.ts +95 -38
  213. package/src/network/ftp.ts +129 -47
  214. package/src/network/http.ts +232 -77
  215. package/src/network/ip-address.ts +118 -48
  216. package/src/network/packet.ts +161 -54
  217. package/src/network/sftp.ts +498 -168
  218. package/src/network/socket-selector.ts +66 -26
  219. package/src/network/socket.ts +133 -46
  220. package/src/network/tcp-listener.ts +78 -29
  221. package/src/network/tcp-socket.ts +240 -95
  222. package/src/network/tls-material.ts +6 -2
  223. package/src/network/udp-socket.ts +147 -53
  224. package/src/system/angle.ts +3 -1
  225. package/src/system/clock.ts +12 -4
  226. package/src/system/err.ts +5 -2
  227. package/src/system/file-input-stream.ts +12 -4
  228. package/src/system/input-stream.ts +9 -3
  229. package/src/system/operators.ts +290 -115
  230. package/src/system/sleep.ts +6 -2
  231. package/src/system/time.ts +18 -6
  232. package/src/system/timeout-with-predicate.ts +19 -8
  233. package/src/system/vector2.ts +101 -49
  234. package/src/system/vector3.ts +85 -36
  235. package/src/window/clipboard.ts +3 -1
  236. package/src/window/context.ts +15 -5
  237. package/src/window/cursor.ts +3 -1
  238. package/src/window/event.ts +26 -12
  239. package/src/window/mouse.ts +6 -2
  240. package/src/window/video-mode.ts +3 -1
  241. package/src/window/window.ts +119 -37
  242. package/test/native/audio-probes.cc +74 -36
  243. package/test/native/deferred-delete-probes.cc +17 -11
  244. package/test/native/drawable-probes.cc +70 -36
  245. package/test/native/exception-probes.cc +14 -9
  246. package/test/native/image-probes.cc +20 -10
  247. package/test/native/matrix-probes.cc +8 -4
  248. package/test/native/network-oracle.cc +17 -11
  249. package/test/native/render-texture-probes.cc +33 -24
  250. package/test/native/shader-probes.cc +9 -9
  251. package/test/native/shape-probes.cc +37 -23
  252. package/test/native/sprite-probes.cc +41 -25
  253. package/test/native/system-probes.cc +58 -35
  254. package/test/native/text-probes.cc +77 -44
  255. package/test/native/texture-probes.cc +43 -26
  256. package/test/native/time-probes.cc +18 -12
  257. package/test/native/transform-probes.cc +15 -10
  258. package/test/native/transformable-probes.cc +23 -17
  259. package/test/native/value-oracle.h +9 -4
  260. package/test/native/value-probes.cc +31 -23
  261. package/test/native/vertex-array-probes.cc +22 -14
  262. package/test/native/vertex-buffer-probes.cc +28 -17
  263. package/test/native/view-probes.cc +29 -17
  264. package/test/native/window-probes.cc +66 -33
  265. package/tools/ensure-sfml.cjs +9 -0
  266. package/tools/generate-network-constants.cjs +11 -6
  267. package/tools/generate-window-constants.cjs +31 -12
  268. package/docs/README.ja.md +0 -30
  269. package/docs/README.ko.md +0 -30
  270. package/docs/README.md +0 -30
  271. package/docs/README.zh-CN.md +0 -30
  272. package/docs/api.ja.md +0 -84
  273. package/docs/api.ko.md +0 -84
  274. package/docs/api.md +0 -81
  275. package/docs/api.zh-CN.md +0 -81
  276. package/docs/audio.ja.md +0 -249
  277. package/docs/audio.ko.md +0 -251
  278. package/docs/audio.md +0 -252
  279. package/docs/audio.zh-CN.md +0 -252
  280. package/docs/concepts.ja.md +0 -130
  281. package/docs/concepts.ko.md +0 -130
  282. package/docs/concepts.md +0 -131
  283. package/docs/concepts.zh-CN.md +0 -131
  284. package/docs/development.ja.md +0 -148
  285. package/docs/development.ko.md +0 -148
  286. package/docs/development.md +0 -150
  287. package/docs/development.zh-CN.md +0 -150
  288. package/docs/getting-started.ja.md +0 -154
  289. package/docs/getting-started.ko.md +0 -154
  290. package/docs/getting-started.md +0 -156
  291. package/docs/getting-started.zh-CN.md +0 -156
  292. package/docs/graphics.ja.md +0 -256
  293. package/docs/graphics.ko.md +0 -254
  294. package/docs/graphics.md +0 -255
  295. package/docs/graphics.zh-CN.md +0 -257
  296. package/docs/network.ja.md +0 -214
  297. package/docs/network.ko.md +0 -216
  298. package/docs/network.md +0 -218
  299. package/docs/network.zh-CN.md +0 -218
  300. package/docs/system.ja.md +0 -169
  301. package/docs/system.ko.md +0 -171
  302. package/docs/system.md +0 -173
  303. package/docs/system.zh-CN.md +0 -173
  304. package/docs/window.ja.md +0 -138
  305. package/docs/window.ko.md +0 -140
  306. package/docs/window.md +0 -141
  307. package/docs/window.zh-CN.md +0 -141
  308. package/native/exception-boundary.h +0 -97
  309. package/native/numeric-fields.h +0 -96
  310. package/native/shared-handle.h +0 -69
  311. package/test/tsconfig.json +0 -8
  312. package/tools/configure-lsp.cjs +0 -23
  313. package/tools/lib_downloader.cjs +0 -92
  314. package/tools/lib_downloader_urls.cjs +0 -23
@@ -1,11 +1,21 @@
1
1
  import {
2
- native, type NativeGraphicsHandle, type NativeVertexBufferInfo,
2
+ native,
3
+ type NativeGraphicsHandle,
4
+ type NativeVertexBufferInfo,
3
5
  } from '../internal/native';
4
6
  import {
5
- dispatchDrawable, flushGraphics, graphicsContext, graphicsNative,
6
- recordVertexBuffer, vertexArrayBytes, vertexBufferId,
7
+ dispatchDrawable,
8
+ flushGraphics,
9
+ graphicsContext,
10
+ graphicsNative,
11
+ recordVertexBuffer,
12
+ vertexArrayBytes,
13
+ vertexBufferId,
7
14
  } from '../internal/graphics-state';
8
- import { vertexStorage, type ReadonlyValue } from '../internal/value-storage';
15
+ import {
16
+ vertexStorage,
17
+ type ReadonlyValue,
18
+ } from '../internal/value-storage';
9
19
  import { nativeStruct } from '../internal/struct-view';
10
20
  import { Drawable } from './drawable';
11
21
  import { PrimitiveType, validatePrimitiveType } from './primitive-type';
@@ -45,19 +55,26 @@ export enum VertexBufferUsage {
45
55
  }
46
56
 
47
57
  const usages = [
48
- VertexBufferUsage.Stream, VertexBufferUsage.Dynamic, VertexBufferUsage.Static,
58
+ VertexBufferUsage.Stream,
59
+ VertexBufferUsage.Dynamic,
60
+ VertexBufferUsage.Static,
49
61
  ];
50
62
  type Vertices = VertexArray | readonly ReadonlyValue<Vertex>[];
51
63
 
52
64
  function usageIndex(usage: VertexBufferUsage): number {
53
65
  const index = usages.indexOf(usage);
54
- if (index === -1) throw new RangeError('Invalid vertex buffer usage');
66
+ if (index === -1) {
67
+ throw new RangeError('Invalid vertex buffer usage');
68
+ }
55
69
  return index;
56
70
  }
57
71
 
58
72
  function validateCount(count: number): void {
59
- if (!Number.isInteger(count) || count < 0 ||
60
- count > Math.floor(0x7fffffff / 20)) {
73
+ if (
74
+ !Number.isInteger(count) ||
75
+ count < 0 ||
76
+ count > Math.floor(0x7fffffff / 20)
77
+ ) {
61
78
  throw new RangeError('Vertex count exceeds the buffer limit');
62
79
  }
63
80
  }
@@ -123,18 +140,31 @@ export class VertexBuffer extends Drawable {
123
140
  */
124
141
  constructor(source: VertexBuffer);
125
142
  constructor(
126
- source: PrimitiveType | VertexBufferUsage | VertexBuffer = PrimitiveType.Points,
143
+ source:
144
+ | PrimitiveType
145
+ | VertexBufferUsage
146
+ | VertexBuffer = PrimitiveType.Points,
127
147
  usage = VertexBufferUsage.Stream,
128
148
  ) {
129
149
  super();
130
150
  const copy = source instanceof VertexBuffer ? source : undefined;
131
- const type = copy ? copy.getPrimitiveType()
132
- : typeof source === 'string' ? PrimitiveType.Points : source as PrimitiveType;
133
- const selectedUsage = copy ? copy.getUsage()
134
- : typeof source === 'string' ? source : usage;
151
+ const type = copy
152
+ ? copy.getPrimitiveType()
153
+ : typeof source === 'string'
154
+ ? PrimitiveType.Points
155
+ : (source as PrimitiveType);
156
+ const selectedUsage = copy
157
+ ? copy.getUsage()
158
+ : typeof source === 'string'
159
+ ? source
160
+ : usage;
135
161
  validatePrimitiveType(type);
136
162
  const mapping = native.createVertexBuffer(
137
- graphicsContext(), type, usageIndex(selectedUsage), copy?.[graphicsNative]);
163
+ graphicsContext(),
164
+ type,
165
+ usageIndex(selectedUsage),
166
+ copy?.[graphicsNative],
167
+ );
138
168
  this[graphicsNative] = mapping.handle;
139
169
  this[vertexBufferId] = mapping.id;
140
170
  this.info = nativeStruct<NativeVertexBufferInfo>(mapping.info);
@@ -150,8 +180,10 @@ export class VertexBuffer extends Drawable {
150
180
  create(vertexCount: number): boolean {
151
181
  validateCount(vertexCount);
152
182
  flushGraphics();
153
- return native.allocateVertexBuffer(
154
- this[graphicsNative], vertexCount) !== undefined;
183
+ return (
184
+ native.allocateVertexBuffer(this[graphicsNative], vertexCount) !==
185
+ undefined
186
+ );
155
187
  }
156
188
 
157
189
  /**
@@ -187,15 +219,22 @@ export class VertexBuffer extends Drawable {
187
219
  * @ko source의 GPU 꼭짓점 데이터를 복사하고 성공 여부를 반환합니다.
188
220
  */
189
221
  update(source: VertexBuffer): boolean;
190
- update(source: Vertices | VertexBuffer, vertexCount?: number,
191
- offset = 0): boolean {
222
+ update(
223
+ source: Vertices | VertexBuffer,
224
+ vertexCount?: number,
225
+ offset = 0,
226
+ ): boolean {
192
227
  if (source instanceof VertexBuffer) {
193
228
  if (vertexCount !== undefined) {
194
229
  throw new TypeError('Buffer copies do not accept a vertex range');
195
230
  }
196
231
  flushGraphics();
197
- return native.copyVertexBuffer(
198
- this[graphicsNative], source[graphicsNative]) !== undefined;
232
+ return (
233
+ native.copyVertexBuffer(
234
+ this[graphicsNative],
235
+ source[graphicsNative],
236
+ ) !== undefined
237
+ );
199
238
  }
200
239
  const count = vertexCount ?? this.info.count;
201
240
  validateCount(count);
@@ -209,22 +248,39 @@ export class VertexBuffer extends Drawable {
209
248
  throw new RangeError('Not enough source vertices');
210
249
  }
211
250
  } else {
212
- if (!Array.isArray(source)) throw new TypeError('Expected vertex data');
213
- if (count > source.length) throw new RangeError('Not enough source vertices');
251
+ if (!Array.isArray(source)) {
252
+ throw new TypeError('Expected vertex data');
253
+ }
254
+ if (count > source.length) {
255
+ throw new RangeError('Not enough source vertices');
256
+ }
214
257
  bytes = new Uint8Array(count * 20);
215
258
  for (let i = 0; i < count; i++) {
216
259
  const vertex = source[i];
217
- if (!(vertex instanceof Vertex) || vertex[vertexStorage].byteLength !== 20) {
260
+ if (
261
+ !(vertex instanceof Vertex) ||
262
+ vertex[vertexStorage].byteLength !== 20
263
+ ) {
218
264
  throw new TypeError('Expected attached Vertex values');
219
265
  }
220
266
  bytes.set(vertex[vertexStorage], i * 20);
221
267
  }
222
268
  }
223
- if (!this.info.nativeHandle ||
224
- (offset !== 0 && offset + count > this.info.count)) return false;
269
+ if (
270
+ !this.info.nativeHandle ||
271
+ (offset !== 0 && offset + count > this.info.count)
272
+ ) {
273
+ return false;
274
+ }
225
275
  flushGraphics();
226
- return native.updateVertexBuffer(
227
- this[graphicsNative], bytes, count, offset) !== undefined;
276
+ return (
277
+ native.updateVertexBuffer(
278
+ this[graphicsNative],
279
+ bytes,
280
+ count,
281
+ offset,
282
+ ) !== undefined
283
+ );
228
284
  }
229
285
 
230
286
  /**
@@ -235,8 +291,12 @@ export class VertexBuffer extends Drawable {
235
291
  * @ko 두 버퍼의 데이터와 설정을 교환합니다. 스냅샷 의미를 유지하기 위해 대기 중인 그리기를 먼저 제출합니다.
236
292
  */
237
293
  swap(other: VertexBuffer): void {
238
- if (!(other instanceof VertexBuffer)) throw new TypeError('Expected a VertexBuffer');
239
- if (other === this) return;
294
+ if (!(other instanceof VertexBuffer)) {
295
+ throw new TypeError('Expected a VertexBuffer');
296
+ }
297
+ if (other === this) {
298
+ return;
299
+ }
240
300
  flushGraphics();
241
301
  native.swapVertexBuffers(this[graphicsNative], other[graphicsNative]);
242
302
  }
@@ -252,7 +312,9 @@ export class VertexBuffer extends Drawable {
252
312
  if (!(source instanceof VertexBuffer)) {
253
313
  throw new TypeError('Expected a VertexBuffer');
254
314
  }
255
- if (source === this) return this;
315
+ if (source === this) {
316
+ return this;
317
+ }
256
318
  flushGraphics();
257
319
  native.assignVertexBuffer(this[graphicsNative], source[graphicsNative]);
258
320
  return this;
@@ -338,8 +400,10 @@ export class VertexBuffer extends Drawable {
338
400
  }
339
401
 
340
402
  [dispatchDrawable](target: RenderTarget, states: RenderStates): void {
341
- if (this.draw === VertexBuffer.prototype.draw) this.draw(target, states);
342
- else super[dispatchDrawable](target, states);
403
+ if (this.draw === VertexBuffer.prototype.draw) {
404
+ this.draw(target, states);
405
+ } else {
406
+ super[dispatchDrawable](target, states);
407
+ }
343
408
  }
344
-
345
409
  }
@@ -93,7 +93,9 @@ export class Vertex {
93
93
  constructor(...args: VertexArguments) {
94
94
  this.coordinates = new Float32Array(this.state.values.buffer);
95
95
  this.state.values.fill(255, 8, 12);
96
- if (args.length === 0) return;
96
+ if (args.length === 0) {
97
+ return;
98
+ }
97
99
  const source = args[0];
98
100
  if (source instanceof Vertex && args.length === 1) {
99
101
  // Copy bytes so RGBA and floating-point bit patterns remain intact.
@@ -104,8 +106,12 @@ export class Vertex {
104
106
  throw new TypeError('Vertex requires a Vertex or a Vector2f position');
105
107
  }
106
108
  this.position = source;
107
- if (args[1] !== undefined) this.color = args[1];
108
- if (args[2] !== undefined) this.texCoords = args[2];
109
+ if (args[1] !== undefined) {
110
+ this.color = args[1];
111
+ }
112
+ if (args[2] !== undefined) {
113
+ this.texCoords = args[2];
114
+ }
109
115
  }
110
116
 
111
117
  get [vertexStorage](): Uint8Array {
@@ -1,5 +1,8 @@
1
1
  import {
2
- mutableValue, rectStorage, transformStorage, type ReadonlyValue as R,
2
+ mutableValue,
3
+ rectStorage,
4
+ transformStorage,
5
+ type ReadonlyValue as R,
3
6
  } from '../internal/value-storage';
4
7
  import { Angle, radians } from '../system/angle';
5
8
  import { Vector2, Vector2f } from '../system/vector2';
@@ -15,7 +18,9 @@ function vector(value: R<Vector2f>): void {
15
18
  }
16
19
 
17
20
  function rectangle(value: R<FloatRect>): void {
18
- if (!(value instanceof FloatRect)) throw new TypeError('Expected a FloatRect');
21
+ if (!(value instanceof FloatRect)) {
22
+ throw new TypeError('Expected a FloatRect');
23
+ }
19
24
  }
20
25
 
21
26
  function constantRectangle(): R<FloatRect> {
@@ -24,15 +29,18 @@ function constantRectangle(): R<FloatRect> {
24
29
  const position = result.position;
25
30
  const size = result.size;
26
31
  Object.defineProperties(position, {
27
- x: { get: () => data[0] }, y: { get: () => data[1] },
32
+ x: { get: () => data[0] },
33
+ y: { get: () => data[1] },
28
34
  });
29
35
  Object.defineProperties(size, {
30
- x: { get: () => data[2] }, y: { get: () => data[3] },
36
+ x: { get: () => data[2] },
37
+ y: { get: () => data[3] },
31
38
  });
32
39
  Object.freeze(position);
33
40
  Object.freeze(size);
34
41
  Object.defineProperties(result, {
35
- position: { value: position }, size: { value: size },
42
+ position: { value: position },
43
+ size: { value: size },
36
44
  });
37
45
  return Object.freeze(result);
38
46
  }
@@ -51,7 +59,9 @@ export let copyView: (destination: R<View>, source: R<View>) => void;
51
59
  * @ko 내부 명령 인코딩 순서는 중심, 크기, 라디안, 뷰포트, 시저입니다.
52
60
  */
53
61
  export let writeView: (
54
- source: R<View>, destination: Float32Array, offset: number,
62
+ source: R<View>,
63
+ destination: Float32Array,
64
+ offset: number,
55
65
  ) => void;
56
66
 
57
67
  /**
@@ -79,12 +89,18 @@ export class View {
79
89
  }
80
90
  destination.state.data.set(source.state.data);
81
91
  destination.state.viewport[rectStorage].set(
82
- source.state.viewport[rectStorage]);
83
- destination.state.scissor[rectStorage].set(source.state.scissor[rectStorage]);
84
- destination.state.transformDirty = destination.state.inverseDirty = true;
92
+ source.state.viewport[rectStorage],
93
+ );
94
+ destination.state.scissor[rectStorage].set(
95
+ source.state.scissor[rectStorage],
96
+ );
97
+ destination.state.transformDirty =
98
+ destination.state.inverseDirty = true;
85
99
  };
86
100
  writeView = (source, destination, offset) => {
87
- if (!(source instanceof View)) throw new TypeError('Expected a View');
101
+ if (!(source instanceof View)) {
102
+ throw new TypeError('Expected a View');
103
+ }
88
104
  destination.set(source.state.data, offset);
89
105
  destination.set(source.state.viewport[rectStorage], offset + 5);
90
106
  destination.set(source.state.scissor[rectStorage], offset + 9);
@@ -120,9 +136,13 @@ export class View {
120
136
  * @ko 월드 좌표의 중심과 크기로 뷰를 만듭니다.
121
137
  */
122
138
  constructor(center: R<Vector2f>, size: R<Vector2f>);
123
- constructor(source?: R<View> | R<FloatRect> | R<Vector2f>, size?: R<Vector2f>) {
124
- if (source instanceof View && size === undefined) copyView(this, source);
125
- else if (source instanceof FloatRect && size === undefined) {
139
+ constructor(
140
+ source?: R<View> | R<FloatRect> | R<Vector2f>,
141
+ size?: R<Vector2f>,
142
+ ) {
143
+ if (source instanceof View && size === undefined) {
144
+ copyView(this, source);
145
+ } else if (source instanceof FloatRect && size === undefined) {
126
146
  this.setCenter(source.getCenter());
127
147
  this.setSize(source.size);
128
148
  } else if (source !== undefined && size !== undefined) {
@@ -189,7 +209,9 @@ export class View {
189
209
  */
190
210
  setRotation(this: View, angle: R<Angle>): void {
191
211
  this.checkWritable();
192
- if (!(angle instanceof Angle)) throw new TypeError('Expected an Angle');
212
+ if (!(angle instanceof Angle)) {
213
+ throw new TypeError('Expected an Angle');
214
+ }
193
215
  this.state.data[4] = angle.wrapUnsigned().asRadians();
194
216
  this.invalidate();
195
217
  }
@@ -239,9 +261,18 @@ export class View {
239
261
  this.checkWritable();
240
262
  rectangle(scissor);
241
263
  const [ x, y, width, height ] = scissor[rectStorage];
242
- if (!(x >= 0 && y >= 0 && x <= 1 && y <= 1 &&
243
- width >= 0 && height >= 0 &&
244
- f(x + width) <= 1 && f(y + height) <= 1)) {
264
+ if (
265
+ !(
266
+ x >= 0 &&
267
+ y >= 0 &&
268
+ x <= 1 &&
269
+ y <= 1 &&
270
+ width >= 0 &&
271
+ height >= 0 &&
272
+ f(x + width) <= 1 &&
273
+ f(y + height) <= 1
274
+ )
275
+ ) {
245
276
  throw new RangeError('Scissor rectangle must lie within [0, 1]');
246
277
  }
247
278
  this.state.scissor[rectStorage].set(scissor[rectStorage]);
@@ -279,7 +310,9 @@ export class View {
279
310
  * @ko 현재 뷰 각도에 angle을 더합니다.
280
311
  */
281
312
  rotate(this: View, angle: R<Angle>): void {
282
- if (!(angle instanceof Angle)) throw new TypeError('Expected an Angle');
313
+ if (!(angle instanceof Angle)) {
314
+ throw new TypeError('Expected an Angle');
315
+ }
283
316
  this.setRotation(radians(f(this.state.data[4] + angle.asRadians())));
284
317
  }
285
318
 
@@ -292,7 +325,9 @@ export class View {
292
325
  */
293
326
  zoom(this: View, factor: number): void {
294
327
  this.checkWritable();
295
- if (typeof factor !== 'number') throw new TypeError('Expected a number');
328
+ if (typeof factor !== 'number') {
329
+ throw new TypeError('Expected a number');
330
+ }
296
331
  const value = f(factor);
297
332
  this.state.data[2] *= value;
298
333
  this.state.data[3] *= value;
@@ -339,7 +374,8 @@ export class View {
339
374
  const state = this.state;
340
375
  if (state.inverseDirty) {
341
376
  state.inverse[transformStorage].set(
342
- this.getTransform().getInverse()[transformStorage]);
377
+ this.getTransform().getInverse()[transformStorage],
378
+ );
343
379
  state.inverseDirty = false;
344
380
  }
345
381
  return state.inverse;
@@ -350,6 +386,8 @@ export class View {
350
386
  }
351
387
 
352
388
  private checkWritable(): void {
353
- if (Object.isFrozen(this)) throw new TypeError('Cannot modify a const View');
389
+ if (Object.isFrozen(this)) {
390
+ throw new TypeError('Cannot modify a const View');
391
+ }
354
392
  }
355
393
  }
package/src/index.ts CHANGED
@@ -7,23 +7,47 @@ export type { PacketValues, PacketType } from './network/packet';
7
7
  export { Socket, SocketStatus, SocketType } from './network/socket';
8
8
  export type { SocketHandle } from './network/socket';
9
9
  export { TcpSocket, TlsStatus } from './network/tcp-socket';
10
- export type { SocketTransfer, SocketSendResult } from './network/tcp-socket';
10
+ export type {
11
+ SocketTransfer,
12
+ SocketSendResult,
13
+ } from './network/tcp-socket';
11
14
  export { TcpListener } from './network/tcp-listener';
12
15
  export { UdpSocket } from './network/udp-socket';
13
16
  export type { DatagramResult } from './network/udp-socket';
14
17
  export { SocketSelector, ReadinessType } from './network/socket-selector';
15
18
  export type { ReadyCallback } from './network/socket-selector';
16
- export { Http, HttpRequest, HttpResponse, HttpMethod, HttpStatus } from './network/http';
17
19
  export {
18
- Ftp, FtpResponse, FtpDirectoryResponse, FtpListingResponse, FtpStatus, TransferMode,
20
+ Http,
21
+ HttpRequest,
22
+ HttpResponse,
23
+ HttpMethod,
24
+ HttpStatus,
25
+ } from './network/http';
26
+ export {
27
+ Ftp,
28
+ FtpResponse,
29
+ FtpDirectoryResponse,
30
+ FtpListingResponse,
31
+ FtpStatus,
32
+ TransferMode,
19
33
  } from './network/ftp';
20
34
  export {
21
- Sftp, SftpResult, SftpPathResult, SftpAttributesResult, SftpListingResult,
22
- SftpResultValue, SftpHostKeyType, FileType,
35
+ Sftp,
36
+ SftpResult,
37
+ SftpPathResult,
38
+ SftpAttributesResult,
39
+ SftpListingResult,
40
+ SftpResultValue,
41
+ SftpHostKeyType,
42
+ FileType,
23
43
  } from './network/sftp';
24
44
  export type {
25
- SftpAttributes, SftpSessionInfo, SftpTimeout, SftpDownloadCallback,
26
- SftpUploadCallback, SftpUploadChunk,
45
+ SftpAttributes,
46
+ SftpSessionInfo,
47
+ SftpTimeout,
48
+ SftpDownloadCallback,
49
+ SftpUploadCallback,
50
+ SftpUploadChunk,
27
51
  } from './network/sftp';
28
52
  export { SoundBuffer } from './audio/sound-buffer';
29
53
  export type { ReadonlySoundBuffer } from './audio/sound-buffer';
@@ -34,23 +58,39 @@ export { SoundBufferRecorder } from './audio/sound-buffer-recorder';
34
58
  export { EffectProcessor } from './audio/effect-processor';
35
59
  export type { EffectProcessorOptions } from './audio/effect-processor';
36
60
  export type {
37
- AudioWorkerModule, AudioWorkerOptions, AudioWorkerContext, AudioWorkerStats,
38
- SoundStreamOptions, SoundStreamChunk, SoundStreamCallbacks,
39
- SoundRecorderCallbacks, EffectFrames, EffectProcessorCallbacks,
61
+ AudioWorkerModule,
62
+ AudioWorkerOptions,
63
+ AudioWorkerContext,
64
+ AudioWorkerStats,
65
+ SoundStreamOptions,
66
+ SoundStreamChunk,
67
+ SoundStreamCallbacks,
68
+ SoundRecorderCallbacks,
69
+ EffectFrames,
70
+ EffectProcessorCallbacks,
40
71
  } from './audio/worker';
41
72
  export { Sound } from './audio/sound';
42
73
  export { Music } from './audio/music';
43
74
  export { InputSoundFile } from './audio/input-sound-file';
44
75
  export { OutputSoundFile } from './audio/output-sound-file';
45
- export { SoundFileReader, SoundFileReaderInfo } from './audio/sound-file-reader';
76
+ export {
77
+ SoundFileReader,
78
+ SoundFileReaderInfo,
79
+ } from './audio/sound-file-reader';
46
80
  export type {
47
- SoundFileReaderInfoInput, SoundFileReaderConstructor,
81
+ SoundFileReaderInfoInput,
82
+ SoundFileReaderConstructor,
48
83
  } from './audio/sound-file-reader';
49
84
  export { SoundFileWriter } from './audio/sound-file-writer';
50
85
  export type { SoundFileWriterConstructor } from './audio/sound-file-writer';
51
86
  export { SoundFileFactory } from './audio/sound-file-factory';
52
87
  export { Cone, TimeSpan, SoundChannel, SoundStatus } from './audio/value';
53
- export type { ConeInput, TimeSpanInput, ReadonlySamples, ChannelMap } from './audio/value';
88
+ export type {
89
+ ConeInput,
90
+ TimeSpanInput,
91
+ ReadonlySamples,
92
+ ChannelMap,
93
+ } from './audio/value';
54
94
  export * as Listener from './audio/listener';
55
95
  export * as PlaybackDevice from './audio/playback-device';
56
96
  export { err, setErrorOutput } from './system/err';
@@ -85,16 +125,34 @@ export * as Sensor from './window/sensor';
85
125
  export * as Clipboard from './window/clipboard';
86
126
  export * as Touch from './window/touch';
87
127
  export type {
88
- EventKind, EventData, EventPayloads, EventHandlers, EventVisitor,
128
+ EventKind,
129
+ EventData,
130
+ EventPayloads,
131
+ EventHandlers,
132
+ EventVisitor,
89
133
  } from './window/event';
90
134
  export * from './window/gen/constants';
91
135
  export { ContextAttribute } from './window/context-settings';
92
136
  export type { ContextSettings } from './window/context-settings';
93
137
  export type { ReadonlyValue } from './internal/value-storage';
94
138
  export {
95
- add, subtract, negate, addAssign, subtractAssign,
96
- multiply, multiplyAssign, divide, divideAssign, modulo, moduloAssign,
97
- equal, notEqual, less, lessEqual, greater, greaterEqual,
139
+ add,
140
+ subtract,
141
+ negate,
142
+ addAssign,
143
+ subtractAssign,
144
+ multiply,
145
+ multiplyAssign,
146
+ divide,
147
+ divideAssign,
148
+ modulo,
149
+ moduloAssign,
150
+ equal,
151
+ notEqual,
152
+ less,
153
+ lessEqual,
154
+ greater,
155
+ greaterEqual,
98
156
  } from './system/operators';
99
157
  export { Texture } from './graphics/texture';
100
158
  export type { ReadonlyTexture } from './graphics/texture';
@@ -105,10 +163,18 @@ export { Font } from './graphics/font';
105
163
  export type { FontInfo, ReadonlyFont } from './graphics/font';
106
164
  export { Glyph } from './graphics/glyph';
107
165
  export {
108
- Text, TextStyle, LineAlignment, ClusterGrouping, TextDirection, TextOrientation,
166
+ Text,
167
+ TextStyle,
168
+ LineAlignment,
169
+ ClusterGrouping,
170
+ TextDirection,
171
+ TextOrientation,
109
172
  } from './graphics/text';
110
173
  export type {
111
- TextOptions, ShapedGlyph, GlyphAppearance, GlyphPreProcessor,
174
+ TextOptions,
175
+ ShapedGlyph,
176
+ GlyphAppearance,
177
+ GlyphPreProcessor,
112
178
  } from './graphics/text';
113
179
  export type { ReadonlyPixels } from './graphics/image';
114
180
  export { Color } from './graphics/color';
@@ -132,14 +198,26 @@ export { Drawable } from './graphics/drawable';
132
198
  export { RenderTarget } from './graphics/render-target';
133
199
  export { RenderStates, CoordinateType } from './graphics/render-states';
134
200
  export type {
135
- RenderStatesInput, RenderStatesOptions, ReadonlyRenderStates,
201
+ RenderStatesInput,
202
+ RenderStatesOptions,
203
+ ReadonlyRenderStates,
136
204
  } from './graphics/render-states';
137
205
  export {
138
- BlendMode, BlendFactor, BlendEquation,
139
- BlendAlpha, BlendAdd, BlendMultiply, BlendMin, BlendMax, BlendNone,
206
+ BlendMode,
207
+ BlendFactor,
208
+ BlendEquation,
209
+ BlendAlpha,
210
+ BlendAdd,
211
+ BlendMultiply,
212
+ BlendMin,
213
+ BlendMax,
214
+ BlendNone,
140
215
  } from './graphics/blend-mode';
141
216
  export {
142
- StencilMode, StencilValue, StencilComparison, StencilUpdateOperation,
217
+ StencilMode,
218
+ StencilValue,
219
+ StencilComparison,
220
+ StencilUpdateOperation,
143
221
  } from './graphics/stencil-mode';
144
222
  export type { StencilModeOptions } from './graphics/stencil-mode';
145
223
  export { RenderTexture } from './graphics/render-texture';
@@ -14,13 +14,17 @@ export async function findAudioReader(
14
14
  stream: InputStream,
15
15
  ): Promise<SoundFileReader | undefined> {
16
16
  for (const Reader of [ ...audioReaders ].reverse()) {
17
- if (await stream.seek(0n) !== 0n) return undefined;
17
+ if (await stream.seek(0n) !== 0n) {
18
+ return undefined;
19
+ }
18
20
  const matches = await Reader.check(stream);
19
21
  if (typeof matches !== 'boolean') {
20
22
  throw new TypeError('Reader.check must return a boolean');
21
23
  }
22
24
  if (matches) {
23
- if (await stream.seek(0n) !== 0n) return undefined;
25
+ if (await stream.seek(0n) !== 0n) {
26
+ return undefined;
27
+ }
24
28
  return new Reader();
25
29
  }
26
30
  }
@@ -36,7 +40,9 @@ export async function findAudioWriter(
36
40
  if (typeof matches !== 'boolean') {
37
41
  throw new TypeError('Writer.check must return a boolean');
38
42
  }
39
- if (matches) return new Writer();
43
+ if (matches) {
44
+ return new Writer();
45
+ }
40
46
  }
41
47
  return undefined;
42
48
  }
@@ -46,19 +52,25 @@ export async function findAudioReaderInput(
46
52
  ): Promise<{
47
53
  reader: SoundFileReader; stream: InputStream; owned?: FileInputStream;
48
54
  } | undefined> {
49
- if (!audioReaders.size) return undefined;
55
+ if (!audioReaders.size) {
56
+ return undefined;
57
+ }
50
58
  let owned: FileInputStream | undefined;
51
59
  let stream: InputStream;
52
60
  if (typeof input === 'string') {
53
61
  owned = new FileInputStream();
54
- if (!await owned.open(input)) return undefined;
62
+ if (!await owned.open(input)) {
63
+ return undefined;
64
+ }
55
65
  stream = owned;
56
66
  } else {
57
67
  stream = input instanceof Uint8Array ? new MemoryInputStream(input) : input;
58
68
  }
59
69
  try {
60
70
  const reader = await findAudioReader(stream);
61
- if (reader) return { reader, stream, owned };
71
+ if (reader) {
72
+ return { reader, stream, owned };
73
+ }
62
74
  } catch (error) {
63
75
  await owned?.close();
64
76
  throw error;
@@ -26,8 +26,12 @@ export class AudioInputStream {
26
26
  }
27
27
  async run<T>(action: () => Promise<T>): Promise<T> {
28
28
  this.failure.failed = false;
29
- try { return await action(); } catch (error) {
30
- if (this.failure.failed) throw this.failure.error;
29
+ try {
30
+ return await action();
31
+ } catch (error) {
32
+ if (this.failure.failed) {
33
+ throw this.failure.error;
34
+ }
31
35
  if (this.closed && error instanceof Error &&
32
36
  error.message === 'Audio InputStream closed') {
33
37
  cancellations.add(error);