@defold-typescript/types 0.49.0 → 0.50.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 (76) hide show
  1. package/api-availability.json +696 -624
  2. package/api-signatures.json +6799 -160
  3. package/api-targets.json +393 -2
  4. package/examples/translations.json +12 -0
  5. package/generated/b2d.d.ts +15 -0
  6. package/generated/bullet3d.d.ts +16 -0
  7. package/generated/font.d.ts +7 -3
  8. package/generated/graphics.d.ts +7 -0
  9. package/generated/gui.d.ts +5 -4
  10. package/generated/label.d.ts +3 -3
  11. package/generated/render.d.ts +16 -1
  12. package/generated/versions/defold-1.13.2/b2d.d.ts +709 -0
  13. package/generated/versions/defold-1.13.2/b2d_body.d.ts +593 -0
  14. package/generated/versions/defold-1.13.2/b2d_chain.d.ts +105 -0
  15. package/generated/versions/defold-1.13.2/b2d_fixture.d.ts +175 -0
  16. package/generated/versions/defold-1.13.2/b2d_joint.d.ts +1301 -0
  17. package/generated/versions/defold-1.13.2/b2d_shape.d.ts +423 -0
  18. package/generated/versions/defold-1.13.2/b2d_world.d.ts +308 -0
  19. package/generated/versions/defold-1.13.2/buffer.d.ts +192 -0
  20. package/generated/versions/defold-1.13.2/bullet3d.d.ts +91 -0
  21. package/generated/versions/defold-1.13.2/bullet3d_collision_object.d.ts +433 -0
  22. package/generated/versions/defold-1.13.2/bullet3d_constraint.d.ts +818 -0
  23. package/generated/versions/defold-1.13.2/bullet3d_rigid_body.d.ts +429 -0
  24. package/generated/versions/defold-1.13.2/bullet3d_shape.d.ts +123 -0
  25. package/generated/versions/defold-1.13.2/bullet3d_world.d.ts +492 -0
  26. package/generated/versions/defold-1.13.2/camera.d.ts +300 -0
  27. package/generated/versions/defold-1.13.2/collectionfactory.d.ts +148 -0
  28. package/generated/versions/defold-1.13.2/collectionproxy.d.ts +109 -0
  29. package/generated/versions/defold-1.13.2/compute.d.ts +107 -0
  30. package/generated/versions/defold-1.13.2/crash.d.ts +157 -0
  31. package/generated/versions/defold-1.13.2/editor-vm/http.d.ts +139 -0
  32. package/generated/versions/defold-1.13.2/editor-vm/image.d.ts +48 -0
  33. package/generated/versions/defold-1.13.2/editor-vm/json.d.ts +21 -0
  34. package/generated/versions/defold-1.13.2/editor-vm/localization.d.ts +42 -0
  35. package/generated/versions/defold-1.13.2/editor-vm/tilemap_tiles.d.ts +126 -0
  36. package/generated/versions/defold-1.13.2/editor-vm/zip.d.ts +38 -0
  37. package/generated/versions/defold-1.13.2/editor-vm/zlib.d.ts +24 -0
  38. package/generated/versions/defold-1.13.2/editor.d.ts +2177 -0
  39. package/generated/versions/defold-1.13.2/factory.d.ts +121 -0
  40. package/generated/versions/defold-1.13.2/font.d.ts +123 -0
  41. package/generated/versions/defold-1.13.2/go.d.ts +1166 -0
  42. package/generated/versions/defold-1.13.2/graphics.d.ts +613 -0
  43. package/generated/versions/defold-1.13.2/gui.d.ts +2212 -0
  44. package/generated/versions/defold-1.13.2/html5.d.ts +55 -0
  45. package/generated/versions/defold-1.13.2/http.d.ts +83 -0
  46. package/generated/versions/defold-1.13.2/image.d.ts +181 -0
  47. package/generated/versions/defold-1.13.2/index.d.ts +63 -0
  48. package/generated/versions/defold-1.13.2/json.d.ts +94 -0
  49. package/generated/versions/defold-1.13.2/kinds/editor-script.d.ts +14 -0
  50. package/generated/versions/defold-1.13.2/label.d.ts +164 -0
  51. package/generated/versions/defold-1.13.2/liveupdate.d.ts +143 -0
  52. package/generated/versions/defold-1.13.2/material.d.ts +490 -0
  53. package/generated/versions/defold-1.13.2/model.d.ts +287 -0
  54. package/generated/versions/defold-1.13.2/msg.d.ts +10 -0
  55. package/generated/versions/defold-1.13.2/particlefx.d.ts +155 -0
  56. package/generated/versions/defold-1.13.2/physics.d.ts +789 -0
  57. package/generated/versions/defold-1.13.2/profiler.d.ts +228 -0
  58. package/generated/versions/defold-1.13.2/render.d.ts +1153 -0
  59. package/generated/versions/defold-1.13.2/resource.d.ts +1628 -0
  60. package/generated/versions/defold-1.13.2/socket.d.ts +797 -0
  61. package/generated/versions/defold-1.13.2/sound.d.ts +323 -0
  62. package/generated/versions/defold-1.13.2/sprite.d.ts +179 -0
  63. package/generated/versions/defold-1.13.2/sys.d.ts +754 -0
  64. package/generated/versions/defold-1.13.2/tilemap.d.ts +206 -0
  65. package/generated/versions/defold-1.13.2/timer.d.ts +136 -0
  66. package/generated/versions/defold-1.13.2/types.d.ts +61 -0
  67. package/generated/versions/defold-1.13.2/vmath.d.ts +775 -0
  68. package/generated/versions/defold-1.13.2/window.d.ts +196 -0
  69. package/generated/versions/defold-1.13.2/zlib.d.ts +41 -0
  70. package/identity-vocabulary.json +1 -0
  71. package/package.json +2 -2
  72. package/scripts/import-defold-release.ts +3 -31
  73. package/scripts/materialize-version.ts +13 -7
  74. package/scripts/regen.ts +63 -29
  75. package/scripts/sync-api-docs.ts +31 -2
  76. package/src/emit-dts.ts +25 -3
@@ -0,0 +1,1628 @@
1
+ /** @noSelfInFile */
2
+ import type { Hash, Opaque } from "../../../src/core-types";
3
+
4
+ declare global {
5
+ /**
6
+ * Functions and constants to access resources.
7
+ */
8
+ namespace resource {
9
+ /**
10
+ * Animation data accepted when creating or updating an atlas. Specify either
11
+ * `frames`, or both `frame_start` and `frame_end`.
12
+ */
13
+ interface animation {
14
+ /**
15
+ * Animation id.
16
+ */
17
+ id: string;
18
+ /**
19
+ * Animation width.
20
+ */
21
+ width: number;
22
+ /**
23
+ * Animation height.
24
+ */
25
+ height: number;
26
+ /**
27
+ * Geometry indices for the animation frames.
28
+ */
29
+ frames?: number[];
30
+ /**
31
+ * First geometry index for the legacy contiguous frame range.
32
+ */
33
+ frame_start?: number;
34
+ /**
35
+ * Non-inclusive last geometry index for the legacy contiguous frame range.
36
+ */
37
+ frame_end?: number;
38
+ /**
39
+ * Playback mode. The default is `go.PLAYBACK_ONCE_FORWARD`.
40
+ */
41
+ playback?: go.PLAYBACK;
42
+ /**
43
+ * Animation frame rate. The default is 30.
44
+ */
45
+ fps?: number;
46
+ /**
47
+ * Whether to flip the animation vertically. The default is false.
48
+ */
49
+ flip_vertical?: boolean;
50
+ /**
51
+ * Whether to flip the animation horizontally. The default is false.
52
+ */
53
+ flip_horizontal?: boolean;
54
+ }
55
+ /**
56
+ * Animation data returned by resource.get_atlas.
57
+ */
58
+ interface animation_data {
59
+ /**
60
+ * Animation id.
61
+ */
62
+ id: string;
63
+ /**
64
+ * Animation width.
65
+ */
66
+ width: number;
67
+ /**
68
+ * Animation height.
69
+ */
70
+ height: number;
71
+ /**
72
+ * Geometry indices for the animation frames.
73
+ */
74
+ frames: number[];
75
+ /**
76
+ * Playback mode.
77
+ */
78
+ playback: go.PLAYBACK;
79
+ /**
80
+ * Animation frame rate.
81
+ */
82
+ fps: number;
83
+ /**
84
+ * Whether the animation is flipped vertically.
85
+ */
86
+ flip_vertical: boolean;
87
+ /**
88
+ * Whether the animation is flipped horizontally.
89
+ */
90
+ flip_horizontal: boolean;
91
+ }
92
+ /**
93
+ * Data accepted by resource.create_atlas and resource.set_atlas.
94
+ */
95
+ interface atlas {
96
+ /**
97
+ * Path to the texture resource, for example `"/main/my_texture.texturec"`.
98
+ */
99
+ texture: string | Hash;
100
+ /**
101
+ * Animations in the atlas.
102
+ */
103
+ animations: [Omit<resource.animation, "frame_start" | "frame_end"> & ({ frames: [number, ...number[]] } | { frame_start: number; frame_end: number }), ...(Omit<resource.animation, "frame_start" | "frame_end"> & ({ frames: [number, ...number[]] } | { frame_start: number; frame_end: number }))[]];
104
+ /**
105
+ * Geometries that map to the texture data.
106
+ */
107
+ geometries: [resource.geometry, ...resource.geometry[]];
108
+ }
109
+ /**
110
+ * Data returned by resource.get_atlas.
111
+ */
112
+ interface atlas_data {
113
+ /**
114
+ * Path to the texture resource.
115
+ */
116
+ texture: string | Hash;
117
+ /**
118
+ * Animations in the atlas.
119
+ */
120
+ animations: resource.animation_data[];
121
+ /**
122
+ * Geometries that map to the texture data.
123
+ */
124
+ geometries: resource.geometry_data[];
125
+ }
126
+ /**
127
+ * Buffer-resource creation parameters
128
+ */
129
+ interface buffer_creation_params {
130
+ /**
131
+ * Buffer to bind to the resource.
132
+ */
133
+ buffer: Opaque<"buffer">;
134
+ /**
135
+ * Whether the resource takes ownership of the buffer. The default is true.
136
+ */
137
+ transfer_ownership?: boolean;
138
+ }
139
+ /**
140
+ * Buffer-resource update options
141
+ */
142
+ interface buffer_update_options {
143
+ /**
144
+ * Whether the resource takes ownership of the buffer. The default is false.
145
+ */
146
+ transfer_ownership?: boolean;
147
+ }
148
+ /**
149
+ * Geometry data accepted when creating or updating an atlas. Vertex, UV, and
150
+ * index values are zero-based.
151
+ */
152
+ interface geometry {
153
+ /**
154
+ * Geometry name, used when matching animations between atlases.
155
+ */
156
+ id?: string;
157
+ /**
158
+ * Width of the image represented by the geometry. If omitted, it is calculated from the vertices.
159
+ */
160
+ width?: number;
161
+ /**
162
+ * Height of the image represented by the geometry. If omitted, it is calculated from the vertices.
163
+ */
164
+ height?: number;
165
+ /**
166
+ * Horizontal pivot in unit coordinates. The default is 0.5.
167
+ */
168
+ pivot_x?: number;
169
+ /**
170
+ * Vertical pivot in unit coordinates. The default is 0.5.
171
+ */
172
+ pivot_y?: number;
173
+ /**
174
+ * Whether the image is rotated 90 degrees counter-clockwise in the atlas.
175
+ */
176
+ rotated?: boolean;
177
+ /**
178
+ * Vertex coordinates in image space as `{px0, py0, px1, py1, ...}`.
179
+ */
180
+ vertices: number[];
181
+ /**
182
+ * UV coordinates in image space as `{u0, v0, u1, v1, ...}`.
183
+ */
184
+ uvs: number[];
185
+ /**
186
+ * Geometry indices where each group of three entries represents a triangle.
187
+ */
188
+ indices: number[];
189
+ }
190
+ /**
191
+ * Geometry data returned by resource.get_atlas.
192
+ */
193
+ interface geometry_data {
194
+ /**
195
+ * Width of the image represented by the geometry.
196
+ */
197
+ width: number;
198
+ /**
199
+ * Height of the image represented by the geometry.
200
+ */
201
+ height: number;
202
+ /**
203
+ * Horizontal pivot in unit coordinates.
204
+ */
205
+ pivot_x: number;
206
+ /**
207
+ * Vertical pivot in unit coordinates.
208
+ */
209
+ pivot_y: number;
210
+ /**
211
+ * Whether the image is rotated 90 degrees counter-clockwise in the atlas.
212
+ */
213
+ rotated: boolean;
214
+ /**
215
+ * Vertex coordinates in image space as `{px0, py0, px1, py1, ...}`.
216
+ */
217
+ vertices: number[];
218
+ /**
219
+ * UV coordinates in image space as `{u0, v0, u1, v1, ...}`.
220
+ */
221
+ uvs: number[];
222
+ /**
223
+ * Geometry indices where each group of three entries represents a triangle.
224
+ */
225
+ indices: number[];
226
+ }
227
+ /**
228
+ * Render target attachment information
229
+ */
230
+ interface render_target_attachment_info {
231
+ /**
232
+ * Opaque texture handle.
233
+ */
234
+ handle: Opaque<"texture">;
235
+ /**
236
+ * Texture width.
237
+ */
238
+ width: number;
239
+ /**
240
+ * Texture height.
241
+ */
242
+ height: number;
243
+ /**
244
+ * Texture depth or layer count.
245
+ */
246
+ depth: number;
247
+ /**
248
+ * Texture page count.
249
+ */
250
+ page_count: number;
251
+ /**
252
+ * Number of mipmaps.
253
+ */
254
+ mipmaps: number;
255
+ /**
256
+ * Texture usage flags.
257
+ */
258
+ flags: graphics.TEXTURE_USAGE_FLAG | number;
259
+ /**
260
+ * Texture type.
261
+ */
262
+ type: graphics.TEXTURE_TYPE;
263
+ /**
264
+ * Render-target buffer type.
265
+ */
266
+ buffer_type: graphics.BUFFER_TYPE;
267
+ /**
268
+ * Backing texture resource, when present.
269
+ */
270
+ texture?: Hash;
271
+ }
272
+ /**
273
+ * Render target information
274
+ */
275
+ interface render_target_info {
276
+ /**
277
+ * Opaque render-target handle.
278
+ */
279
+ handle: Opaque<"render_target">;
280
+ /**
281
+ * Effective sample count shared by all render-target attachments.
282
+ */
283
+ sample_count: number;
284
+ /**
285
+ * Render-target attachments.
286
+ */
287
+ attachments: resource.render_target_attachment_info[];
288
+ }
289
+ type resource_data = Hash;
290
+ /**
291
+ * Sound-data creation options
292
+ */
293
+ interface sound_data_options {
294
+ /**
295
+ * Raw sound file data, including the file header.
296
+ */
297
+ data: string | Opaque<"buffer">;
298
+ /**
299
+ * Complete file size when `data` is partial.
300
+ */
301
+ filesize?: number;
302
+ /**
303
+ * Whether `data` contains only the initial file chunk.
304
+ */
305
+ partial?: boolean;
306
+ }
307
+ /**
308
+ * Text metrics
309
+ */
310
+ interface text_metrics {
311
+ /**
312
+ * Text width.
313
+ */
314
+ width: number;
315
+ /**
316
+ * Text height.
317
+ */
318
+ height: number;
319
+ /**
320
+ * Maximum ascent.
321
+ */
322
+ max_ascent: number;
323
+ /**
324
+ * Maximum descent.
325
+ */
326
+ max_descent: number;
327
+ }
328
+ /**
329
+ * Text metric options
330
+ */
331
+ interface text_metrics_options {
332
+ /**
333
+ * Text-field width; unused when `line_break` is false.
334
+ */
335
+ width?: number;
336
+ /**
337
+ * Line leading. The default is 1.
338
+ */
339
+ leading?: number;
340
+ /**
341
+ * Character tracking. The default is 0.
342
+ */
343
+ tracking?: number;
344
+ /**
345
+ * Whether to account for line breaks. The default is false.
346
+ */
347
+ line_break?: boolean;
348
+ }
349
+ /**
350
+ * Texture creation parameters
351
+ */
352
+ interface texture_creation_params {
353
+ /**
354
+ * Texture type.
355
+ */
356
+ type: graphics.TEXTURE_TYPE;
357
+ /**
358
+ * Texture width in pixels; must be greater than zero.
359
+ */
360
+ width: number;
361
+ /**
362
+ * Texture height in pixels; must be greater than zero.
363
+ */
364
+ height: number;
365
+ /**
366
+ * Texture depth; used by 3D texture types and must be greater than zero.
367
+ */
368
+ depth?: number;
369
+ /**
370
+ * Number of pages for a 2D array texture.
371
+ */
372
+ page_count?: number;
373
+ /**
374
+ * Texture format. Device-specific unsupported constants evaluate to `nil`.
375
+ */
376
+ format: graphics.TEXTURE_FORMAT;
377
+ /**
378
+ * Creation-usage hints. The default is graphics.TEXTURE_USAGE_FLAG_SAMPLE.
379
+ */
380
+ flags?: graphics.TEXTURE_USAGE_FLAG | number;
381
+ /**
382
+ * Maximum mipmap count. The default is zero.
383
+ */
384
+ max_mipmaps?: number;
385
+ /**
386
+ * Compression used by the supplied buffer. The default is graphics.COMPRESSION_TYPE_DEFAULT.
387
+ */
388
+ compression_type?: graphics.COMPRESSION_TYPE;
389
+ }
390
+ /**
391
+ * Asynchronous texture creation result
392
+ */
393
+ interface texture_creation_result {
394
+ /**
395
+ * Created texture resource path.
396
+ */
397
+ path: Hash;
398
+ }
399
+ /**
400
+ * Texture information
401
+ */
402
+ interface texture_info {
403
+ /**
404
+ * Opaque texture handle.
405
+ */
406
+ handle: Opaque<"texture">;
407
+ /**
408
+ * Texture width.
409
+ */
410
+ width: number;
411
+ /**
412
+ * Texture height.
413
+ */
414
+ height: number;
415
+ /**
416
+ * Texture depth or layer count.
417
+ */
418
+ depth: number;
419
+ /**
420
+ * Texture page count.
421
+ */
422
+ page_count: number;
423
+ /**
424
+ * Number of mipmaps.
425
+ */
426
+ mipmaps: number;
427
+ /**
428
+ * Texture usage flags.
429
+ */
430
+ flags: graphics.TEXTURE_USAGE_FLAG | number;
431
+ /**
432
+ * Texture type.
433
+ */
434
+ type: graphics.TEXTURE_TYPE;
435
+ }
436
+ /**
437
+ * Texture update parameters
438
+ */
439
+ interface texture_update_params {
440
+ /**
441
+ * Texture type.
442
+ */
443
+ type: graphics.TEXTURE_TYPE;
444
+ /**
445
+ * Update width in pixels.
446
+ */
447
+ width: number;
448
+ /**
449
+ * Update height in pixels.
450
+ */
451
+ height: number;
452
+ /**
453
+ * Update depth for a 3D texture.
454
+ */
455
+ depth?: number;
456
+ /**
457
+ * Texture format. Device-specific unsupported constants evaluate to `nil`.
458
+ */
459
+ format: graphics.TEXTURE_FORMAT;
460
+ /**
461
+ * X offset in pixels.
462
+ */
463
+ x?: number;
464
+ /**
465
+ * Y offset in pixels.
466
+ */
467
+ y?: number;
468
+ /**
469
+ * Z offset for a 3D texture.
470
+ */
471
+ z?: number;
472
+ /**
473
+ * Zero-based page of a 2D array texture.
474
+ */
475
+ page?: number;
476
+ /**
477
+ * Mipmap level to update.
478
+ */
479
+ mipmap?: number;
480
+ /**
481
+ * Compression used by the supplied buffer. The default is graphics.COMPRESSION_TYPE_DEFAULT.
482
+ */
483
+ compression_type?: graphics.COMPRESSION_TYPE;
484
+ }
485
+ /**
486
+ * Constructor-like function with two purposes:
487
+ *
488
+ * - Load the specified resource as part of loading the script
489
+ * - Create a resource reference that resolves to the hashed path of the run-time resource
490
+ *
491
+ * This function can only be called within go.property function calls.
492
+ *
493
+ * @param path - optional resource path string to the resource
494
+ * @returns a reference to the binary version of the resource
495
+ * @example
496
+ * Load an atlas and set it to a sprite:
497
+ * ```ts
498
+ * // Load an atlas and set it to a sprite:
499
+ * export default defineScript({
500
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
501
+ * // registration from this field, and only this field types the property onto `self`.
502
+ * properties: { my_atlas: resource.atlas("/atlas.atlas") },
503
+ *
504
+ * init(self) {
505
+ * go.set("#sprite", "image", self.my_atlas);
506
+ * },
507
+ * });
508
+ * ```
509
+ * @example
510
+ * Load an atlas and set it to a gui:
511
+ * ```ts
512
+ * // Load an atlas and set it to a gui:
513
+ * export default defineScript({
514
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
515
+ * // registration from this field, and only this field types the property onto `self`.
516
+ * properties: { my_atlas: resource.atlas("/atlas.atlas") },
517
+ *
518
+ * init(self) {
519
+ * go.set("#gui", "textures", self.my_atlas, { key: "my_atlas" });
520
+ * },
521
+ * });
522
+ * ```
523
+ */
524
+ function atlas(path?: string): Hash;
525
+ /**
526
+ * Constructor-like function with two purposes:
527
+ *
528
+ * - Load the specified resource as part of loading the script
529
+ * - Create a resource reference that resolves to the hashed path of the run-time resource
530
+ *
531
+ * This function can only be called within go.property function calls.
532
+ *
533
+ * @param path - optional resource path string to the resource
534
+ * @returns a reference to the binary version of the resource
535
+ * @example
536
+ * ```ts
537
+ * // Set a unique buffer it to a sprite:
538
+ * export default defineScript({
539
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
540
+ * // registration from this field, and only this field types the property onto `self`.
541
+ * properties: { my_buffer: resource.buffer("/cube.buffer") },
542
+ *
543
+ * init(self) {
544
+ * go.set("#mesh", "vertices", self.my_buffer);
545
+ * },
546
+ * });
547
+ * ```
548
+ */
549
+ function buffer(path?: string): Hash;
550
+ /**
551
+ * This function creates a new atlas resource that can be used in the same way as any atlas created during build time.
552
+ * The path used for creating the atlas must be unique, trying to create a resource at a path that is already
553
+ * registered will trigger an error. If the intention is to instead modify an existing atlas, use the resource.set_atlas
554
+ * function. Also note that the path to the new atlas resource must have a '.texturesetc' extension,
555
+ * meaning "/path/my_atlas" is not a valid path but "/path/my_atlas.texturesetc" is.
556
+ * When creating the atlas, at least one geometry and one animation is required, and an error will be
557
+ * raised if these requirements are not met. A reference to the resource will be held by the collection
558
+ * that created the resource and will automatically be released when that collection is destroyed.
559
+ * Note that releasing a resource essentially means decreasing the reference count of that resource,
560
+ * and not necessarily that it will be deleted.
561
+ *
562
+ * @param path - The path to the resource.
563
+ * @param table - atlas creation data. **⚠️ `frame_start` is 1-based; passed to Defold unchanged.** **⚠️ `frame_end` is 1-based; passed to Defold unchanged.** **⚠️ `frame_start` is 1-based; passed to Defold unchanged.** **⚠️ `frame_end` is 1-based; passed to Defold unchanged.** **⚠️ `frames` is 1-based; passed to Defold unchanged.** **0️⃣ `indices` is 0-based; passed to Defold unchanged.**
564
+ * @returns Returns the atlas resource path
565
+ * @example
566
+ * ```ts
567
+ * // Create a backing texture and an atlas
568
+ * export default defineScript({
569
+ * init() {
570
+ * // the engine registers a texture format only when the driver supports it
571
+ * const format = graphics.TEXTURE_FORMAT_RGBA;
572
+ * if (format === undefined) return;
573
+ * // create an empty texture
574
+ * const tparams = {
575
+ * width: 128,
576
+ * height: 128,
577
+ * type: graphics.TEXTURE_TYPE_2D,
578
+ * format,
579
+ * };
580
+ * const my_texture_id = resource.create_texture("/my_texture.texturec", tparams);
581
+ *
582
+ * // optionally use resource.set_texture to upload data to texture
583
+ *
584
+ * // create an atlas with one animation and one square geometry
585
+ * // note that the function doesn't support hashes for the texture,
586
+ * // you need to use a string for the texture path here aswell
587
+ * const aparams = {
588
+ * texture: "/my_texture.texturec",
589
+ * animations: [
590
+ * {
591
+ * id: "my_animation",
592
+ * width: 128,
593
+ * height: 128,
594
+ * frames: [1],
595
+ * },
596
+ * ],
597
+ * geometries: [
598
+ * {
599
+ * id: "idle0",
600
+ * width: 128,
601
+ * height: 128,
602
+ * pivot_x: 0.5,
603
+ * pivot_y: 0.5,
604
+ * vertices: [0, 0, 0, 128, 128, 128, 128, 0],
605
+ * uvs: [0, 0, 0, 128, 128, 128, 128, 0],
606
+ * indices: [0, 1, 2, 0, 2, 3],
607
+ * },
608
+ * ],
609
+ * } satisfies Parameters<typeof resource.create_atlas>[1];
610
+ * const my_atlas_id = resource.create_atlas("/my_atlas.texturesetc", aparams);
611
+ *
612
+ * // assign the atlas to the 'sprite' component on the same go
613
+ * go.set("#sprite", "image", my_atlas_id);
614
+ * },
615
+ * });
616
+ * ```
617
+ */
618
+ function create_atlas(path: string, table: resource.atlas): Hash;
619
+ /**
620
+ * This function creates a new buffer resource that can be used in the same way as any buffer created during build time.
621
+ * The function requires a valid buffer created from either buffer.create or another pre-existing buffer resource.
622
+ * By default, the new resource will take ownership of the buffer lua reference, meaning the buffer will not automatically be removed
623
+ * when the lua reference to the buffer is garbage collected. This behaviour can be overruled by specifying 'transfer_ownership = false'
624
+ * in the argument table. If the new buffer resource is created from a buffer object that is created by another resource,
625
+ * the buffer object will be copied and the new resource will effectively own a copy of the buffer instead.
626
+ * Note that the path to the new resource must have the '.bufferc' extension, "/path/my_buffer" is not a valid path but "/path/my_buffer.bufferc" is.
627
+ * The path must also be unique, attempting to create a buffer with the same name as an existing resource will raise an error.
628
+ *
629
+ * @param path - The path to the resource.
630
+ * @param table - buffer-resource creation parameters
631
+ * @returns Returns the buffer resource path
632
+ * @example
633
+ * Create a buffer object and bind it to a buffer resource
634
+ * ```ts
635
+ * // Create a buffer object and bind it to a buffer resource
636
+ * export default defineScript({
637
+ * init() {
638
+ * const size = 1;
639
+ * const positions = [
640
+ * // triangle 1
641
+ * size, size, 0,
642
+ * -size, -size, 0,
643
+ * size, -size, 0,
644
+ * // triangle 2
645
+ * size, size, 0,
646
+ * -size, size, 0,
647
+ * -size, -size, 0,
648
+ * ];
649
+ *
650
+ * const buffer_handle = buffer.create(positions.length, [
651
+ * {
652
+ * name: hash("position"),
653
+ * type: buffer.VALUE_TYPE_FLOAT32,
654
+ * count: 3,
655
+ * },
656
+ * ]);
657
+ *
658
+ * const stream = buffer.get_stream(buffer_handle, hash("position"));
659
+ *
660
+ * // transfer vertex data to buffer
661
+ * positions.forEach((value, k) => {
662
+ * stream[k] = value;
663
+ * });
664
+ *
665
+ * const my_buffer = resource.create_buffer("/my_buffer.bufferc", { buffer: buffer_handle });
666
+ * go.set("/go#mesh", "vertices", my_buffer);
667
+ * },
668
+ * });
669
+ * ```
670
+ * @example
671
+ * Create a buffer resource from existing resource
672
+ * ```ts
673
+ * // Create a buffer resource from existing resource
674
+ * export default defineScript({
675
+ * init() {
676
+ * const res = resource.get_buffer("/my_buffer_path.bufferc");
677
+ * // create a cloned buffer resource from another resource buffer
678
+ * const buf = resource.create_buffer("/my_cloned_buffer.bufferc", { buffer: res });
679
+ * // assign cloned buffer to a mesh component
680
+ * go.set("/go#mesh", "vertices", buf);
681
+ * },
682
+ * });
683
+ * ```
684
+ */
685
+ function create_buffer(path: string, table: resource.buffer_creation_params): Hash;
686
+ /**
687
+ * Creates a sound data resource
688
+ * Supported formats are .oggc, .opusc and .wavc
689
+ *
690
+ * @param path - the path to the resource. Must not already exist.
691
+ * @param options - optional sound-data parameters
692
+ * @returns the resulting path hash to the resource
693
+ * @example
694
+ * ```ts
695
+ * export default defineScript({
696
+ * init() {
697
+ * // create a new sound resource, given the initial chunk of the file
698
+ * const [data] = sys.load_resource("/sounds/music_header.oggc");
699
+ * if (data === undefined) {
700
+ * return;
701
+ * }
702
+ * const filesize = 1048576;
703
+ * const relative_path = "/a/unique/resource/name.oggc";
704
+ * const hash = resource.create_sound_data(relative_path, { data, filesize, partial: true });
705
+ * go.set("#music", "sound", hash); // override the previous sound resource
706
+ * sound.play("#music"); // start the playing
707
+ * },
708
+ * });
709
+ * ```
710
+ */
711
+ function create_sound_data(path: string, options: resource.sound_data_options): Hash;
712
+ /**
713
+ * Creates a new texture resource that can be used in the same way as any texture created during build time.
714
+ * The path used for creating the texture must be unique, trying to create a resource at a path that is already
715
+ * registered will trigger an error. If the intention is to instead modify an existing texture, use the resource.set_texture
716
+ * function. Also note that the path to the new texture resource must have a '.texturec' extension,
717
+ * meaning "/path/my_texture" is not a valid path but "/path/my_texture.texturec" is.
718
+ * If the texture is created without a buffer, the pixel data will be blank.
719
+ *
720
+ * @param path - The path to the resource.
721
+ * @param table - texture creation parameters
722
+ * @param buffer - optional buffer of precreated pixel data
723
+ * @returns The path to the resource.
724
+ * @example
725
+ * Check whether a texture format is supported by the device:
726
+ * ```ts
727
+ * if (graphics.TEXTURE_FORMAT_RGBA16F !== undefined) {
728
+ * // It is safe to use this format.
729
+ * }
730
+ * ```
731
+ * @example
732
+ * 3D textures are currently only supported on OpenGL and Vulkan adapters. Check whether the device supports 3D textures before using them:
733
+ * ```ts
734
+ * if (graphics.TEXTURE_TYPE_3D !== undefined) {
735
+ * // The device and graphics adapter support 3D textures.
736
+ * }
737
+ * ```
738
+ * @example
739
+ * How to create an 128x128 RGBA texture resource and assign it to a model
740
+ * ```ts
741
+ * // How to create an 128x128 RGBA texture resource and assign it to a model
742
+ * export default defineScript({
743
+ * init() {
744
+ * // the engine registers a texture format only when the driver supports it
745
+ * const format = graphics.TEXTURE_FORMAT_RGBA;
746
+ * if (format === undefined) return;
747
+ * const tparams = {
748
+ * width: 128,
749
+ * height: 128,
750
+ * type: graphics.TEXTURE_TYPE_2D,
751
+ * format,
752
+ * };
753
+ * const my_texture_id = resource.create_texture("/my_custom_texture.texturec", tparams);
754
+ * go.set("#model", "texture0", my_texture_id);
755
+ * },
756
+ * });
757
+ * ```
758
+ * @example
759
+ * How to create an 128x128 floating point texture (RGBA32F) resource from a buffer object
760
+ * ```ts
761
+ * // How to create an 128x128 floating point texture (RGBA32F) resource from a buffer object
762
+ * export default defineScript({
763
+ * init() {
764
+ * // the engine registers a texture format only when the driver supports it
765
+ * const format = graphics.TEXTURE_FORMAT_RGBA32F;
766
+ * if (format === undefined) return;
767
+ * // Create a new buffer with 4 components and FLOAT32 type
768
+ * const tbuffer = buffer.create(128 * 128, [{ name: hash("rgba"), type: buffer.VALUE_TYPE_FLOAT32, count: 4 }]);
769
+ * const tstream = buffer.get_stream(tbuffer, hash("rgba"));
770
+ *
771
+ * // Fill the buffer stream with some float values
772
+ * for (let y = 0; y < 128; y++) {
773
+ * for (let x = 0; x < 128; x++) {
774
+ * const index = y * 128 * 4 + x * 4;
775
+ * tstream[index + 0] = 999.0;
776
+ * tstream[index + 1] = -1.0;
777
+ * tstream[index + 2] = 0.5;
778
+ * tstream[index + 3] = 1.0;
779
+ * }
780
+ * }
781
+ *
782
+ * // Create a 2D Texture with a RGBA23F format
783
+ * const tparams = {
784
+ * width: 128,
785
+ * height: 128,
786
+ * type: graphics.TEXTURE_TYPE_2D,
787
+ * format,
788
+ * };
789
+ *
790
+ * // Note that we pass the buffer as the last argument here!
791
+ * const my_texture_id = resource.create_texture("/my_custom_texture.texturec", tparams, tbuffer);
792
+ *
793
+ * // assign the texture to a model
794
+ * go.set("#model", "texture0", my_texture_id);
795
+ * },
796
+ * });
797
+ * ```
798
+ * @example
799
+ * How to create a 32x32x32 floating point 3D texture that can be used to generate volumetric data in a compute shader
800
+ * ```ts
801
+ * // How to create a 32x32x32 floating point 3D texture that can be used to generate volumetric data in a compute shader
802
+ * export default defineScript({
803
+ * init() {
804
+ * // the engine registers a texture type or format only when the driver supports it
805
+ * const type = graphics.TEXTURE_TYPE_IMAGE_3D;
806
+ * const format = graphics.TEXTURE_FORMAT_RGBA32F;
807
+ * if (type === undefined || format === undefined) return;
808
+ * const t_volume = resource.create_texture("/my_backing_texture.texturec", {
809
+ * type,
810
+ * width: 32,
811
+ * height: 32,
812
+ * depth: 32,
813
+ * format,
814
+ * flags: graphics.TEXTURE_USAGE_FLAG_STORAGE + graphics.TEXTURE_USAGE_FLAG_SAMPLE,
815
+ * });
816
+ *
817
+ * // pass the backing texture to the render script
818
+ * msg.post("@render:", "add_textures", [t_volume]);
819
+ * },
820
+ * });
821
+ * ```
822
+ * @example
823
+ * How to create 512x512 texture array with 5 pages.
824
+ * ```ts
825
+ * // How to create 512x512 texture array with 5 pages.
826
+ * // the engine registers a texture format only when the driver supports it
827
+ * const format = graphics.TEXTURE_FORMAT_RGB;
828
+ * if (format !== undefined) {
829
+ * const new_tex = resource.create_texture("/runtime/example_array.texturec", {
830
+ * type: graphics.TEXTURE_TYPE_2D_ARRAY,
831
+ * width: 512,
832
+ * height: 512,
833
+ * page_count: 5,
834
+ * format,
835
+ * });
836
+ * }
837
+ * ```
838
+ */
839
+ function create_texture(path: string, table: resource.texture_creation_params, buffer?: Opaque<"buffer">): Hash;
840
+ /**
841
+ * Creates a new texture resource that can be used in the same way as any texture created during build time.
842
+ * The path used for creating the texture must be unique, trying to create a resource at a path that is already
843
+ * registered will trigger an error. If the intention is to instead modify an existing texture, use the resource.set_texture
844
+ * function. Also note that the path to the new texture resource must have a '.texturec' extension,
845
+ * meaning "/path/my_texture" is not a valid path but "/path/my_texture.texturec" is.
846
+ * If the texture is created without a buffer, the pixel data will be blank.
847
+ * The difference between the async version and resource.create_texture is that the texture data will be uploaded
848
+ * in a graphics worker thread. The function will return a resource immediately that contains a 1x1 blank texture which can be used
849
+ * immediately after the function call. When the new texture has been uploaded, the initial blank texture will be deleted and replaced with the
850
+ * new texture. Be careful when using the initial texture handle handle as it will not be valid after the upload has finished.
851
+ *
852
+ * @param path - The path to the resource.
853
+ * @param table - texture creation parameters
854
+ * @param buffer - optional buffer of precreated pixel data
855
+ * @param callback - callback function invoked when the texture is created
856
+ * @example
857
+ * Check whether a texture format is supported by the device:
858
+ * ```ts
859
+ * if (graphics.TEXTURE_FORMAT_RGBA16F !== undefined) {
860
+ * // It is safe to use this format.
861
+ * }
862
+ * ```
863
+ * @example
864
+ * 3D textures are currently only supported on OpenGL and Vulkan adapters. Check whether the device supports 3D textures before using them:
865
+ * ```ts
866
+ * if (graphics.TEXTURE_TYPE_3D !== undefined) {
867
+ * // The device and graphics adapter support 3D textures.
868
+ * }
869
+ * ```
870
+ * @example
871
+ * Create a texture resource asyncronously with a buffer and a callback
872
+ * ```ts
873
+ * // Create a texture resource asyncronously with a buffer and a callback
874
+ * function callback(self: unknown, request_id: number, result: resource.texture_creation_result) {
875
+ * // The resource has been updated with a new texture,
876
+ * // so we can update other systems with the new handle,
877
+ * // or update components to use the resource if we want
878
+ * const tinfo = resource.get_texture_info(result.path);
879
+ * msg.post("@render:", "set_backing_texture", { handle: tinfo.handle });
880
+ * }
881
+ *
882
+ * export default defineScript({
883
+ * init() {
884
+ * // the engine registers a texture format only when the driver supports it
885
+ * const format = graphics.TEXTURE_FORMAT_RGBA;
886
+ * if (format === undefined) return;
887
+ * // Create a texture resource async
888
+ * const tparams = {
889
+ * width: 128,
890
+ * height: 128,
891
+ * type: graphics.TEXTURE_TYPE_2D,
892
+ * format,
893
+ * };
894
+ *
895
+ * // Create a new buffer with 4 components
896
+ * const tbuffer = buffer.create(tparams.width * tparams.height, [{ name: hash("rgba"), type: buffer.VALUE_TYPE_UINT8, count: 4 }]);
897
+ * const tstream = buffer.get_stream(tbuffer, hash("rgba"));
898
+ *
899
+ * // Fill the buffer stream with some float values
900
+ * for (let y = 0; y < tparams.width; y++) {
901
+ * for (let x = 0; x < tparams.height; x++) {
902
+ * const index = y * 128 * 4 + x * 4;
903
+ * tstream[index + 0] = 255;
904
+ * tstream[index + 1] = 0;
905
+ * tstream[index + 2] = 255;
906
+ * tstream[index + 3] = 255;
907
+ * }
908
+ * }
909
+ * // create the texture
910
+ * const [tpath, request_id] = resource.create_texture_async("/my_texture.texturec", tparams, tbuffer, callback);
911
+ * // at this point you can use the resource as-is, but note that the texture will be a blank 1x1 texture
912
+ * // that will be removed once the new texture has been updated
913
+ * go.set("#model", "texture0", tpath);
914
+ * },
915
+ * });
916
+ * ```
917
+ * @example
918
+ * Create a texture resource asynchronously with a callback that does nothing
919
+ * ```ts
920
+ * // Create a texture resource asyncronously without handling its completion
921
+ * export default defineScript({
922
+ * init() {
923
+ * // the engine registers a texture format only when the driver supports it
924
+ * const format = graphics.TEXTURE_FORMAT_RGBA;
925
+ * if (format === undefined) return;
926
+ * // Create a texture resource async
927
+ * const tparams = {
928
+ * width: 128,
929
+ * height: 128,
930
+ * type: graphics.TEXTURE_TYPE_2D,
931
+ * format,
932
+ * };
933
+ *
934
+ * // Create a new buffer with 4 components
935
+ * const tbuffer = buffer.create(tparams.width * tparams.height, [{ name: hash("rgba"), type: buffer.VALUE_TYPE_UINT8, count: 4 }]);
936
+ * const tstream = buffer.get_stream(tbuffer, hash("rgba"));
937
+ *
938
+ * // Fill the buffer stream with some float values
939
+ * for (let y = 0; y < tparams.width; y++) {
940
+ * for (let x = 0; x < tparams.height; x++) {
941
+ * const index = y * 128 * 4 + x * 4;
942
+ * tstream[index + 0] = 255;
943
+ * tstream[index + 1] = 0;
944
+ * tstream[index + 2] = 255;
945
+ * tstream[index + 3] = 255;
946
+ * }
947
+ * }
948
+ * // create the texture
949
+ * // the binding requires a callback function, so pass one that does nothing
950
+ * const [tpath, request_id] = resource.create_texture_async("/my_texture.texturec", tparams, tbuffer, () => {});
951
+ * // at this point you can use the resource as-is, but note that the texture will be a blank 1x1 texture
952
+ * // that will be removed once the new texture has been updated
953
+ * go.set("#model", "texture0", tpath);
954
+ * },
955
+ * });
956
+ * ```
957
+ */
958
+ function create_texture_async(path: string, table: resource.texture_creation_params, buffer: Opaque<"buffer"> | undefined, callback: (self: unknown, request_id: number, result: resource.texture_creation_result) => void): LuaMultiReturn<[Hash, number]>;
959
+ /**
960
+ * Constructor-like function with two purposes:
961
+ *
962
+ * - Load the specified resource as part of loading the script
963
+ * - Create a resource reference that resolves to the hashed path of the run-time resource
964
+ *
965
+ * This function can only be called within go.property function calls.
966
+ *
967
+ * @param path - optional resource path string to the resource
968
+ * @returns a reference to the binary version of the resource
969
+ * @example
970
+ * Load a font and set it to a label:
971
+ * ```ts
972
+ * // Load a font and set it to a label:
973
+ * export default defineScript({
974
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
975
+ * // registration from this field, and only this field types the property onto `self`.
976
+ * properties: { my_font: resource.font("/font.font") },
977
+ *
978
+ * init(self) {
979
+ * go.set("#label", "font", self.my_font);
980
+ * },
981
+ * });
982
+ * ```
983
+ * @example
984
+ * Load a font and set it to a gui:
985
+ * ```ts
986
+ * // Load a font and set it to a gui:
987
+ * export default defineScript({
988
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
989
+ * // registration from this field, and only this field types the property onto `self`.
990
+ * properties: { my_font: resource.font("/font.font") },
991
+ *
992
+ * init(self) {
993
+ * go.set("#gui", "fonts", self.my_font, { key: "my_font" });
994
+ * },
995
+ * });
996
+ * ```
997
+ */
998
+ function font(path?: string): Hash;
999
+ /**
1000
+ * Returns the atlas data for an atlas
1001
+ *
1002
+ * @param path - The path to the atlas resource
1003
+ * @returns atlas data. **⚠️ `frames` is 1-based; passed to Defold unchanged.** **0️⃣ `indices` is 0-based; passed to Defold unchanged.**
1004
+ */
1005
+ function get_atlas(path: Hash | string): resource.atlas_data;
1006
+ /**
1007
+ * gets the buffer from a resource
1008
+ *
1009
+ * @param path - The path to the resource
1010
+ * @returns The resource buffer
1011
+ * @example
1012
+ * ```ts
1013
+ * // How to get the data from a buffer
1014
+ * export default defineScript({
1015
+ * init() {
1016
+ * const res_path = go.get<mesh.properties>()("#mesh", "vertices");
1017
+ * const buf = resource.get_buffer(res_path);
1018
+ * const stream_positions = buffer.get_stream(buf, "position");
1019
+ *
1020
+ * for (let i = 0; i < stream_positions.length(); i++) {
1021
+ * print(i, stream_positions[i]);
1022
+ * }
1023
+ * },
1024
+ * });
1025
+ * ```
1026
+ */
1027
+ function get_buffer(path: Hash | string): Opaque<"buffer">;
1028
+ /**
1029
+ * Gets render target info from a render target resource path or a render target handle
1030
+ *
1031
+ * @param path - The path to the resource or a render target handle
1032
+ * @returns render-target information
1033
+ * @example
1034
+ * Get the metadata from a render target resource
1035
+ * ```ts
1036
+ * // Get the metadata from a render target resource
1037
+ * export default defineScript({
1038
+ * init() {
1039
+ * const info = resource.get_render_target_info("/my_render_target.render_targetc");
1040
+ * // the info table contains meta data about all the render target attachments
1041
+ * // so it's not necessary to use resource.get_texture here, but we do it here
1042
+ * // just to show that it's possible:
1043
+ * const info_attachment_1 = resource.get_texture_info(info.attachments[0]!.handle);
1044
+ * },
1045
+ * });
1046
+ * ```
1047
+ * @example
1048
+ * Get a texture attachment from a render target and set it on a model component
1049
+ * ```ts
1050
+ * // Get a texture attachment from a render target and set it on a model component
1051
+ * export default defineScript({
1052
+ * init() {
1053
+ * const info = resource.get_render_target_info("/my_render_target.render_targetc");
1054
+ * const attachment = info.attachments[0]!.texture!;
1055
+ * // you can also get texture info from the 'texture' field, since it's a resource hash
1056
+ * const texture_info = resource.get_texture_info(attachment);
1057
+ * go.set("#model", "texture0", attachment);
1058
+ * },
1059
+ * });
1060
+ * ```
1061
+ */
1062
+ function get_render_target_info(path: Hash | string | Opaque<"render_target"> | number): resource.render_target_info;
1063
+ /**
1064
+ * Gets the text metrics from a font. Rich text markup is measured using its
1065
+ * visible text and font sizes. If markup cannot be parsed, the text is measured literally.
1066
+ * Inline sprites reserve their specified dimensions, or one em by default.
1067
+ *
1068
+ * @param url - the font to get the (unscaled) metrics from
1069
+ * @param text - text to measure
1070
+ * @param options - optional text-metric options
1071
+ * @returns measured text metrics
1072
+ * @example
1073
+ * ```ts
1074
+ * export default defineScript({
1075
+ * init() {
1076
+ * const font = go.get<label.properties>()("#label", "font");
1077
+ * const metrics = resource.get_text_metrics(font, "The quick brown fox\n jumps over the lazy dog");
1078
+ * pprint(metrics);
1079
+ * },
1080
+ * });
1081
+ * ```
1082
+ */
1083
+ function get_text_metrics(url: Hash | string, text: string, options?: resource.text_metrics_options): resource.text_metrics;
1084
+ /**
1085
+ * Gets texture info from a texture resource path or a texture handle
1086
+ *
1087
+ * @param path - The path to the resource or a texture handle
1088
+ * @returns texture information
1089
+ * @example
1090
+ * Create a new texture and get the metadata from it
1091
+ * ```ts
1092
+ * // Create a new texture and get the metadata from it
1093
+ * export default defineScript({
1094
+ * init() {
1095
+ * // the engine registers a texture format only when the driver supports it
1096
+ * const format = graphics.TEXTURE_FORMAT_RGBA;
1097
+ * if (format === undefined) return;
1098
+ * // create an empty texture
1099
+ * const tparams = {
1100
+ * width: 128,
1101
+ * height: 128,
1102
+ * type: graphics.TEXTURE_TYPE_2D,
1103
+ * format,
1104
+ * };
1105
+ *
1106
+ * const my_texture_path = resource.create_texture("/my_texture.texturec", tparams);
1107
+ * const my_texture_info = resource.get_texture_info(my_texture_path);
1108
+ *
1109
+ * // my_texture_info now contains
1110
+ * // {
1111
+ * // handle = <the-numeric-handle>,
1112
+ * // width = 128,
1113
+ * // height = 128,
1114
+ * // depth = 1
1115
+ * // mipmaps = 1,
1116
+ * // page_count = 1,
1117
+ * // type = graphics.TEXTURE_TYPE_2D,
1118
+ * // flags = graphics.TEXTURE_USAGE_FLAG_SAMPLE
1119
+ * // }
1120
+ * },
1121
+ * });
1122
+ * ```
1123
+ * @example
1124
+ * Get the meta data from an atlas resource
1125
+ * ```ts
1126
+ * // Get the meta data from an atlas resource
1127
+ * export default defineScript({
1128
+ * init() {
1129
+ * const my_atlas_info = resource.get_atlas("/my_atlas.a.texturesetc");
1130
+ * const my_texture_info = resource.get_texture_info(my_atlas_info.texture);
1131
+ *
1132
+ * // my_texture_info now contains the information about the texture that is backing the atlas
1133
+ * },
1134
+ * });
1135
+ * ```
1136
+ */
1137
+ function get_texture_info(path: Hash | string | Opaque<"texture"> | number): resource.texture_info;
1138
+ /**
1139
+ * Loads the resource data for a specific resource.
1140
+ *
1141
+ * @param path - The path to the resource
1142
+ * @returns Returns the buffer stored on disc
1143
+ * @example
1144
+ * ```ts
1145
+ * // read custom resource data into buffer
1146
+ * const buffer = resource.load("/resources/datafile");
1147
+ * ```
1148
+ * @example
1149
+ * In order for the engine to include custom resources in the build process, you need
1150
+ * to specify them in the "game.project" settings file:
1151
+ * ```ts
1152
+ * // [project]
1153
+ * // title = My project
1154
+ * // version = 0.1
1155
+ * // custom_resources = resources/,assets/level_data.json
1156
+ * ```
1157
+ */
1158
+ function load(path: string): Opaque<"buffer">;
1159
+ /**
1160
+ * Constructor-like function with two purposes:
1161
+ *
1162
+ * - Load the specified resource as part of loading the script
1163
+ * - Create a resource reference that resolves to the hashed path of the run-time resource
1164
+ *
1165
+ * This function can only be called within go.property function calls.
1166
+ *
1167
+ * @param path - optional resource path string to the resource
1168
+ * @returns a reference to the binary version of the resource
1169
+ * @example
1170
+ * Load a material and set it to a sprite:
1171
+ * ```ts
1172
+ * // Load a material and set it to a sprite:
1173
+ * export default defineScript({
1174
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
1175
+ * // registration from this field, and only this field types the property onto `self`.
1176
+ * properties: { my_material: resource.material("/material.material") },
1177
+ *
1178
+ * init(self) {
1179
+ * go.set("#sprite", "material", self.my_material);
1180
+ * },
1181
+ * });
1182
+ * ```
1183
+ * @example
1184
+ * Load a material resource and update a named material with the resource:
1185
+ * ```ts
1186
+ * // Load a material resource and update a named material with the resource:
1187
+ * export default defineScript({
1188
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
1189
+ * // registration from this field, and only this field types the property onto `self`.
1190
+ * properties: { my_material: resource.material("/material.material") },
1191
+ *
1192
+ * init(self) {
1193
+ * go.set("#gui", "materials", self.my_material, { key: "my_material" });
1194
+ * },
1195
+ * });
1196
+ * ```
1197
+ */
1198
+ function material(path?: string): Hash;
1199
+ /**
1200
+ * Release a resource.
1201
+ * This is a potentially dangerous operation, releasing resources currently being used can cause unexpected behaviour.
1202
+ *
1203
+ * @param path - The path to the resource.
1204
+ */
1205
+ function release(path: Hash | string): void;
1206
+ /**
1207
+ * Constructor-like function with two purposes:
1208
+ *
1209
+ * - Load the specified resource as part of loading the script
1210
+ * - Create a resource reference that resolves to the hashed path of the run-time resource
1211
+ *
1212
+ * This function can only be called within go.property function calls.
1213
+ *
1214
+ * @param path - optional resource path string to the resource
1215
+ * @returns a reference to the binary version of the resource
1216
+ * @example
1217
+ * ```ts
1218
+ * // Set a render target color attachment as a model texture:
1219
+ * export default defineScript({
1220
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
1221
+ * // registration from this field, and only this field types the property onto `self`.
1222
+ * properties: { my_render_target: resource.render_target("/rt.render_target") },
1223
+ *
1224
+ * init(self) {
1225
+ * const rt_info = resource.get_render_target_info(self.my_render_target);
1226
+ * go.set("#model", "texture0", rt_info.attachments[0]!.texture!);
1227
+ * },
1228
+ * });
1229
+ * ```
1230
+ */
1231
+ function render_target(path?: string): Hash;
1232
+ /**
1233
+ * Sets the resource data for a specific resource
1234
+ *
1235
+ * @param path - The path to the resource
1236
+ * @param buffer - The buffer of precreated data, suitable for the intended resource type
1237
+ * @example
1238
+ * ```ts
1239
+ * // Assuming the folder "/res" is added to the project custom resources:
1240
+ * // load a texture resource and set it on a sprite
1241
+ * const buffer = resource.load("/res/new.texturec");
1242
+ * resource.set(go.get<sprite.properties>()("#sprite", "texture0"), buffer);
1243
+ * ```
1244
+ */
1245
+ function set(path: string | Hash, buffer: Opaque<"buffer">): void;
1246
+ /**
1247
+ * Sets the data for a specific atlas resource. Setting new atlas data is specified by passing in
1248
+ * a texture path for the backing texture of the atlas, a list of geometries and a list of animations
1249
+ * that map to the entries in the geometry list. The geometry entries are represented by three lists:
1250
+ * vertices, uvs and indices that together represent triangles that are used in other parts of the
1251
+ * engine to produce render objects from.
1252
+ * Vertex and uv coordinates for the geometries are expected to be
1253
+ * in pixel coordinates where 0,0 is the top left corner of the texture.
1254
+ * There is no automatic padding or margin support when setting custom data,
1255
+ * which could potentially cause filtering artifacts if used with a material sampler that has linear filtering.
1256
+ * If that is an issue, you need to calculate padding and margins manually before passing in the geometry data to
1257
+ * this function.
1258
+ *
1259
+ * @param path - The path to the atlas resource
1260
+ * @param table - atlas data. **⚠️ `frame_start` is 1-based; passed to Defold unchanged.** **⚠️ `frame_end` is 1-based; passed to Defold unchanged.** **⚠️ `frame_start` is 1-based; passed to Defold unchanged.** **⚠️ `frame_end` is 1-based; passed to Defold unchanged.** **⚠️ `frames` is 1-based; passed to Defold unchanged.** **0️⃣ `indices` is 0-based; passed to Defold unchanged.**
1261
+ * @example
1262
+ * Add a new animation to an existing atlas
1263
+ * ```ts
1264
+ * // Add a new animation to an existing atlas
1265
+ * export default defineScript({
1266
+ * init() {
1267
+ * const data = resource.get_atlas("/main/my_atlas.a.texturesetc");
1268
+ * const my_animation = {
1269
+ * id: "my_new_animation",
1270
+ * width: 128,
1271
+ * height: 128,
1272
+ * frame_start: 1,
1273
+ * frame_end: 6,
1274
+ * playback: go.PLAYBACK_LOOP_PINGPONG,
1275
+ * fps: 8,
1276
+ * flip_vertical: false,
1277
+ * flip_horizontal: false,
1278
+ * };
1279
+ * // set_atlas takes each animation's frames as a non-empty list
1280
+ * const animations = data.animations.flatMap((animation) => {
1281
+ * // an animation described by frame_start/frame_end passes through as-is
1282
+ * if (!("frames" in animation)) return [animation];
1283
+ * const [first, ...rest] = (animation.frames as number[] | undefined) ?? [];
1284
+ * return first === undefined ? [] : [{ ...animation, frames: [first, ...rest] as [number, ...number[]] }];
1285
+ * });
1286
+ * // set_atlas needs at least one animation and one geometry
1287
+ * const [first_geometry, ...geometries] = data.geometries;
1288
+ * if (first_geometry !== undefined) {
1289
+ * resource.set_atlas("/main/my_atlas.a.texturesetc", {
1290
+ * ...data,
1291
+ * animations: [my_animation, ...animations],
1292
+ * geometries: [first_geometry, ...geometries],
1293
+ * });
1294
+ * }
1295
+ * },
1296
+ * });
1297
+ * ```
1298
+ * @example
1299
+ * Sets atlas data for a 256x256 texture with a single animation being rendered as a quad
1300
+ * ```ts
1301
+ * // Sets atlas data for a 256x256 texture with a single animation being rendered as a quad
1302
+ * export default defineScript({
1303
+ * init() {
1304
+ * const params = {
1305
+ * texture: "/main/my_256x256_texture.texturec",
1306
+ * animations: [
1307
+ * {
1308
+ * id: "my_animation",
1309
+ * width: 256,
1310
+ * height: 256,
1311
+ * frames: [1],
1312
+ * },
1313
+ * ],
1314
+ * geometries: [
1315
+ * {
1316
+ * vertices: [0, 0, 0, 256, 256, 256, 256, 0],
1317
+ * uvs: [0, 0, 0, 256, 256, 256, 256, 0],
1318
+ * indices: [0, 1, 2, 0, 2, 3],
1319
+ * },
1320
+ * ],
1321
+ * } satisfies Parameters<typeof resource.set_atlas>[1];
1322
+ * resource.set_atlas("/main/test.a.texturesetc", params);
1323
+ * },
1324
+ * });
1325
+ * ```
1326
+ */
1327
+ function set_atlas(path: Hash | string, table: resource.atlas): void;
1328
+ /**
1329
+ * Sets the buffer of a resource. By default, setting the resource buffer will either copy the data from the incoming buffer object
1330
+ * to the buffer stored in the destination resource, or make a new buffer object if the sizes between the source buffer and the destination buffer
1331
+ * stored in the resource differs. In some cases, e.g performance reasons, it might be beneficial to just set the buffer object on the resource without copying or cloning.
1332
+ * To achieve this, set the `transfer_ownership` flag to true in the argument table. Transferring ownership from a lua buffer to a resource with this function
1333
+ * works exactly the same as resource.create_buffer: the destination resource will take ownership of the buffer held by the lua reference, i.e the buffer will not automatically be removed
1334
+ * when the lua reference to the buffer is garbage collected.
1335
+ * Note: When setting a buffer with `transfer_ownership = true`, the currently bound buffer in the resource will be destroyed.
1336
+ *
1337
+ * @param path - The path to the resource
1338
+ * @param buffer - The resource buffer
1339
+ * @param table - optional buffer-resource update options
1340
+ * @example
1341
+ * ```ts
1342
+ * // How to set the data from a buffer
1343
+ * function fill_stream(stream: { [index: number]: number }, verts: number[]) {
1344
+ * verts.forEach((value, key) => {
1345
+ * stream[key] = value;
1346
+ * });
1347
+ * }
1348
+ *
1349
+ * export default defineScript({
1350
+ * init() {
1351
+ * const res_path = go.get<mesh.properties>()("#mesh", "vertices");
1352
+ *
1353
+ * const positions = [
1354
+ * 1, -1, 0,
1355
+ * 1, 1, 0,
1356
+ * -1, -1, 0,
1357
+ * ];
1358
+ *
1359
+ * const num_verts = positions.length / 3;
1360
+ *
1361
+ * // create a new buffer
1362
+ * let buf = buffer.create(num_verts, [{ name: hash("position"), type: buffer.VALUE_TYPE_FLOAT32, count: 3 }]);
1363
+ *
1364
+ * buf = resource.get_buffer(res_path);
1365
+ * const stream_positions = buffer.get_stream(buf, "position");
1366
+ *
1367
+ * fill_stream(stream_positions, positions);
1368
+ *
1369
+ * resource.set_buffer(res_path, buf);
1370
+ * },
1371
+ * });
1372
+ * ```
1373
+ */
1374
+ function set_buffer(path: Hash | string, buffer: Opaque<"buffer">, table?: resource.buffer_update_options): void;
1375
+ /**
1376
+ * Update internal sound resource (wavc/oggc/opusc) with new data
1377
+ *
1378
+ * @param path - The path to the resource
1379
+ * @param buffer - A lua string containing the binary sound data
1380
+ */
1381
+ function set_sound(path: Hash | string, buffer: string): void;
1382
+ /**
1383
+ * Sets the pixel data for a specific texture.
1384
+ *
1385
+ * @param path - The path to the resource
1386
+ * @param table - texture update parameters. **0️⃣ `page` is 0-based; passed to Defold unchanged.** **0️⃣ `mipmap` is 0-based; passed to Defold unchanged.**
1387
+ * @param buffer - The buffer of precreated pixel data
1388
+ * To update a cube map texture you need to pass in six times the amount of data via the buffer, since a cube map has six sides!
1389
+ * 3D textures are currently only supported on OpenGL and Vulkan adapters.
1390
+ * @example
1391
+ * Check whether a texture format is supported by the device:
1392
+ * ```ts
1393
+ * if (graphics.TEXTURE_FORMAT_RGBA16F !== undefined) {
1394
+ * // It is safe to use this format.
1395
+ * }
1396
+ * ```
1397
+ * @example
1398
+ * Check whether the device supports 3D textures before using them:
1399
+ * ```ts
1400
+ * if (graphics.TEXTURE_TYPE_3D !== undefined) {
1401
+ * // The device and graphics adapter support 3D textures.
1402
+ * }
1403
+ * ```
1404
+ * @example
1405
+ * How to set all pixels of an atlas
1406
+ * ```ts
1407
+ * // How to set all pixels of an atlas
1408
+ * export default defineScript({
1409
+ * init() {
1410
+ * const height = 128;
1411
+ * const width = 128;
1412
+ * const buf = buffer.create(width * height, [{ name: hash("rgb"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);
1413
+ * const stream = buffer.get_stream(buf, hash("rgb"));
1414
+ *
1415
+ * for (let y = 0; y < height; y++) {
1416
+ * for (let x = 0; x < width; x++) {
1417
+ * const index = y * width * 3 + x * 3;
1418
+ * stream[index + 0] = 0xff;
1419
+ * stream[index + 1] = 0x80;
1420
+ * stream[index + 2] = 0x10;
1421
+ * }
1422
+ * }
1423
+ *
1424
+ * // the engine registers a texture format only when the driver supports it
1425
+ * const format = graphics.TEXTURE_FORMAT_RGB;
1426
+ * if (format !== undefined) {
1427
+ * const resource_path = go.get<model.properties>()("#model", "texture0");
1428
+ * const args = { width, height, type: graphics.TEXTURE_TYPE_2D, format, num_mip_maps: 1 };
1429
+ * resource.set_texture(resource_path, args, buf);
1430
+ * }
1431
+ * return { buffer: buf, stream };
1432
+ * },
1433
+ * });
1434
+ * ```
1435
+ * @example
1436
+ * How to update a specific region of an atlas by using the x,y values. Assumes the already set atlas is a 128x128 texture.
1437
+ * ```ts
1438
+ * // How to update a specific region of an atlas by using the x,y values. Assumes the already set atlas is a 128x128 texture.
1439
+ * export default defineScript({
1440
+ * init() {
1441
+ * const x = 16;
1442
+ * const y = 16;
1443
+ * const height = 128 - x * 2;
1444
+ * const width = 128 - y * 2;
1445
+ * const buf = buffer.create(width * height, [{ name: hash("rgb"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);
1446
+ * const stream = buffer.get_stream(buf, hash("rgb"));
1447
+ *
1448
+ * for (let row = 0; row < height; row++) {
1449
+ * for (let col = 0; col < width; col++) {
1450
+ * const index = row * width * 3 + col * 3;
1451
+ * stream[index + 0] = 0xff;
1452
+ * stream[index + 1] = 0x80;
1453
+ * stream[index + 2] = 0x10;
1454
+ * }
1455
+ * }
1456
+ *
1457
+ * // the engine registers a texture format only when the driver supports it
1458
+ * const format = graphics.TEXTURE_FORMAT_RGB;
1459
+ * if (format !== undefined) {
1460
+ * const resource_path = go.get<model.properties>()("#model", "texture0");
1461
+ * const args = { width, height, x, y, type: graphics.TEXTURE_TYPE_2D, format, num_mip_maps: 1 };
1462
+ * resource.set_texture(resource_path, args, buf);
1463
+ * }
1464
+ * return { buffer: buf, stream };
1465
+ * },
1466
+ * });
1467
+ * ```
1468
+ * @example
1469
+ * Update a texture from a buffer resource
1470
+ * ```ts
1471
+ * // Update a texture from a buffer resource
1472
+ * export default defineScript({
1473
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
1474
+ * // registration from this field, and only this field types the property onto `self`.
1475
+ * properties: { my_buffer: resource.buffer("/my_default_buffer.buffer") },
1476
+ *
1477
+ * init(self) {
1478
+ * // the engine registers a texture format only when the driver supports it
1479
+ * const format = graphics.TEXTURE_FORMAT_RGB;
1480
+ * if (format === undefined) return;
1481
+ * const resource_path = go.get<model.properties>()("#model", "texture0");
1482
+ * // the "my_buffer" resource is expected to hold 128 * 128 * 3 bytes!
1483
+ * const args = {
1484
+ * width: 128,
1485
+ * height: 128,
1486
+ * type: graphics.TEXTURE_TYPE_2D,
1487
+ * format,
1488
+ * };
1489
+ * // Note that the extra resource.get_buffer call is a requirement here
1490
+ * // since the "self.my_buffer" is just pointing to a buffer resource path
1491
+ * // and not an actual buffer object or buffer resource.
1492
+ * resource.set_texture(resource_path, args, resource.get_buffer(self.my_buffer));
1493
+ * },
1494
+ * });
1495
+ * ```
1496
+ * @example
1497
+ * Update an existing 3D texture from a lua buffer
1498
+ * ```ts
1499
+ * // Update an existing 3D texture from a lua buffer
1500
+ * export default defineScript({
1501
+ * init() {
1502
+ * // the engine registers a texture type or format only when the driver supports it
1503
+ * const type = graphics.TEXTURE_TYPE_IMAGE_3D;
1504
+ * const format = graphics.TEXTURE_FORMAT_RGBA32F;
1505
+ * if (type === undefined || format === undefined) return;
1506
+ * // create a buffer that can hold the data of a 8x8x8 texture
1507
+ * const tbuffer = buffer.create(8 * 8 * 8, [{ name: hash("rgba"), type: buffer.VALUE_TYPE_FLOAT32, count: 4 }]);
1508
+ * const tstream = buffer.get_stream(tbuffer, hash("rgba"));
1509
+ *
1510
+ * // populate the buffer with some data
1511
+ * let index = 0;
1512
+ * for (let z = 1; z <= 8; z++) {
1513
+ * for (let y = 1; y <= 8; y++) {
1514
+ * for (let x = 1; x <= 8; x++) {
1515
+ * tstream[index + 0] = x;
1516
+ * tstream[index + 1] = y;
1517
+ * tstream[index + 2] = z;
1518
+ * tstream[index + 3] = 1.0;
1519
+ * index = index + 4;
1520
+ * }
1521
+ * }
1522
+ * }
1523
+ *
1524
+ * const t_args = {
1525
+ * type,
1526
+ * width: 8,
1527
+ * height: 8,
1528
+ * depth: 8,
1529
+ * format,
1530
+ * };
1531
+ *
1532
+ * // This expects that the texture resource "/my_3d_texture.texturec" already exists
1533
+ * // and is a 3D texture resource. To create a dynamic 3D texture resource
1534
+ * // use the "resource.create_texture" function.
1535
+ * resource.set_texture("/my_3d_texture.texturec", t_args, tbuffer);
1536
+ * },
1537
+ * });
1538
+ * ```
1539
+ * @example
1540
+ * Update texture 2nd array page with loaded texture from png
1541
+ * ```ts
1542
+ * // Update texture 2nd array page with loaded texture from png
1543
+ * const tex_path = "/bundle_resources/page_02.png";
1544
+ * const [data] = sys.load_resource(tex_path);
1545
+ * // the engine registers a texture format only when the driver supports it
1546
+ * const format = graphics.TEXTURE_FORMAT_RGB;
1547
+ * if (data !== undefined && format !== undefined) {
1548
+ * const buf = image.load_buffer(data);
1549
+ * if (buf !== undefined) {
1550
+ * // new_tex is the resource handle of a texture created via resource.create_texture
1551
+ * const new_tex = resource.create_texture("/my_array_texture.texturec", {
1552
+ * type: graphics.TEXTURE_TYPE_2D_ARRAY,
1553
+ * width: buf.width,
1554
+ * height: buf.height,
1555
+ * page_count: 2,
1556
+ * format,
1557
+ * });
1558
+ * resource.set_texture(
1559
+ * new_tex,
1560
+ * {
1561
+ * type: graphics.TEXTURE_TYPE_2D_ARRAY,
1562
+ * width: buf.width,
1563
+ * height: buf.height,
1564
+ * page: 1,
1565
+ * format,
1566
+ * },
1567
+ * buf.buffer,
1568
+ * );
1569
+ * go.set("#mesh", "texture0", new_tex);
1570
+ * }
1571
+ * }
1572
+ * ```
1573
+ */
1574
+ function set_texture(path: Hash | string, table: resource.texture_update_params, buffer: Opaque<"buffer">): void;
1575
+ /**
1576
+ * Constructor-like function with two purposes:
1577
+ *
1578
+ * - Load the specified resource as part of loading the script
1579
+ * - Create a resource reference that resolves to the hashed path of the run-time resource
1580
+ *
1581
+ * This function can only be called within go.property function calls.
1582
+ *
1583
+ * @param path - optional resource path string to the resource
1584
+ * @returns a reference to the binary version of the resource
1585
+ * @example
1586
+ * ```ts
1587
+ * // Load a texture and set it to a model:
1588
+ * export default defineScript({
1589
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
1590
+ * // registration from this field, and only this field types the property onto `self`.
1591
+ * properties: { my_texture: resource.texture("/texture.png") },
1592
+ *
1593
+ * init(self) {
1594
+ * go.set("#model", "texture0", self.my_texture);
1595
+ * },
1596
+ * });
1597
+ * ```
1598
+ */
1599
+ function texture(path?: string): Hash;
1600
+ /**
1601
+ * Constructor-like function with two purposes:
1602
+ *
1603
+ * - Load the specified resource as part of loading the script
1604
+ * - Create a resource reference that resolves to the hashed path of the run-time resource
1605
+ *
1606
+ * This function can only be called within go.property function calls.
1607
+ *
1608
+ * @param path - optional resource path string to the resource
1609
+ * @returns a reference to the binary version of the resource
1610
+ * @example
1611
+ * ```ts
1612
+ * // Load tile source and set it to a tile map:
1613
+ * export default defineScript({
1614
+ * // Never call `go.property` yourself: the transpiler emits the chunk-scope
1615
+ * // registration from this field, and only this field types the property onto `self`.
1616
+ * properties: { my_tile_source: resource.tile_source("/tilesource.tilesource") },
1617
+ *
1618
+ * init(self) {
1619
+ * go.set("#tilemap", "tile_source", self.my_tile_source);
1620
+ * },
1621
+ * });
1622
+ * ```
1623
+ */
1624
+ function tile_source(path?: string): Hash;
1625
+ }
1626
+ }
1627
+
1628
+ export {};