@defold-typescript/types 0.5.5 → 0.7.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 (54) hide show
  1. package/README.md +2 -2
  2. package/api-targets.json +1 -1
  3. package/generated/b2d.d.ts +3 -0
  4. package/generated/buffer.d.ts +44 -38
  5. package/generated/builtin-messages.d.ts +1 -1
  6. package/generated/camera.d.ts +3 -0
  7. package/generated/collectionfactory.d.ts +47 -40
  8. package/generated/collectionproxy.d.ts +23 -18
  9. package/generated/crash.d.ts +3 -0
  10. package/generated/factory.d.ts +32 -24
  11. package/generated/go.d.ts +123 -124
  12. package/generated/graphics.d.ts +3 -0
  13. package/generated/gui.d.ts +303 -283
  14. package/generated/http.d.ts +26 -16
  15. package/generated/iac.d.ts +3 -0
  16. package/generated/iap.d.ts +6 -3
  17. package/generated/image.d.ts +30 -26
  18. package/generated/json.d.ts +36 -32
  19. package/generated/kinds/gui-script.d.ts +7 -5
  20. package/generated/kinds/render-script.d.ts +7 -5
  21. package/generated/kinds/script.d.ts +7 -5
  22. package/generated/label.d.ts +16 -9
  23. package/generated/liveupdate.d.ts +29 -26
  24. package/generated/model.d.ts +57 -45
  25. package/generated/msg.d.ts +3 -0
  26. package/generated/particlefx.d.ts +50 -34
  27. package/generated/physics.d.ts +153 -133
  28. package/generated/profiler.d.ts +45 -41
  29. package/generated/push.d.ts +5 -2
  30. package/generated/render.d.ts +410 -349
  31. package/generated/resource.d.ts +619 -572
  32. package/generated/socket.d.ts +49 -33
  33. package/generated/sound.d.ts +83 -72
  34. package/generated/sprite.d.ts +3 -0
  35. package/generated/sys.d.ts +198 -189
  36. package/generated/tilemap.d.ts +43 -39
  37. package/generated/timer.d.ts +42 -36
  38. package/generated/vmath.d.ts +22 -0
  39. package/generated/webview.d.ts +3 -0
  40. package/generated/window.d.ts +23 -17
  41. package/generated/zlib.d.ts +15 -12
  42. package/index.d.ts +3 -1
  43. package/package.json +13 -2
  44. package/scripts/fidelity-audit.ts +61 -1
  45. package/scripts/fidelity-baseline.json +10 -10
  46. package/scripts/ref-doc-delta.ts +143 -0
  47. package/scripts/regen.ts +18 -9
  48. package/src/core-types.ts +14 -0
  49. package/src/emit-dts.ts +219 -13
  50. package/src/engine-globals.d.ts +2 -0
  51. package/src/go-overloads.d.ts +43 -0
  52. package/src/index.ts +5 -0
  53. package/src/lifecycle.ts +157 -16
  54. package/src/publish-dts.ts +1 -1
@@ -2,6 +2,9 @@
2
2
  import type { Hash, Opaque } from "../src/core-types";
3
3
 
4
4
  declare global {
5
+ /**
6
+ * Functions and constants to access resources.
7
+ */
5
8
  namespace resource {
6
9
  /**
7
10
  * Constructor-like function with two purposes:
@@ -12,18 +15,24 @@ declare global {
12
15
  * @param path - optional resource path string to the resource
13
16
  * @returns a path hash to the binary version of the resource
14
17
  * @example
15
- * ```lua
16
- * Load an atlas and set it to a sprite:
17
- * go.property("my_atlas", resource.atlas("/atlas.atlas"))
18
- * function init(self)
19
- * go.set("#sprite", "image", self.my_atlas)
20
- * end
21
- *
22
- * Load an atlas and set it to a gui:
23
- * go.property("my_atlas", resource.atlas("/atlas.atlas"))
24
- * function init(self)
25
- * go.set("#gui", "textures", self.my_atlas, {key = "my_atlas"})
26
- * end
18
+ * ```ts
19
+ * // Load an atlas and set it to a sprite:
20
+ * go.property("my_atlas", resource.atlas("/atlas.atlas"));
21
+ *
22
+ * export default defineScript({
23
+ * init(self) {
24
+ * go.set("#sprite", "image", self.my_atlas);
25
+ * },
26
+ * });
27
+ *
28
+ * // Load an atlas and set it to a gui:
29
+ * go.property("my_atlas", resource.atlas("/atlas.atlas"));
30
+ *
31
+ * export default defineScript({
32
+ * init(self) {
33
+ * go.set("#gui", "textures", self.my_atlas, { key: "my_atlas" });
34
+ * },
35
+ * });
27
36
  * ```
28
37
  */
29
38
  function atlas(path?: string): Hash;
@@ -36,12 +45,15 @@ declare global {
36
45
  * @param path - optional resource path string to the resource
37
46
  * @returns a path hash to the binary version of the resource
38
47
  * @example
39
- * ```lua
40
- * Set a unique buffer it to a sprite:
41
- * go.property("my_buffer", resource.buffer("/cube.buffer"))
42
- * function init(self)
43
- * go.set("#mesh", "vertices", self.my_buffer)
44
- * end
48
+ * ```ts
49
+ * // Set a unique buffer it to a sprite:
50
+ * go.property("my_buffer", resource.buffer("/cube.buffer"));
51
+ *
52
+ * export default defineScript({
53
+ * init(self) {
54
+ * go.set("#mesh", "vertices", self.my_buffer);
55
+ * },
56
+ * });
45
57
  * ```
46
58
  */
47
59
  function buffer(path?: string): Hash;
@@ -124,61 +136,53 @@ declare global {
124
136
  * table a list of the indices of the geometry in the form {i0, i1, i2, ..., in}. Each tripe in the list represents a triangle.
125
137
  * @returns Returns the atlas resource path
126
138
  * @example
127
- * ```lua
128
- * Create a backing texture and an atlas
129
- * function init(self)
130
- * -- create an empty texture
131
- * local tparams = {
132
- * width = 128,
133
- * height = 128,
134
- * type = graphics.TEXTURE_TYPE_2D,
135
- * format = graphics.TEXTURE_FORMAT_RGBA,
136
- * }
137
- * local my_texture_id = resource.create_texture("/my_texture.texturec", tparams)
138
- *
139
- * -- optionally use resource.set_texture to upload data to texture
140
- *
141
- * -- create an atlas with one animation and one square geometry
142
- * -- note that the function doesn't support hashes for the texture,
143
- * -- you need to use a string for the texture path here aswell
144
- * local aparams = {
145
- * texture = "/my_texture.texturec",
146
- * animations = {
147
- * {
148
- * id = "my_animation",
149
- * width = 128,
150
- * height = 128,
151
- * frames = { 1 }
152
- * }
139
+ * ```ts
140
+ * // Create a backing texture and an atlas
141
+ * export default defineScript({
142
+ * init() {
143
+ * // create an empty texture
144
+ * const tparams = {
145
+ * width: 128,
146
+ * height: 128,
147
+ * type: graphics.TEXTURE_TYPE_2D,
148
+ * format: graphics.TEXTURE_FORMAT_RGBA,
149
+ * };
150
+ * const my_texture_id = resource.create_texture("/my_texture.texturec", tparams);
151
+ *
152
+ * // optionally use resource.set_texture to upload data to texture
153
+ *
154
+ * // create an atlas with one animation and one square geometry
155
+ * // note that the function doesn't support hashes for the texture,
156
+ * // you need to use a string for the texture path here aswell
157
+ * const aparams = {
158
+ * texture: "/my_texture.texturec",
159
+ * animations: [
160
+ * {
161
+ * id: "my_animation",
162
+ * width: 128,
163
+ * height: 128,
164
+ * frames: [1],
153
165
  * },
154
- * geometries = {
155
- * {
156
- * id = 'idle0',
157
- * width = 128,
158
- * height = 128,
159
- * pivot_x = 0.5,
160
- * pivot_y = 0.5,
161
- * vertices = {
162
- * 0, 0,
163
- * 0, 128,
164
- * 128, 128,
165
- * 128, 0
166
- * },
167
- * uvs = {
168
- * 0, 0,
169
- * 0, 128,
170
- * 128, 128,
171
- * 128, 0
172
- * },
173
- * indices = {0,1,2,0,2,3}
174
- * }
175
- * }
176
- * }
177
- * local my_atlas_id = resource.create_atlas("/my_atlas.texturesetc", aparams)
178
- *
179
- * -- assign the atlas to the 'sprite' component on the same go
180
- * go.set("#sprite", "image", my_atlas_id)
181
- * end
166
+ * ],
167
+ * geometries: [
168
+ * {
169
+ * id: "idle0",
170
+ * width: 128,
171
+ * height: 128,
172
+ * pivot_x: 0.5,
173
+ * pivot_y: 0.5,
174
+ * vertices: [0, 0, 0, 128, 128, 128, 128, 0],
175
+ * uvs: [0, 0, 0, 128, 128, 128, 128, 0],
176
+ * indices: [0, 1, 2, 0, 2, 3],
177
+ * },
178
+ * ],
179
+ * };
180
+ * const my_atlas_id = resource.create_atlas("/my_atlas.texturesetc", aparams);
181
+ *
182
+ * // assign the atlas to the 'sprite' component on the same go
183
+ * go.set("#sprite", "image", my_atlas_id);
184
+ * },
185
+ * });
182
186
  * ```
183
187
  */
184
188
  function create_atlas(path: string, table: { texture?: string | Hash; animations?: { id?: string; width?: number; height?: number; frame_start?: number; frame_end?: number; playback?: Opaque<"constant">; fps?: number; flip_vertical?: boolean; flip_horizontal?: boolean }[]; geometries?: { id?: string; width?: number; height?: number; pivot_x?: number; pivot_y?: number; rotated?: boolean }[]; vertices?: number[]; uvs?: number[]; indices?: number[] }): Hash;
@@ -202,49 +206,52 @@ declare global {
202
206
  * boolean optional flag to determine wether or not the resource should take over ownership of the buffer object (default true)
203
207
  * @returns Returns the buffer resource path
204
208
  * @example
205
- * ```lua
206
- * Create a buffer object and bind it to a buffer resource
207
- * function init(self)
208
- * local size = 1
209
- * local positions = {
210
- * -- triangle 1
211
- * size, size, 0,
212
- * -size, -size, 0,
213
- * size, -size, 0,
214
- * -- triangle 2
215
- * size, size, 0,
216
- * -size, size, 0,
217
- * -size, -size, 0,
209
+ * ```ts
210
+ * // Create a buffer object and bind it to a buffer resource
211
+ * export default defineScript({
212
+ * init() {
213
+ * const size = 1;
214
+ * const positions = [
215
+ * // triangle 1
216
+ * size, size, 0,
217
+ * -size, -size, 0,
218
+ * size, -size, 0,
219
+ * // triangle 2
220
+ * size, size, 0,
221
+ * -size, size, 0,
222
+ * -size, -size, 0,
223
+ * ];
224
+ *
225
+ * const buffer_handle = buffer.create(positions.length, [
226
+ * {
227
+ * name: hash("position"),
228
+ * type: buffer.VALUE_TYPE_FLOAT32,
229
+ * count: 3,
230
+ * },
231
+ * ]);
232
+ *
233
+ * const stream = buffer.get_stream(buffer_handle, hash("position"));
234
+ *
235
+ * // transfer vertex data to buffer
236
+ * for (let k = 0; k < positions.length; k++) {
237
+ * stream[k] = positions[k];
218
238
  * }
219
239
  *
220
- * local buffer_handle = buffer.create(#positions, {
221
- * {
222
- * name = hash("position"),
223
- * type = buffer.VALUE_TYPE_FLOAT32,
224
- * count = 3
225
- * }
226
- * })
227
- *
228
- * local stream = buffer.get_stream(buffer_handle, hash("position"))
229
- *
230
- * -- transfer vertex data to buffer
231
- * for k=1,#positions do
232
- * stream[k] = positions[k]
233
- * end
234
- *
235
- * local my_buffer = resource.create_buffer("/my_buffer.bufferc", { buffer = buffer_handle })
236
- * go.set("/go#mesh", "vertices", my_buffer)
237
- * end
238
- * ```Create a buffer resource from existing resource
239
- *
240
- * ```lua
241
- * function init(self)
242
- * local res = resource.get_buffer("/my_buffer_path.bufferc")
243
- * -- create a cloned buffer resource from another resource buffer
244
- * local buf = reource.create_buffer("/my_cloned_buffer.bufferc", { buffer = res })
245
- * -- assign cloned buffer to a mesh component
246
- * go.set("/go#mesh", "vertices", buf)
247
- * end
240
+ * const my_buffer = resource.create_buffer("/my_buffer.bufferc", { buffer: buffer_handle });
241
+ * go.set("/go#mesh", "vertices", my_buffer);
242
+ * },
243
+ * });
244
+ *
245
+ * // Create a buffer resource from existing resource
246
+ * export default defineScript({
247
+ * init() {
248
+ * const res = resource.get_buffer("/my_buffer_path.bufferc");
249
+ * // create a cloned buffer resource from another resource buffer
250
+ * const buf = resource.create_buffer("/my_cloned_buffer.bufferc", { buffer: res });
251
+ * // assign cloned buffer to a mesh component
252
+ * go.set("/go#mesh", "vertices", buf);
253
+ * },
254
+ * });
248
255
  * ```
249
256
  */
250
257
  function create_buffer(path: string, table?: { buffer?: Opaque<"buffer">; transfer_ownership?: boolean }): Hash;
@@ -262,14 +269,16 @@ declare global {
262
269
  * boolean Is the data not representing the full file, but just the initial chunk?
263
270
  * @returns the resulting path hash to the resource
264
271
  * @example
265
- * ```lua
266
- * function init(self)
267
- * -- create a new sound resource, given the initial chunk of the file
268
- * local relative_path = "/a/unique/resource/name.oggc"
269
- * local hash = resource.create_sound_data(relative_path, { data = data, filesize = filesize, partial = true })
270
- * go.set("#music", "sound", hash) -- override the previous sound resource
271
- * sound.play("#music") -- start the playing
272
- * end
272
+ * ```ts
273
+ * export default defineScript({
274
+ * init() {
275
+ * // create a new sound resource, given the initial chunk of the file
276
+ * const relative_path = "/a/unique/resource/name.oggc";
277
+ * const hash = resource.create_sound_data(relative_path, { data, filesize, partial: true });
278
+ * go.set("#music", "sound", hash); // override the previous sound resource
279
+ * sound.play("#music"); // start the playing
280
+ * },
281
+ * });
273
282
  * ```
274
283
  */
275
284
  function create_sound_data(path: string, options?: { data?: string; filesize?: number; partial?: boolean }): Hash;
@@ -348,77 +357,80 @@ declare global {
348
357
  * -- Device and graphics adapter support 3D textures
349
358
  * end
350
359
  * @example
351
- * ```lua
352
- * How to create an 128x128 RGBA texture resource and assign it to a model
353
- * function init(self)
354
- * local tparams = {
355
- * width = 128,
356
- * height = 128,
357
- * type = graphics.TEXTURE_TYPE_2D,
358
- * format = graphics.TEXTURE_FORMAT_RGBA,
359
- * }
360
- * local my_texture_id = resource.create_texture("/my_custom_texture.texturec", tparams)
361
- * go.set("#model", "texture0", my_texture_id)
362
- * end
363
- * ```How to create an 128x128 floating point texture (RGBA32F) resource from a buffer object
364
- *
365
- * ```lua
366
- * function init(self)
367
- * -- Create a new buffer with 4 components and FLOAT32 type
368
- * local tbuffer = buffer.create(128 * 128, { {name=hash("rgba"), type=buffer.VALUE_TYPE_FLOAT32, count=4} } )
369
- * local tstream = buffer.get_stream(tbuffer, hash("rgba"))
370
- *
371
- * -- Fill the buffer stream with some float values
372
- * for y=1,128 do
373
- * for x=1,128 do
374
- * local index = (y-1) * 128 * 4 + (x-1) * 4 + 1
375
- * tstream[index + 0] = 999.0
376
- * tstream[index + 1] = -1.0
377
- * tstream[index + 2] = 0.5
378
- * tstream[index + 3] = 1.0
379
- * end
380
- * end
381
- *
382
- * -- Create a 2D Texture with a RGBA23F format
383
- * local tparams = {
384
- * width = 128,
385
- * height = 128,
386
- * type = graphics.TEXTURE_TYPE_2D,
387
- * format = graphics.TEXTURE_FORMAT_RGBA32F,
388
- * }
389
- *
390
- * -- Note that we pass the buffer as the last argument here!
391
- * local my_texture_id = resource.create_texture("/my_custom_texture.texturec", tparams, tbuffer)
392
- *
393
- * -- assign the texture to a model
394
- * go.set("#model", "texture0", my_texture_id)
395
- * end
396
- * ```How to create a 32x32x32 floating point 3D texture that can be used to generate volumetric data in a compute shader
397
- *
398
- * ```lua
399
- * function init(self)
400
- * local t_volume = resource.create_texture("/my_backing_texture.texturec", {
401
- * type = graphics.TEXTURE_TYPE_IMAGE_3D,
402
- * width = 32,
403
- * height = 32,
404
- * depth = 32,
405
- * format = resource.TEXTURE_FORMAT_RGBA32F,
406
- * flags = resource.TEXTURE_USAGE_FLAG_STORAGE + resource.TEXTURE_USAGE_FLAG_SAMPLE,
407
- * })
408
- *
409
- * -- pass the backing texture to the render script
410
- * msg.post("@render:", "add_textures", { t_volume })
411
- * end
412
- * ```How to create 512x512 texture array with 5 pages.
360
+ * ```ts
361
+ * // How to create an 128x128 RGBA texture resource and assign it to a model
362
+ * export default defineScript({
363
+ * init() {
364
+ * const tparams = {
365
+ * width: 128,
366
+ * height: 128,
367
+ * type: graphics.TEXTURE_TYPE_2D,
368
+ * format: graphics.TEXTURE_FORMAT_RGBA,
369
+ * };
370
+ * const my_texture_id = resource.create_texture("/my_custom_texture.texturec", tparams);
371
+ * go.set("#model", "texture0", my_texture_id);
372
+ * },
373
+ * });
374
+ *
375
+ * // How to create an 128x128 floating point texture (RGBA32F) resource from a buffer object
376
+ * export default defineScript({
377
+ * init() {
378
+ * // Create a new buffer with 4 components and FLOAT32 type
379
+ * const tbuffer = buffer.create(128 * 128, [{ name: hash("rgba"), type: buffer.VALUE_TYPE_FLOAT32, count: 4 }]);
380
+ * const tstream = buffer.get_stream(tbuffer, hash("rgba"));
381
+ *
382
+ * // Fill the buffer stream with some float values
383
+ * for (let y = 0; y < 128; y++) {
384
+ * for (let x = 0; x < 128; x++) {
385
+ * const index = y * 128 * 4 + x * 4;
386
+ * tstream[index + 0] = 999.0;
387
+ * tstream[index + 1] = -1.0;
388
+ * tstream[index + 2] = 0.5;
389
+ * tstream[index + 3] = 1.0;
390
+ * }
391
+ * }
413
392
  *
414
- * ```lua
415
- * local new_tex = resource.create_texture("/runtime/example_array.texturec", {
416
- * type = graphics.TEXTURE_TYPE_2D_ARRAY,
417
- * width = 512,
418
- * height = 512,
419
- * page_count = 5,
420
- * format = graphics.TEXTURE_FORMAT_RGB,
421
- * })
393
+ * // Create a 2D Texture with a RGBA23F format
394
+ * const tparams = {
395
+ * width: 128,
396
+ * height: 128,
397
+ * type: graphics.TEXTURE_TYPE_2D,
398
+ * format: graphics.TEXTURE_FORMAT_RGBA32F,
399
+ * };
400
+ *
401
+ * // Note that we pass the buffer as the last argument here!
402
+ * const my_texture_id = resource.create_texture("/my_custom_texture.texturec", tparams, tbuffer);
403
+ *
404
+ * // assign the texture to a model
405
+ * go.set("#model", "texture0", my_texture_id);
406
+ * },
407
+ * });
408
+ *
409
+ * // How to create a 32x32x32 floating point 3D texture that can be used to generate volumetric data in a compute shader
410
+ * export default defineScript({
411
+ * init() {
412
+ * const t_volume = resource.create_texture("/my_backing_texture.texturec", {
413
+ * type: graphics.TEXTURE_TYPE_IMAGE_3D,
414
+ * width: 32,
415
+ * height: 32,
416
+ * depth: 32,
417
+ * format: resource.TEXTURE_FORMAT_RGBA32F,
418
+ * flags: resource.TEXTURE_USAGE_FLAG_STORAGE + resource.TEXTURE_USAGE_FLAG_SAMPLE,
419
+ * });
420
+ *
421
+ * // pass the backing texture to the render script
422
+ * msg.post("@render:", "add_textures", [t_volume]);
423
+ * },
424
+ * });
425
+ *
426
+ * // How to create 512x512 texture array with 5 pages.
427
+ * const new_tex = resource.create_texture("/runtime/example_array.texturec", {
428
+ * type: graphics.TEXTURE_TYPE_2D_ARRAY,
429
+ * width: 512,
430
+ * height: 512,
431
+ * page_count: 5,
432
+ * format: graphics.TEXTURE_FORMAT_RGB,
433
+ * });
422
434
  * ```
423
435
  */
424
436
  function create_texture(path: string, table: { type?: number; width?: number; height?: number; depth?: number; format?: number; flags?: number; max_mipmaps?: number; compression_type?: number }, buffer: Opaque<"buffer">): Hash;
@@ -495,76 +507,80 @@ declare global {
495
507
  * @param buffer - optional buffer of precreated pixel data
496
508
  * @param callback - callback function when texture is created (self, request_id, resource)
497
509
  * @example
498
- * ```lua
499
- * Create a texture resource asyncronously with a buffer and a callback
500
- * function callback(self, request_id, resource)
501
- * -- The resource has been updated with a new texture,
502
- * -- so we can update other systems with the new handle,
503
- * -- or update components to use the resource if we want
504
- * local tinfo = resource.get_texture_info(resource)
505
- * msg.post("@render:", "set_backing_texture", tinfo.handle)
506
- * end
507
- * function init(self)
508
- * -- Create a texture resource async
509
- * local tparams = {
510
- * width = 128,
511
- * height = 128,
512
- * type = graphics.TEXTURE_TYPE_2D,
513
- * format = graphics.TEXTURE_FORMAT_RGBA,
510
+ * ```ts
511
+ * // Create a texture resource asyncronously with a buffer and a callback
512
+ * function callback(self, request_id, resource) {
513
+ * // The resource has been updated with a new texture,
514
+ * // so we can update other systems with the new handle,
515
+ * // or update components to use the resource if we want
516
+ * const tinfo = resource.get_texture_info(resource);
517
+ * msg.post("@render:", "set_backing_texture", tinfo.handle);
518
+ * }
519
+ *
520
+ * export default defineScript({
521
+ * init() {
522
+ * // Create a texture resource async
523
+ * const tparams = {
524
+ * width: 128,
525
+ * height: 128,
526
+ * type: graphics.TEXTURE_TYPE_2D,
527
+ * format: graphics.TEXTURE_FORMAT_RGBA,
528
+ * };
529
+ *
530
+ * // Create a new buffer with 4 components
531
+ * const tbuffer = buffer.create(tparams.width * tparams.height, [{ name: hash("rgba"), type: buffer.VALUE_TYPE_UINT8, count: 4 }]);
532
+ * const tstream = buffer.get_stream(tbuffer, hash("rgba"));
533
+ *
534
+ * // Fill the buffer stream with some float values
535
+ * for (let y = 0; y < tparams.width; y++) {
536
+ * for (let x = 0; x < tparams.height; x++) {
537
+ * const index = y * 128 * 4 + x * 4;
538
+ * tstream[index + 0] = 255;
539
+ * tstream[index + 1] = 0;
540
+ * tstream[index + 2] = 255;
541
+ * tstream[index + 3] = 255;
542
+ * }
514
543
  * }
515
- *
516
- * -- Create a new buffer with 4 components
517
- * local tbuffer = buffer.create(tparams.width * tparams.height, { {name=hash("rgba"), type=buffer.VALUE_TYPE_UINT8, count=4} } )
518
- * local tstream = buffer.get_stream(tbuffer, hash("rgba"))
519
- *
520
- * -- Fill the buffer stream with some float values
521
- * for y=1,tparams.width do
522
- * for x=1,tparams.height do
523
- * local index = (y-1) * 128 * 4 + (x-1) * 4 + 1
524
- * tstream[index + 0] = 255
525
- * tstream[index + 1] = 0
526
- * tstream[index + 2] = 255
527
- * tstream[index + 3] = 255
528
- * end
529
- * end
530
- * -- create the texture
531
- * local tpath, request_id = resource.create_texture_async("/my_texture.texturec", tparams, tbuffer, callback)
532
- * -- at this point you can use the resource as-is, but note that the texture will be a blank 1x1 texture
533
- * -- that will be removed once the new texture has been updated
534
- * go.set("#model", "texture0", tpath)
535
- * end
536
- * ```Create a texture resource asyncronously without a callback
537
- *
538
- * ```lua
539
- * function init(self)
540
- * -- Create a texture resource async
541
- * local tparams = {
542
- * width = 128,
543
- * height = 128,
544
- * type = graphics.TEXTURE_TYPE_2D,
545
- * format = graphics.TEXTURE_FORMAT_RGBA,
544
+ * // create the texture
545
+ * const [tpath, request_id] = resource.create_texture_async("/my_texture.texturec", tparams, tbuffer, callback);
546
+ * // at this point you can use the resource as-is, but note that the texture will be a blank 1x1 texture
547
+ * // that will be removed once the new texture has been updated
548
+ * go.set("#model", "texture0", tpath);
549
+ * },
550
+ * });
551
+ *
552
+ * // Create a texture resource asyncronously without a callback
553
+ * export default defineScript({
554
+ * init() {
555
+ * // Create a texture resource async
556
+ * const tparams = {
557
+ * width: 128,
558
+ * height: 128,
559
+ * type: graphics.TEXTURE_TYPE_2D,
560
+ * format: graphics.TEXTURE_FORMAT_RGBA,
561
+ * };
562
+ *
563
+ * // Create a new buffer with 4 components
564
+ * const tbuffer = buffer.create(tparams.width * tparams.height, [{ name: hash("rgba"), type: buffer.VALUE_TYPE_UINT8, count: 4 }]);
565
+ * const tstream = buffer.get_stream(tbuffer, hash("rgba"));
566
+ *
567
+ * // Fill the buffer stream with some float values
568
+ * for (let y = 0; y < tparams.width; y++) {
569
+ * for (let x = 0; x < tparams.height; x++) {
570
+ * const index = y * 128 * 4 + x * 4;
571
+ * tstream[index + 0] = 255;
572
+ * tstream[index + 1] = 0;
573
+ * tstream[index + 2] = 255;
574
+ * tstream[index + 3] = 255;
575
+ * }
546
576
  * }
547
- *
548
- * -- Create a new buffer with 4 components
549
- * local tbuffer = buffer.create(tparams.width * tparams.height, { {name=hash("rgba"), type=buffer.VALUE_TYPE_UINT8, count=4} } )
550
- * local tstream = buffer.get_stream(tbuffer, hash("rgba"))
551
- *
552
- * -- Fill the buffer stream with some float values
553
- * for y=1,tparams.width do
554
- * for x=1,tparams.height do
555
- * local index = (y-1) * 128 * 4 + (x-1) * 4 + 1
556
- * tstream[index + 0] = 255
557
- * tstream[index + 1] = 0
558
- * tstream[index + 2] = 255
559
- * tstream[index + 3] = 255
560
- * end
561
- * end
562
- * -- create the texture
563
- * local tpath, request_id = resource.create_texture_async("/my_texture.texturec", tparams, tbuffer)
564
- * -- at this point you can use the resource as-is, but note that the texture will be a blank 1x1 texture
565
- * -- that will be removed once the new texture has been updated
566
- * go.set("#model", "texture0", tpath)
567
- * end
577
+ * // create the texture
578
+ * const [tpath, request_id] = resource.create_texture_async("/my_texture.texturec", tparams, tbuffer);
579
+ * // at this point you can use the resource as-is, but note that the texture will be a blank 1x1 texture
580
+ * // that will be removed once the new texture has been updated
581
+ * go.set("#model", "texture0", tpath);
582
+ * },
583
+ * });
568
584
  * ```
569
585
  */
570
586
  function create_texture_async(path: string | Hash, table: { type?: number; width?: number; height?: number; depth?: number; format?: number; flags?: number; max_mipmaps?: number; compression_type?: number }, buffer: Opaque<"buffer">, callback: (...args: unknown[]) => unknown): LuaMultiReturn<[Hash, number]>;
@@ -577,18 +593,24 @@ declare global {
577
593
  * @param path - optional resource path string to the resource
578
594
  * @returns a path hash to the binary version of the resource
579
595
  * @example
580
- * ```lua
581
- * Load a font and set it to a label:
582
- * go.property("my_font", resource.font("/font.font"))
583
- * function init(self)
584
- * go.set("#label", "font", self.my_font)
585
- * end
586
- *
587
- * Load a font and set it to a gui:
588
- * go.property("my_font", resource.font("/font.font"))
589
- * function init(self)
590
- * go.set("#gui", "fonts", self.my_font, {key = "my_font"})
591
- * end
596
+ * ```ts
597
+ * // Load a font and set it to a label:
598
+ * go.property("my_font", resource.font("/font.font"));
599
+ *
600
+ * export default defineScript({
601
+ * init(self) {
602
+ * go.set("#label", "font", self.my_font);
603
+ * },
604
+ * });
605
+ *
606
+ * // Load a font and set it to a gui:
607
+ * go.property("my_font", resource.font("/font.font"));
608
+ *
609
+ * export default defineScript({
610
+ * init(self) {
611
+ * go.set("#gui", "fonts", self.my_font, { key: "my_font" });
612
+ * },
613
+ * });
592
614
  * ```
593
615
  */
594
616
  function font(path?: string): Hash;
@@ -611,18 +633,19 @@ declare global {
611
633
  * @param path - The path to the resource
612
634
  * @returns The resource buffer
613
635
  * @example
614
- * ```lua
615
- * How to get the data from a buffer
616
- * function init(self)
617
- *
618
- * local res_path = go.get("#mesh", "vertices")
619
- * local buf = resource.get_buffer(res_path)
620
- * local stream_positions = buffer.get_stream(buf, "position")
621
- *
622
- * for i=1,#stream_positions do
623
- * print(i, stream_positions[i])
624
- * end
625
- * end
636
+ * ```ts
637
+ * // How to get the data from a buffer
638
+ * export default defineScript({
639
+ * init() {
640
+ * const res_path = go.get("#mesh", "vertices");
641
+ * const buf = resource.get_buffer(res_path);
642
+ * const stream_positions = buffer.get_stream(buf, "position");
643
+ *
644
+ * for (let i = 0; i < stream_positions.length; i++) {
645
+ * print(i, stream_positions[i]);
646
+ * }
647
+ * },
648
+ * });
626
649
  * ```
627
650
  */
628
651
  function get_buffer(path: Hash | string): Opaque<"buffer">;
@@ -661,25 +684,28 @@ declare global {
661
684
  * `texture`
662
685
  * hash The hashed path to the attachment texture resource. This field is only available if the render target passed in is a resource.
663
686
  * @example
664
- * ```lua
665
- * Get the metadata from a render target resource
666
- * function init(self)
667
- * local info = resource.get_render_target_info("/my_render_target.render_targetc")
668
- * -- the info table contains meta data about all the render target attachments
669
- * -- so it's not necessary to use resource.get_texture here, but we do it here
670
- * -- just to show that it's possible:
671
- * local info_attachment_1 = resource.get_texture_info(info.attachments[1].handle)
672
- * end
673
- * ```Get a texture attachment from a render target and set it on a model component
674
- *
675
- * ```lua
676
- * function init(self)
677
- * local info = resource.get_render_target_info("/my_render_target.render_targetc")
678
- * local attachment = info.attachments[1].texture
679
- * -- you can also get texture info from the 'texture' field, since it's a resource hash
680
- * local texture_info = resource.get_texture_info(attachment)
681
- * go.set("#model", "texture0", attachment)
682
- * end
687
+ * ```ts
688
+ * // Get the metadata from a render target resource
689
+ * export default defineScript({
690
+ * init() {
691
+ * const info = resource.get_render_target_info("/my_render_target.render_targetc");
692
+ * // the info table contains meta data about all the render target attachments
693
+ * // so it's not necessary to use resource.get_texture here, but we do it here
694
+ * // just to show that it's possible:
695
+ * const info_attachment_1 = resource.get_texture_info(info.attachments[0].handle);
696
+ * },
697
+ * });
698
+ *
699
+ * // Get a texture attachment from a render target and set it on a model component
700
+ * export default defineScript({
701
+ * init() {
702
+ * const info = resource.get_render_target_info("/my_render_target.render_targetc");
703
+ * const attachment = info.attachments[0].texture;
704
+ * // you can also get texture info from the 'texture' field, since it's a resource hash
705
+ * const texture_info = resource.get_texture_info(attachment);
706
+ * go.set("#model", "texture0", attachment);
707
+ * },
708
+ * });
683
709
  * ```
684
710
  */
685
711
  function get_render_target_info(path: Hash | string | number): { handle: number; width: number; height: number; depth: number; mipmaps: number; type: number; buffer_type: number; texture: Hash };
@@ -703,12 +729,14 @@ declare global {
703
729
  * - max_ascent
704
730
  * - max_descent
705
731
  * @example
706
- * ```lua
707
- * function init(self)
708
- * local font = go.get("#label", "font")
709
- * local metrics = resource.get_text_metrics(font, "The quick brown fox\n jumps over the lazy dog")
710
- * pprint(metrics)
711
- * end
732
+ * ```ts
733
+ * export default defineScript({
734
+ * init() {
735
+ * const font = go.get("#label", "font");
736
+ * const metrics = resource.get_text_metrics(font, "The quick brown fox\n jumps over the lazy dog");
737
+ * pprint(metrics);
738
+ * },
739
+ * });
712
740
  * ```
713
741
  */
714
742
  function get_text_metrics(url: Hash, text: string, options?: { width?: number; leading?: number; tracking?: number; line_break?: boolean }): Record<string | number, unknown>;
@@ -740,41 +768,44 @@ declare global {
740
768
  * - `graphics.TEXTURE_TYPE_IMAGE_3D`
741
769
  * - `graphics.TEXTURE_TYPE_CUBE_MAP`
742
770
  * @example
743
- * ```lua
744
- * Create a new texture and get the metadata from it
745
- * function init(self)
746
- * -- create an empty texture
747
- * local tparams = {
748
- * width = 128,
749
- * height = 128,
750
- * type = graphics.TEXTURE_TYPE_2D,
751
- * format = graphics.TEXTURE_FORMAT_RGBA,
752
- * }
753
- *
754
- * local my_texture_path = resource.create_texture("/my_texture.texturec", tparams)
755
- * local my_texture_info = resource.get_texture_info(my_texture_path)
756
- *
757
- * -- my_texture_info now contains
758
- * -- {
759
- * -- handle = <the-numeric-handle>,
760
- * -- width = 128,
761
- * -- height = 128,
762
- * -- depth = 1
763
- * -- mipmaps = 1,
764
- * -- page_count = 1,
765
- * -- type = graphics.TEXTURE_TYPE_2D,
766
- * -- flags = graphics.TEXTURE_USAGE_FLAG_SAMPLE
767
- * -- }
768
- * end
769
- * ```Get the meta data from an atlas resource
770
- *
771
- * ```lua
772
- * function init(self)
773
- * local my_atlas_info = resource.get_atlas("/my_atlas.a.texturesetc")
774
- * local my_texture_info = resource.get_texture_info(my_atlas_info.texture)
775
- *
776
- * -- my_texture_info now contains the information about the texture that is backing the atlas
777
- * end
771
+ * ```ts
772
+ * // Create a new texture and get the metadata from it
773
+ * export default defineScript({
774
+ * init() {
775
+ * // create an empty texture
776
+ * const tparams = {
777
+ * width: 128,
778
+ * height: 128,
779
+ * type: graphics.TEXTURE_TYPE_2D,
780
+ * format: graphics.TEXTURE_FORMAT_RGBA,
781
+ * };
782
+ *
783
+ * const my_texture_path = resource.create_texture("/my_texture.texturec", tparams);
784
+ * const my_texture_info = resource.get_texture_info(my_texture_path);
785
+ *
786
+ * // my_texture_info now contains
787
+ * // {
788
+ * // handle = <the-numeric-handle>,
789
+ * // width = 128,
790
+ * // height = 128,
791
+ * // depth = 1
792
+ * // mipmaps = 1,
793
+ * // page_count = 1,
794
+ * // type = graphics.TEXTURE_TYPE_2D,
795
+ * // flags = graphics.TEXTURE_USAGE_FLAG_SAMPLE
796
+ * // }
797
+ * },
798
+ * });
799
+ *
800
+ * // Get the meta data from an atlas resource
801
+ * export default defineScript({
802
+ * init() {
803
+ * const my_atlas_info = resource.get_atlas("/my_atlas.a.texturesetc");
804
+ * const my_texture_info = resource.get_texture_info(my_atlas_info.texture);
805
+ *
806
+ * // my_texture_info now contains the information about the texture that is backing the atlas
807
+ * },
808
+ * });
778
809
  * ```
779
810
  */
780
811
  function get_texture_info(path: Hash | string | number): { handle: number; width: number; height: number; depth: number; page_count: number; mipmaps: number; flags: number; type: number };
@@ -784,16 +815,16 @@ declare global {
784
815
  * @param path - The path to the resource
785
816
  * @returns Returns the buffer stored on disc
786
817
  * @example
787
- * ```lua
788
- * -- read custom resource data into buffer
789
- * local buffer = resource.load("/resources/datafile")
790
- *
791
- * In order for the engine to include custom resources in the build process, you need
792
- * to specify them in the "game.project" settings file:
793
- * [project]
794
- * title = My project
795
- * version = 0.1
796
- * custom_resources = resources/,assets/level_data.json
818
+ * ```ts
819
+ * // read custom resource data into buffer
820
+ * const buffer = resource.load("/resources/datafile");
821
+ *
822
+ * // In order for the engine to include custom resources in the build process, you
823
+ * // need to specify them in the "game.project" settings file:
824
+ * // [project]
825
+ * // title = My project
826
+ * // version = 0.1
827
+ * // custom_resources = resources/,assets/level_data.json
797
828
  * ```
798
829
  */
799
830
  function load(path: string): Opaque<"buffer">;
@@ -806,18 +837,24 @@ declare global {
806
837
  * @param path - optional resource path string to the resource
807
838
  * @returns a path hash to the binary version of the resource
808
839
  * @example
809
- * ```lua
810
- * Load a material and set it to a sprite:
811
- * go.property("my_material", resource.material("/material.material"))
812
- * function init(self)
813
- * go.set("#sprite", "material", self.my_material)
814
- * end
815
- *
816
- * Load a material resource and update a named material with the resource:
817
- * go.property("my_material", resource.material("/material.material"))
818
- * function init(self)
819
- * go.set("#gui", "materials", self.my_material, {key = "my_material"})
820
- * end
840
+ * ```ts
841
+ * // Load a material and set it to a sprite:
842
+ * go.property("my_material", resource.material("/material.material"));
843
+ *
844
+ * export default defineScript({
845
+ * init(self) {
846
+ * go.set("#sprite", "material", self.my_material);
847
+ * },
848
+ * });
849
+ *
850
+ * // Load a material resource and update a named material with the resource:
851
+ * go.property("my_material", resource.material("/material.material"));
852
+ *
853
+ * export default defineScript({
854
+ * init(self) {
855
+ * go.set("#gui", "materials", self.my_material, { key: "my_material" });
856
+ * },
857
+ * });
821
858
  * ```
822
859
  */
823
860
  function material(path?: string): Hash;
@@ -837,13 +874,16 @@ declare global {
837
874
  * @param path - optional resource path string to the resource
838
875
  * @returns a path hash to the binary version of the resource
839
876
  * @example
840
- * ```lua
841
- * Set a render target color attachment as a model texture:
842
- * go.property("my_render_target", resource.render_target("/rt.render_target"))
843
- * function init(self)
844
- * local rt_info = resource.get_render_target_info(self.my_render_target)
845
- * go.set("#model", "texture0", rt_info.attachments[1].texture)
846
- * end
877
+ * ```ts
878
+ * // Set a render target color attachment as a model texture:
879
+ * go.property("my_render_target", resource.render_target("/rt.render_target"));
880
+ *
881
+ * export default defineScript({
882
+ * init(self) {
883
+ * const rt_info = resource.get_render_target_info(self.my_render_target);
884
+ * go.set("#model", "texture0", rt_info.attachments[0].texture);
885
+ * },
886
+ * });
847
887
  * ```
848
888
  */
849
889
  function render_target(path?: string): Hash;
@@ -853,11 +893,11 @@ declare global {
853
893
  * @param path - The path to the resource
854
894
  * @param buffer - The buffer of precreated data, suitable for the intended resource type
855
895
  * @example
856
- * ```lua
857
- * Assuming the folder "/res" is added to the project custom resources:
858
- * -- load a texture resource and set it on a sprite
859
- * local buffer = resource.load("/res/new.texturec")
860
- * resource.set(go.get("#sprite", "texture0"), buffer)
896
+ * ```ts
897
+ * // Assuming the folder "/res" is added to the project custom resources:
898
+ * // load a texture resource and set it on a sprite
899
+ * const buffer = resource.load("/res/new.texturec");
900
+ * resource.set(go.get("#sprite", "texture0"), buffer);
861
901
  * ```
862
902
  */
863
903
  function set(path: string | Hash, buffer: Opaque<"buffer">): void;
@@ -922,56 +962,49 @@ declare global {
922
962
  * `indices`
923
963
  * table a list of the indices of the geometry in the form {i0, i1, i2, ..., in}. Each tripe in the list represents a triangle.
924
964
  * @example
925
- * ```lua
926
- * Add a new animation to an existing atlas
927
- * function init(self)
928
- * local data = resource.get_atlas("/main/my_atlas.a.texturesetc")
929
- * local my_animation = {
930
- * id = "my_new_animation",
931
- * width = 128,
932
- * height = 128,
933
- * frame_start = 1,
934
- * frame_end = 6,
935
- * playback = go.PLAYBACK_LOOP_PINGPONG,
936
- * fps = 8
937
- * }
938
- * table.insert(data.animations, my_animation)
939
- * resource.set_atlas("/main/my_atlas.a.texturesetc", data)
940
- * end
941
- * ```Sets atlas data for a 256x256 texture with a single animation being rendered as a quad
942
- *
943
- * ```lua
944
- * function init(self)
945
- * local params = {
946
- * texture = "/main/my_256x256_texture.texturec",
947
- * animations = {
948
- * {
949
- * id = "my_animation",
950
- * width = 256,
951
- * height = 256,
952
- * frames = { 1 }
953
- * }
965
+ * ```ts
966
+ * // Add a new animation to an existing atlas
967
+ * export default defineScript({
968
+ * init() {
969
+ * const data = resource.get_atlas("/main/my_atlas.a.texturesetc");
970
+ * const my_animation = {
971
+ * id: "my_new_animation",
972
+ * width: 128,
973
+ * height: 128,
974
+ * frame_start: 1,
975
+ * frame_end: 6,
976
+ * playback: go.PLAYBACK_LOOP_PINGPONG,
977
+ * fps: 8,
978
+ * };
979
+ * data.animations.push(my_animation);
980
+ * resource.set_atlas("/main/my_atlas.a.texturesetc", data);
981
+ * },
982
+ * });
983
+ *
984
+ * // Sets atlas data for a 256x256 texture with a single animation being rendered as a quad
985
+ * export default defineScript({
986
+ * init() {
987
+ * const params = {
988
+ * texture: "/main/my_256x256_texture.texturec",
989
+ * animations: [
990
+ * {
991
+ * id: "my_animation",
992
+ * width: 256,
993
+ * height: 256,
994
+ * frames: [1],
954
995
  * },
955
- * geometries = {
956
- * {
957
- * vertices = {
958
- * 0, 0,
959
- * 0, 256,
960
- * 256, 256,
961
- * 256, 0
962
- * },
963
- * uvs = {
964
- * 0, 0,
965
- * 0, 256,
966
- * 256, 256,
967
- * 256, 0
968
- * },
969
- * indices = { 0,1,2,0,2,3 }
970
- * }
971
- * }
972
- * }
973
- * resource.set_atlas("/main/test.a.texturesetc", params)
974
- * end
996
+ * ],
997
+ * geometries: [
998
+ * {
999
+ * vertices: [0, 0, 0, 256, 256, 256, 256, 0],
1000
+ * uvs: [0, 0, 0, 256, 256, 256, 256, 0],
1001
+ * indices: [0, 1, 2, 0, 2, 3],
1002
+ * },
1003
+ * ],
1004
+ * };
1005
+ * resource.set_atlas("/main/test.a.texturesetc", params);
1006
+ * },
1007
+ * });
975
1008
  * ```
976
1009
  */
977
1010
  function set_atlas(path: Hash | string, table: { texture?: string | Hash; animations?: { id?: string; width?: number; height?: number; frame_start?: number; frame_end?: number; playback?: Opaque<"constant">; fps?: number; flip_vertical?: boolean; flip_horizontal?: boolean }[]; geometries?: Record<string | number, unknown>; vertices?: number[]; uvs?: number[]; indices?: number[] }): void;
@@ -991,38 +1024,37 @@ declare global {
991
1024
  * `transfer_ownership`
992
1025
  * boolean optional flag to determine wether or not the resource should take over ownership of the buffer object (default false)
993
1026
  * @example
994
- * ```lua
995
- * How to set the data from a buffer
996
- * local function fill_stream(stream, verts)
997
- * for key, value in ipairs(verts) do
998
- * stream[key] = verts[key]
999
- * end
1000
- * end
1027
+ * ```ts
1028
+ * // How to set the data from a buffer
1029
+ * function fill_stream(stream, verts) {
1030
+ * verts.forEach((value, key) => {
1031
+ * stream[key] = verts[key];
1032
+ * });
1033
+ * }
1001
1034
  *
1002
- * function init(self)
1035
+ * export default defineScript({
1036
+ * init() {
1037
+ * const res_path = go.get("#mesh", "vertices");
1003
1038
  *
1004
- * local res_path = go.get("#mesh", "vertices")
1039
+ * const positions = [
1040
+ * 1, -1, 0,
1041
+ * 1, 1, 0,
1042
+ * -1, -1, 0,
1043
+ * ];
1005
1044
  *
1006
- * local positions = {
1007
- * 1, -1, 0,
1008
- * 1, 1, 0,
1009
- * -1, -1, 0
1010
- * }
1011
- *
1012
- * local num_verts = #positions / 3
1045
+ * const num_verts = positions.length / 3;
1013
1046
  *
1014
- * -- create a new buffer
1015
- * local buf = buffer.create(num_verts, {
1016
- * { name = hash("position"), type=buffer.VALUE_TYPE_FLOAT32, count = 3 }
1017
- * })
1047
+ * // create a new buffer
1048
+ * let buf = buffer.create(num_verts, [{ name: hash("position"), type: buffer.VALUE_TYPE_FLOAT32, count: 3 }]);
1018
1049
  *
1019
- * local buf = resource.get_buffer(res_path)
1020
- * local stream_positions = buffer.get_stream(buf, "position")
1050
+ * buf = resource.get_buffer(res_path);
1051
+ * const stream_positions = buffer.get_stream(buf, "position");
1021
1052
  *
1022
- * fill_stream(stream_positions, positions)
1053
+ * fill_stream(stream_positions, positions);
1023
1054
  *
1024
- * resource.set_buffer(res_path, buf)
1025
- * end
1055
+ * resource.set_buffer(res_path, buf);
1056
+ * },
1057
+ * });
1026
1058
  * ```
1027
1059
  */
1028
1060
  function set_buffer(path: Hash | string, buffer: Opaque<"buffer">, table?: { transfer_ownership?: boolean }): void;
@@ -1102,119 +1134,128 @@ declare global {
1102
1134
  * -- Device and graphics adapter support 3D textures
1103
1135
  * end
1104
1136
  * @example
1105
- * ```lua
1106
- * How to set all pixels of an atlas
1107
- * function init(self)
1108
- * self.height = 128
1109
- * self.width = 128
1110
- * self.buffer = buffer.create(self.width * self.height, { {name=hash("rgb"), type=buffer.VALUE_TYPE_UINT8, count=3} } )
1111
- * self.stream = buffer.get_stream(self.buffer, hash("rgb"))
1112
- *
1113
- * for y=1,self.height do
1114
- * for x=1,self.width do
1115
- * local index = (y-1) * self.width * 3 + (x-1) * 3 + 1
1116
- * self.stream[index + 0] = 0xff
1117
- * self.stream[index + 1] = 0x80
1118
- * self.stream[index + 2] = 0x10
1119
- * end
1120
- * end
1121
- *
1122
- * local resource_path = go.get("#model", "texture0")
1123
- * local args = { width=self.width, height=self.height, type=graphics.TEXTURE_TYPE_2D, format=graphics.TEXTURE_FORMAT_RGB, num_mip_maps=1 }
1124
- * resource.set_texture( resource_path, args, self.buffer )
1125
- * end
1126
- * ```How to update a specific region of an atlas by using the x,y values. Assumes the already set atlas is a 128x128 texture.
1127
- *
1128
- * ```lua
1129
- * function init(self)
1130
- * self.x = 16
1131
- * self.y = 16
1132
- * self.height = 128 - self.x * 2
1133
- * self.width = 128 - self.y * 2
1134
- * self.buffer = buffer.create(self.width * self.height, { {name=hash("rgb"), type=buffer.VALUE_TYPE_UINT8, count=3} } )
1135
- * self.stream = buffer.get_stream(self.buffer, hash("rgb"))
1136
- *
1137
- * for y=1,self.height do
1138
- * for x=1,self.width do
1139
- * local index = (y-1) * self.width * 3 + (x-1) * 3 + 1
1140
- * self.stream[index + 0] = 0xff
1141
- * self.stream[index + 1] = 0x80
1142
- * self.stream[index + 2] = 0x10
1143
- * end
1144
- * end
1145
- *
1146
- * local resource_path = go.get("#model", "texture0")
1147
- * local args = { width=self.width, height=self.height, x=self.x, y=self.y, type=graphics.TEXTURE_TYPE_2D, format=graphics.TEXTURE_FORMAT_RGB, num_mip_maps=1 }
1148
- * resource.set_texture(resource_path, args, self.buffer )
1149
- * end
1150
- * ```Update a texture from a buffer resource
1151
- * ```lua
1152
- * go.property("my_buffer", resource.buffer("/my_default_buffer.buffer"))
1153
- *
1154
- * function init(self)
1155
- * local resource_path = go.get("#model", "texture0")
1156
- * -- the "my_buffer" resource is expected to hold 128 * 128 * 3 bytes!
1157
- * local args = {
1158
- * width = 128,
1159
- * height = 128,
1160
- * type = graphics.TEXTURE_TYPE_2D,
1161
- * format = graphics.TEXTURE_FORMAT_RGB
1162
- * }
1163
- * -- Note that the extra resource.get_buffer call is a requirement here
1164
- * -- since the "self.my_buffer" is just pointing to a buffer resource path
1165
- * -- and not an actual buffer object or buffer resource.
1166
- * resource.set_texture(resource_path, args, resource.get_buffer(self.my_buffer))
1167
- * end
1168
- * ```Update an existing 3D texture from a lua buffer
1169
- *
1170
- * ```lua
1137
+ * ```ts
1138
+ * // How to set all pixels of an atlas
1139
+ * export default defineScript({
1140
+ * init(self) {
1141
+ * self.height = 128;
1142
+ * self.width = 128;
1143
+ * self.buffer = buffer.create(self.width * self.height, [{ name: hash("rgb"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);
1144
+ * self.stream = buffer.get_stream(self.buffer, hash("rgb"));
1145
+ *
1146
+ * for (let y = 0; y < self.height; y++) {
1147
+ * for (let x = 0; x < self.width; x++) {
1148
+ * const index = y * self.width * 3 + x * 3;
1149
+ * self.stream[index + 0] = 0xff;
1150
+ * self.stream[index + 1] = 0x80;
1151
+ * self.stream[index + 2] = 0x10;
1152
+ * }
1153
+ * }
1171
1154
  *
1172
- * function init(self)
1173
- * -- create a buffer that can hold the data of a 8x8x8 texture
1174
- * local tbuffer = buffer.create(8 * 8 * 8, { {name=hash("rgba"), type=buffer.VALUE_TYPE_FLOAT32, count=4} } )
1175
- * local tstream = buffer.get_stream(tbuffer, hash("rgba"))
1176
- *
1177
- * -- populate the buffer with some data
1178
- * local index = 1
1179
- * for z=1,8 do
1180
- * for y=1,8 do
1181
- * for x=1,8 do
1182
- * tstream[index + 0] = x
1183
- * tstream[index + 1] = y
1184
- * tstream[index + 2] = z
1185
- * tstream[index + 3] = 1.0
1186
- * index = index + 4
1187
- * end
1188
- * end
1189
- * end
1190
- *
1191
- * local t_args = {
1192
- * type = graphics.TEXTURE_TYPE_IMAGE_3D,
1193
- * width = 8,
1194
- * height = 8,
1195
- * depth = 8,
1196
- * format = resource.TEXTURE_FORMAT_RGBA32F
1155
+ * const resource_path = go.get("#model", "texture0");
1156
+ * const args = { width: self.width, height: self.height, type: graphics.TEXTURE_TYPE_2D, format: graphics.TEXTURE_FORMAT_RGB, num_mip_maps: 1 };
1157
+ * resource.set_texture(resource_path, args, self.buffer);
1158
+ * },
1159
+ * });
1160
+ *
1161
+ * // How to update a specific region of an atlas by using the x,y values. Assumes the already set atlas is a 128x128 texture.
1162
+ * export default defineScript({
1163
+ * init(self) {
1164
+ * self.x = 16;
1165
+ * self.y = 16;
1166
+ * self.height = 128 - self.x * 2;
1167
+ * self.width = 128 - self.y * 2;
1168
+ * self.buffer = buffer.create(self.width * self.height, [{ name: hash("rgb"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);
1169
+ * self.stream = buffer.get_stream(self.buffer, hash("rgb"));
1170
+ *
1171
+ * for (let y = 0; y < self.height; y++) {
1172
+ * for (let x = 0; x < self.width; x++) {
1173
+ * const index = y * self.width * 3 + x * 3;
1174
+ * self.stream[index + 0] = 0xff;
1175
+ * self.stream[index + 1] = 0x80;
1176
+ * self.stream[index + 2] = 0x10;
1177
+ * }
1197
1178
  * }
1198
1179
  *
1199
- * -- This expects that the texture resource "/my_3d_texture.texturec" already exists
1200
- * -- and is a 3D texture resource. To create a dynamic 3D texture resource
1201
- * -- use the "resource.create_texture" function.
1202
- * resource.set_texture("/my_3d_texture.texturec", t_args, tbuffer)
1203
- * endUpdate texture 2nd array page with loaded texture from png
1180
+ * const resource_path = go.get("#model", "texture0");
1181
+ * const args = { width: self.width, height: self.height, x: self.x, y: self.y, type: graphics.TEXTURE_TYPE_2D, format: graphics.TEXTURE_FORMAT_RGB, num_mip_maps: 1 };
1182
+ * resource.set_texture(resource_path, args, self.buffer);
1183
+ * },
1184
+ * });
1185
+ *
1186
+ * // Update a texture from a buffer resource
1187
+ * go.property("my_buffer", resource.buffer("/my_default_buffer.buffer"));
1188
+ *
1189
+ * export default defineScript({
1190
+ * init(self) {
1191
+ * const resource_path = go.get("#model", "texture0");
1192
+ * // the "my_buffer" resource is expected to hold 128 * 128 * 3 bytes!
1193
+ * const args = {
1194
+ * width: 128,
1195
+ * height: 128,
1196
+ * type: graphics.TEXTURE_TYPE_2D,
1197
+ * format: graphics.TEXTURE_FORMAT_RGB,
1198
+ * };
1199
+ * // Note that the extra resource.get_buffer call is a requirement here
1200
+ * // since the "self.my_buffer" is just pointing to a buffer resource path
1201
+ * // and not an actual buffer object or buffer resource.
1202
+ * resource.set_texture(resource_path, args, resource.get_buffer(self.my_buffer));
1203
+ * },
1204
+ * });
1205
+ *
1206
+ * // Update an existing 3D texture from a buffer
1207
+ * export default defineScript({
1208
+ * init() {
1209
+ * // create a buffer that can hold the data of a 8x8x8 texture
1210
+ * const tbuffer = buffer.create(8 * 8 * 8, [{ name: hash("rgba"), type: buffer.VALUE_TYPE_FLOAT32, count: 4 }]);
1211
+ * const tstream = buffer.get_stream(tbuffer, hash("rgba"));
1212
+ *
1213
+ * // populate the buffer with some data
1214
+ * let index = 0;
1215
+ * for (let z = 0; z < 8; z++) {
1216
+ * for (let y = 0; y < 8; y++) {
1217
+ * for (let x = 0; x < 8; x++) {
1218
+ * tstream[index + 0] = x;
1219
+ * tstream[index + 1] = y;
1220
+ * tstream[index + 2] = z;
1221
+ * tstream[index + 3] = 1.0;
1222
+ * index = index + 4;
1223
+ * }
1224
+ * }
1225
+ * }
1204
1226
  *
1205
- * ```lua
1206
- * -- new_tex is resource handle of texture which was created via resource.create_resource
1207
- * local tex_path = "/bundle_resources/page_02.png"
1208
- * local data = sys.load_resource(tex_path)
1209
- * local buf = image.load_buffer(data)
1210
- * resource.set_texture(new_tex, {
1211
- * type = graphics.TEXTURE_TYPE_2D_ARRAY,
1212
- * width = buf.width,
1213
- * height = buf.height,
1214
- * page = 1,
1215
- * format = graphics.TEXTURE_FORMAT_RGB
1216
- * }, buf.buffer)
1217
- * go.set("#mesh", "texture0", new_tex)
1227
+ * const t_args = {
1228
+ * type: graphics.TEXTURE_TYPE_IMAGE_3D,
1229
+ * width: 8,
1230
+ * height: 8,
1231
+ * depth: 8,
1232
+ * format: resource.TEXTURE_FORMAT_RGBA32F,
1233
+ * };
1234
+ *
1235
+ * // This expects that the texture resource "/my_3d_texture.texturec" already exists
1236
+ * // and is a 3D texture resource. To create a dynamic 3D texture resource
1237
+ * // use the "resource.create_texture" function.
1238
+ * resource.set_texture("/my_3d_texture.texturec", t_args, tbuffer);
1239
+ * },
1240
+ * });
1241
+ *
1242
+ * // Update texture 2nd array page with loaded texture from png
1243
+ * // new_tex is resource handle of texture which was created via resource.create_resource
1244
+ * const tex_path = "/bundle_resources/page_02.png";
1245
+ * const [data] = sys.load_resource(tex_path);
1246
+ * const buf = image.load_buffer(data);
1247
+ * resource.set_texture(
1248
+ * new_tex,
1249
+ * {
1250
+ * type: graphics.TEXTURE_TYPE_2D_ARRAY,
1251
+ * width: buf.width,
1252
+ * height: buf.height,
1253
+ * page: 1,
1254
+ * format: graphics.TEXTURE_FORMAT_RGB,
1255
+ * },
1256
+ * buf.buffer,
1257
+ * );
1258
+ * go.set("#mesh", "texture0", new_tex);
1218
1259
  * ```
1219
1260
  */
1220
1261
  function set_texture(path: Hash | string, table: { type?: number; width?: number; height?: number; format?: number; x?: number; y?: number; z?: number; page?: number; mipmap?: number; compression_type?: number }, buffer: Opaque<"buffer">): void;
@@ -1227,12 +1268,15 @@ declare global {
1227
1268
  * @param path - optional resource path string to the resource
1228
1269
  * @returns a path hash to the binary version of the resource
1229
1270
  * @example
1230
- * ```lua
1231
- * Load a texture and set it to a model:
1232
- * go.property("my_texture", resource.texture("/texture.png"))
1233
- * function init(self)
1234
- * go.set("#model", "texture0", self.my_texture)
1235
- * end
1271
+ * ```ts
1272
+ * // Load a texture and set it to a model:
1273
+ * go.property("my_texture", resource.texture("/texture.png"));
1274
+ *
1275
+ * export default defineScript({
1276
+ * init(self) {
1277
+ * go.set("#model", "texture0", self.my_texture);
1278
+ * },
1279
+ * });
1236
1280
  * ```
1237
1281
  */
1238
1282
  function texture(path?: string): Hash;
@@ -1245,12 +1289,15 @@ declare global {
1245
1289
  * @param path - optional resource path string to the resource
1246
1290
  * @returns a path hash to the binary version of the resource
1247
1291
  * @example
1248
- * ```lua
1249
- * Load tile source and set it to a tile map:
1250
- * go.property("my_tile_source", resource.tile_source("/tilesource.tilesource"))
1251
- * function init(self)
1252
- * go.set("#tilemap", "tile_source", self.my_tile_source)
1253
- * end
1292
+ * ```ts
1293
+ * // Load tile source and set it to a tile map:
1294
+ * go.property("my_tile_source", resource.tile_source("/tilesource.tilesource"));
1295
+ *
1296
+ * export default defineScript({
1297
+ * init(self) {
1298
+ * go.set("#tilemap", "tile_source", self.my_tile_source);
1299
+ * },
1300
+ * });
1254
1301
  * ```
1255
1302
  */
1256
1303
  function tile_source(path?: string): Hash;