@defold-typescript/types 0.51.0 → 0.52.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 (130) hide show
  1. package/api-availability.json +4 -58
  2. package/api-signatures.json +878 -1356
  3. package/api-targets.json +15 -5
  4. package/examples/translations.json +4 -56
  5. package/generated/b2d_world.d.ts +10 -10
  6. package/generated/buffer.d.ts +9 -9
  7. package/generated/bullet3d_collision_object.d.ts +1 -1
  8. package/generated/bullet3d_constraint.d.ts +109 -7
  9. package/generated/bullet3d_shape.d.ts +2 -2
  10. package/generated/go.d.ts +114 -220
  11. package/generated/graphics.d.ts +1 -0
  12. package/generated/gui.d.ts +148 -371
  13. package/generated/http.d.ts +2 -2
  14. package/generated/image.d.ts +55 -3
  15. package/generated/kinds/gui-script.d.ts +2 -0
  16. package/generated/kinds/render-script.d.ts +14 -15
  17. package/generated/liveupdate.d.ts +5 -1
  18. package/generated/material.d.ts +3 -3
  19. package/generated/particlefx.d.ts +20 -1
  20. package/generated/physics.d.ts +45 -1
  21. package/generated/render-script-modules/b2d.d.ts +711 -0
  22. package/generated/render-script-modules/bullet3d.d.ts +73 -0
  23. package/generated/render-script-modules/collectionfactory.d.ts +25 -0
  24. package/generated/render-script-modules/collectionproxy.d.ts +39 -0
  25. package/generated/render-script-modules/factory.d.ts +25 -0
  26. package/generated/render-script-modules/go.d.ts +436 -0
  27. package/generated/render-script-modules/label.d.ts +105 -0
  28. package/generated/render-script-modules/model.d.ts +89 -0
  29. package/generated/render-script-modules/particlefx.d.ts +59 -0
  30. package/generated/render-script-modules/physics.d.ts +333 -0
  31. package/generated/render-script-modules/resource.d.ts +1233 -0
  32. package/generated/render-script-modules/sound.d.ts +227 -0
  33. package/generated/render-script-modules/sprite.d.ts +68 -0
  34. package/generated/render-script-modules/tilemap.d.ts +43 -0
  35. package/generated/render.d.ts +134 -8
  36. package/generated/resource.d.ts +31 -10
  37. package/generated/sprite.d.ts +49 -1
  38. package/generated/sys.d.ts +70 -6
  39. package/generated/versions/defold-1.12.4/buffer.d.ts +8 -8
  40. package/generated/versions/defold-1.12.4/go.d.ts +115 -343
  41. package/generated/versions/defold-1.12.4/graphics.d.ts +1 -0
  42. package/generated/versions/defold-1.12.4/gui.d.ts +151 -513
  43. package/generated/versions/defold-1.12.4/http.d.ts +2 -2
  44. package/generated/versions/defold-1.12.4/image.d.ts +82 -2
  45. package/generated/versions/defold-1.12.4/index.d.ts +1 -0
  46. package/generated/versions/defold-1.12.4/liveupdate.d.ts +4 -0
  47. package/generated/versions/defold-1.12.4/particlefx.d.ts +22 -1
  48. package/generated/versions/defold-1.12.4/physics.d.ts +45 -1
  49. package/generated/versions/defold-1.12.4/render.d.ts +78 -2
  50. package/generated/versions/defold-1.12.4/resource.d.ts +43 -10
  51. package/generated/versions/defold-1.12.4/sprite.d.ts +58 -1
  52. package/generated/versions/defold-1.12.4/sys.d.ts +101 -6
  53. package/generated/versions/defold-1.12.4/vmath.d.ts +0 -24
  54. package/generated/versions/defold-1.13.0/buffer.d.ts +8 -8
  55. package/generated/versions/defold-1.13.0/go.d.ts +115 -370
  56. package/generated/versions/defold-1.13.0/graphics.d.ts +1 -0
  57. package/generated/versions/defold-1.13.0/gui.d.ts +151 -513
  58. package/generated/versions/defold-1.13.0/http.d.ts +2 -2
  59. package/generated/versions/defold-1.13.0/image.d.ts +82 -2
  60. package/generated/versions/defold-1.13.0/index.d.ts +1 -0
  61. package/generated/versions/defold-1.13.0/liveupdate.d.ts +4 -0
  62. package/generated/versions/defold-1.13.0/material.d.ts +3 -1
  63. package/generated/versions/defold-1.13.0/particlefx.d.ts +22 -1
  64. package/generated/versions/defold-1.13.0/physics.d.ts +45 -1
  65. package/generated/versions/defold-1.13.0/render.d.ts +142 -4
  66. package/generated/versions/defold-1.13.0/resource.d.ts +43 -10
  67. package/generated/versions/defold-1.13.0/sprite.d.ts +58 -1
  68. package/generated/versions/defold-1.13.0/sys.d.ts +101 -6
  69. package/generated/versions/defold-1.13.0/vmath.d.ts +0 -24
  70. package/generated/versions/defold-1.13.1/buffer.d.ts +8 -8
  71. package/generated/versions/defold-1.13.1/go.d.ts +115 -370
  72. package/generated/versions/defold-1.13.1/graphics.d.ts +1 -0
  73. package/generated/versions/defold-1.13.1/gui.d.ts +151 -529
  74. package/generated/versions/defold-1.13.1/http.d.ts +2 -2
  75. package/generated/versions/defold-1.13.1/image.d.ts +82 -2
  76. package/generated/versions/defold-1.13.1/index.d.ts +2 -0
  77. package/generated/versions/defold-1.13.1/liveupdate.d.ts +4 -0
  78. package/generated/versions/defold-1.13.1/material.d.ts +3 -1
  79. package/generated/versions/defold-1.13.1/particlefx.d.ts +22 -1
  80. package/generated/versions/defold-1.13.1/physics.d.ts +45 -1
  81. package/generated/versions/defold-1.13.1/render.d.ts +142 -4
  82. package/generated/versions/defold-1.13.1/resource.d.ts +43 -10
  83. package/generated/versions/defold-1.13.1/sprite.d.ts +58 -1
  84. package/generated/versions/defold-1.13.1/sys.d.ts +101 -6
  85. package/generated/versions/defold-1.13.1/vmath.d.ts +0 -24
  86. package/generated/versions/defold-1.13.2/b2d_world.d.ts +10 -10
  87. package/generated/versions/defold-1.13.2/buffer.d.ts +9 -9
  88. package/generated/versions/defold-1.13.2/bullet3d_collision_object.d.ts +1 -1
  89. package/generated/versions/defold-1.13.2/bullet3d_constraint.d.ts +109 -7
  90. package/generated/versions/defold-1.13.2/bullet3d_shape.d.ts +2 -2
  91. package/generated/versions/defold-1.13.2/go.d.ts +114 -220
  92. package/generated/versions/defold-1.13.2/graphics.d.ts +1 -0
  93. package/generated/versions/defold-1.13.2/gui.d.ts +148 -371
  94. package/generated/versions/defold-1.13.2/http.d.ts +2 -2
  95. package/generated/versions/defold-1.13.2/image.d.ts +55 -3
  96. package/generated/versions/defold-1.13.2/index.d.ts +2 -0
  97. package/generated/versions/defold-1.13.2/liveupdate.d.ts +5 -1
  98. package/generated/versions/defold-1.13.2/material.d.ts +3 -3
  99. package/generated/versions/defold-1.13.2/particlefx.d.ts +20 -1
  100. package/generated/versions/defold-1.13.2/physics.d.ts +45 -1
  101. package/generated/versions/defold-1.13.2/render.d.ts +123 -7
  102. package/generated/versions/defold-1.13.2/resource.d.ts +31 -10
  103. package/generated/versions/defold-1.13.2/sprite.d.ts +49 -1
  104. package/generated/versions/defold-1.13.2/sys.d.ts +70 -6
  105. package/generated/versions/defold-1.13.2/vmath.d.ts +0 -24
  106. package/generated/vmath.d.ts +0 -24
  107. package/identity-vocabulary.json +52 -7
  108. package/index.d.ts +2 -0
  109. package/package.json +2 -1
  110. package/scripts/generate-api-availability.ts +1 -21
  111. package/scripts/generate-api-signatures.ts +75 -14
  112. package/scripts/materialize-version.ts +48 -7
  113. package/scripts/regen.ts +214 -19
  114. package/scripts/signature-store-fs.ts +1 -0
  115. package/scripts/target-version.ts +26 -0
  116. package/src/api-doc.ts +26 -0
  117. package/src/component-properties.d.ts +89 -0
  118. package/src/core-types.ts +42 -15
  119. package/src/doc-corrections.ts +53 -5
  120. package/src/emit-dts.ts +758 -198
  121. package/src/engine-globals.d.ts +5 -1
  122. package/src/go-overloads.d.ts +68 -13
  123. package/src/gui-overloads.d.ts +489 -0
  124. package/src/gui-texture-removal.d.ts +41 -0
  125. package/src/index.ts +2 -0
  126. package/src/lifecycle.ts +30 -21
  127. package/src/msg-overloads.d.ts +25 -13
  128. package/src/signature-store.ts +50 -0
  129. package/src/timers.d.ts +2 -1
  130. package/src/vmath-overloads.d.ts +26 -0
@@ -73,7 +73,7 @@ declare global {
73
73
  /**
74
74
  * Loaded payload for a successful request.
75
75
  */
76
- buffer?: Opaque<"buffer">;
76
+ buffer?: Opaque<"buffer"> & { length: LuaLengthMethod<number> };
77
77
  }
78
78
  /**
79
79
  * URL opening attributes
@@ -317,7 +317,40 @@ declare global {
317
317
  * }
318
318
  * ```
319
319
  */
320
- function get_config_int(key: string, default_value?: number): number;
320
+ function get_config_int(key: string): number;
321
+ /**
322
+ * Get integer config value from the game.project configuration file with optional default value
323
+ *
324
+ * @param key - key to get value for. The syntax is SECTION.KEY
325
+ * @param default_value - (optional) default value to return if the value does not exist
326
+ * @returns config value as an integer. default_value if the config key does not exist. 0 if no default value was supplied.
327
+ * @example
328
+ * Get user config value
329
+ * ```ts
330
+ * const speed = sys.get_config_int("my_game.speed", 20); // with default value
331
+ * ```
332
+ * @example
333
+ * ```ts
334
+ * const testmode = sys.get_config_int("my_game.testmode"); // without default value
335
+ * if (testmode !== undefined) {
336
+ * // do stuff
337
+ * }
338
+ * ```
339
+ */
340
+ function get_config_int(key: string, default_value: number): number;
341
+ /**
342
+ * Get number config value from the game.project configuration file with optional default value
343
+ *
344
+ * @param key - key to get value for. The syntax is SECTION.KEY
345
+ * @param default_value - (optional) default value to return if the value does not exist
346
+ * @returns config value as an number. default_value if the config key does not exist. 0 if no default value was supplied.
347
+ * @example
348
+ * ```ts
349
+ * // Get user config value
350
+ * const speed = sys.get_config_number("my_game.speed", 20.0);
351
+ * ```
352
+ */
353
+ function get_config_number(key: string): number;
321
354
  /**
322
355
  * Get number config value from the game.project configuration file with optional default value
323
356
  *
@@ -330,7 +363,7 @@ declare global {
330
363
  * const speed = sys.get_config_number("my_game.speed", 20.0);
331
364
  * ```
332
365
  */
333
- function get_config_number(key: string, default_value?: number): number;
366
+ function get_config_number(key: string, default_value: number): number;
334
367
  /**
335
368
  * Returns the current network connectivity status
336
369
  * on mobile platforms.
@@ -443,7 +476,22 @@ declare global {
443
476
  * }
444
477
  * ```
445
478
  */
446
- function get_sys_info(options?: sys.sys_info_options): sys.sys_info;
479
+ function get_sys_info(): sys.sys_info;
480
+ /**
481
+ * Returns a table with system information.
482
+ *
483
+ * @param options - optional system-information options
484
+ * @returns system information
485
+ * @example
486
+ * ```ts
487
+ * // How to get system information:
488
+ * const info = sys.get_sys_info();
489
+ * if (info.system_name === "HTML5") {
490
+ * // We are running in a browser.
491
+ * }
492
+ * ```
493
+ */
494
+ function get_sys_info(options: sys.sys_info_options): sys.sys_info;
447
495
  /**
448
496
  * If the file exists, it must have been created by `sys.save` to be loaded.
449
497
  * This function will raise a Lua error if an error occurs while loading the file.
@@ -489,7 +537,7 @@ declare global {
489
537
  * const asset_2 = sys.load_buffer("/my/absolute/path");
490
538
  * ```
491
539
  */
492
- function load_buffer(path: string): Opaque<"buffer">;
540
+ function load_buffer(path: string): Opaque<"buffer"> & { length: LuaLengthMethod<number> };
493
541
  /**
494
542
  * The sys.load_buffer function will first try to load the resource
495
543
  * from any of the mounted resource locations and return the data if
@@ -588,7 +636,23 @@ declare global {
588
636
  * }
589
637
  * ```
590
638
  */
591
- function open_url(url: string, attributes?: sys.open_url_attributes): boolean;
639
+ function open_url(url: string): boolean;
640
+ /**
641
+ * Open URL in default application, typically a browser
642
+ *
643
+ * @param url - url to open
644
+ * @param attributes - optional URL opening attributes
645
+ * @returns a boolean indicating if the url could be opened or not
646
+ * @example
647
+ * ```ts
648
+ * // Open an URL:
649
+ * const success = sys.open_url("http://www.defold.com", { target: "_blank" });
650
+ * if (!success) {
651
+ * // could not open the url...
652
+ * }
653
+ * ```
654
+ */
655
+ function open_url(url: string, attributes: sys.open_url_attributes): boolean;
592
656
  /**
593
657
  * Reboots the game engine with a specified set of arguments.
594
658
  * Arguments will be translated into command line arguments. Calling reboot
@@ -69,30 +69,6 @@ declare global {
69
69
  * ```
70
70
  */
71
71
  function cross(v1: Vector3, v2: Vector3): Vector3;
72
- /**
73
- * The returned value is a scalar defined as:
74
- * `P ⋅ Q = |P| |Q| cos θ`
75
- * where θ is the angle between the vectors P and Q.
76
- *
77
- * - If the dot product is positive then the angle between the vectors is below 90 degrees.
78
- * - If the dot product is zero the vectors are perpendicular (at right-angles to each other).
79
- * - If the dot product is negative then the angle between the vectors is more than 90 degrees.
80
- *
81
- * @param v1 - first vector
82
- * @param v2 - second vector
83
- * @returns dot product
84
- * @example
85
- * ```ts
86
- * const vector1 = vmath.vector3(1, 0, 0);
87
- * const vector2 = vmath.vector3(0, 1, 0);
88
- *
89
- * if (vmath.dot(vector1, vector2) === 0) {
90
- * // The two vectors are perpendicular (at right-angles to each other)
91
- * // ...
92
- * }
93
- * ```
94
- */
95
- function dot(v1: Vector3 | Vector4, v2: Vector3 | Vector4): number;
96
72
  /**
97
73
  * The resulting matrix is the inverse of the supplied matrix.
98
74
  * For ortho-normal matrices, e.g. regular object transformation,
@@ -69,30 +69,6 @@ declare global {
69
69
  * ```
70
70
  */
71
71
  function cross(v1: Vector3, v2: Vector3): Vector3;
72
- /**
73
- * The returned value is a scalar defined as:
74
- * `P ⋅ Q = |P| |Q| cos θ`
75
- * where θ is the angle between the vectors P and Q.
76
- *
77
- * - If the dot product is positive then the angle between the vectors is below 90 degrees.
78
- * - If the dot product is zero the vectors are perpendicular (at right-angles to each other).
79
- * - If the dot product is negative then the angle between the vectors is more than 90 degrees.
80
- *
81
- * @param v1 - first vector
82
- * @param v2 - second vector
83
- * @returns dot product
84
- * @example
85
- * ```ts
86
- * const vector1 = vmath.vector3(1, 0, 0);
87
- * const vector2 = vmath.vector3(0, 1, 0);
88
- *
89
- * if (vmath.dot(vector1, vector2) === 0) {
90
- * // The two vectors are perpendicular (at right-angles to each other)
91
- * // ...
92
- * }
93
- * ```
94
- */
95
- function dot(v1: Vector3 | Vector4, v2: Vector3 | Vector4): number;
96
72
  /**
97
73
  * The resulting matrix is the inverse of the supplied matrix.
98
74
  * For ortho-normal matrices, e.g. regular object transformation,
@@ -152,6 +152,7 @@
152
152
  "go.PLAYBACK": "number",
153
153
  "graphics.BLEND_EQUATION": "number",
154
154
  "graphics.BLEND_FACTOR": "number",
155
+ "graphics.BlendFactor": "number",
155
156
  "graphics.BUFFER_TYPE": "number",
156
157
  "graphics.BufferType": "number",
157
158
  "graphics.COMPARE_FUNC": "number",
@@ -212,6 +213,7 @@
212
213
  "render.CONTEXT_EVENT": "number",
213
214
  "render.FRUSTUM_PLANES": "number",
214
215
  "render.RENDER_TARGET_FLAG": "number",
216
+ "render.RenderTargetTextureType": "number",
215
217
  "render.SORT": "number",
216
218
  "sys.NETWORK": "number",
217
219
  "sys.NetworkConnectivity": "number",
@@ -297,6 +299,7 @@
297
299
  "b2d.joint.create_wheel:param:definition",
298
300
  "b2d.shape.ray_cast:param:max_fraction",
299
301
  "b2d.shape.set_shape:param:update_mass",
302
+ "buffer.get_bytes:param:stream_name",
300
303
  "go.cancel_animations:param:url",
301
304
  "go.world_to_local_position:param:url",
302
305
  "go.world_to_local_transform:param:url",
@@ -327,7 +330,6 @@
327
330
  "factory.unload:param:url",
328
331
  "gui.move_above:param:reference",
329
332
  "gui.move_below:param:reference",
330
- "gui.set:param:value",
331
333
  "gui.set_parent:param:parent",
332
334
  "html5.set_interaction_listener:param:callback",
333
335
  "resource.create_buffer:param:table",
@@ -339,6 +341,16 @@
339
341
  ],
340
342
  "parameterCorrections": {
341
343
  "buffer.get_bytes:param:stream_name": { "pins": [["hash"]], "adds": ["string"] },
344
+ "bullet3d.constraint.get_slider_motor:param:motor": {
345
+ "pins": [["string"]],
346
+ "adds": ["\"linear\"", "\"angular\""],
347
+ "removes": ["string"]
348
+ },
349
+ "bullet3d.constraint.set_slider_motor:param:motor": {
350
+ "pins": [["string"]],
351
+ "adds": ["\"linear\"", "\"angular\""],
352
+ "removes": ["string"]
353
+ },
342
354
  "camera.get_aspect_ratio:param:camera": {
343
355
  "pins": [["url", "number", "nil"]],
344
356
  "adds": ["string", "Hash"]
@@ -439,13 +451,11 @@
439
451
  "pins": [["nil", "string", "constant"]],
440
452
  "adds": ["Hash"]
441
453
  },
454
+ "gui.clone_tree:param:node": { "pins": [["node"]], "adds": ["undefined"] },
455
+ "gui.get_tree:param:node": { "pins": [["node"]], "adds": ["undefined"] },
442
456
  "gui.screen_to_local:param:screen_position": { "pins": [["vector3"]], "adds": ["Vector4"] },
443
457
  "gui.set_rotation:param:rotation": { "pins": [["quaternion", "vector4"]], "adds": ["Vector3"] },
444
458
  "gui.set_screen_position:param:screen_position": { "pins": [["vector3"]], "adds": ["Vector4"] },
445
- "gui.set:param:value": {
446
- "pins": [["number", "vector4", "vector3", "quaternion"]],
447
- "adds": ["Matrix4", "Hash"]
448
- },
449
459
  "model.get_mesh_enabled:param:mesh_id": {
450
460
  "pins": [["string", "hash", "url"]],
451
461
  "removes": ["Url"]
@@ -458,15 +468,26 @@
458
468
  "physics.get_maskbit:param:group": { "pins": [["string"]], "adds": ["Hash"] },
459
469
  "physics.set_group:param:group": { "pins": [["string"]], "adds": ["Hash"] },
460
470
  "physics.set_maskbit:param:group": { "pins": [["string"]], "adds": ["Hash"] },
471
+ "render.disable_state:param:state": {
472
+ "pins": [["graphics.STATE"]],
473
+ "adds": ["graphics.State"],
474
+ "removes": ["graphics.STATE"]
475
+ },
461
476
  "render.disable_texture:param:binding": {
462
477
  "pins": [["texture", "string", "hash"]],
463
- "adds": ["number"]
478
+ "adds": ["number"],
479
+ "removes": ["Opaque<\"texture\">"]
464
480
  },
465
481
  "render.draw:param:predicate": {
466
- "pins": [["number"], ["render_predicate"]],
482
+ "pins": [["number"]],
467
483
  "adds": ["Opaque<\"render_predicate\">"],
468
484
  "removes": ["number"]
469
485
  },
486
+ "render.enable_state:param:state": {
487
+ "pins": [["graphics.STATE"]],
488
+ "adds": ["graphics.State"],
489
+ "removes": ["graphics.STATE"]
490
+ },
470
491
  "render.enable_texture:param:handle_or_name": {
471
492
  "pins": [["texture", "string", "hash"]],
472
493
  "adds": ["Opaque<\"render_target\">", "number"]
@@ -479,6 +500,26 @@
479
500
  "pins": [["render_target"]],
480
501
  "adds": ["string", "Hash"]
481
502
  },
503
+ "render.set_blend_func_separate:param:destination_factor_alpha": {
504
+ "pins": [["number"]],
505
+ "adds": ["graphics.BlendFactor"],
506
+ "removes": ["number"]
507
+ },
508
+ "render.set_blend_func_separate:param:destination_factor_color": {
509
+ "pins": [["number"]],
510
+ "adds": ["graphics.BlendFactor"],
511
+ "removes": ["number"]
512
+ },
513
+ "render.set_blend_func_separate:param:source_factor_alpha": {
514
+ "pins": [["number"]],
515
+ "adds": ["graphics.BlendFactor"],
516
+ "removes": ["number"]
517
+ },
518
+ "render.set_blend_func_separate:param:source_factor_color": {
519
+ "pins": [["number"]],
520
+ "adds": ["graphics.BlendFactor"],
521
+ "removes": ["number"]
522
+ },
482
523
  "render.set_camera:param:camera": {
483
524
  "pins": [["url", "number", "nil"]],
484
525
  "adds": ["string", "Hash"]
@@ -539,6 +580,10 @@
539
580
  "undefined"
540
581
  ]
541
582
  },
583
+ "bullet3d.shape.get_shape": {
584
+ "pins": [["bullet3d.shape.definition"]],
585
+ "replaces": ["bullet3d.shape.definition", "{ type: typeof bullet3d.shape.SHAPE_TYPE_MESH }"]
586
+ },
542
587
  "collectionfactory.create": {
543
588
  "pins": [["table"], ["table<hash, hash>"]],
544
589
  "replaces": ["LuaTable<Hash, Hash> & { get: LuaTableGetMethod<string, Hash> }"]
package/index.d.ts CHANGED
@@ -35,6 +35,8 @@ import "./src/go-overloads";
35
35
  import "./src/component-properties";
36
36
  import "./generated/graphics";
37
37
  import "./generated/gui";
38
+ import "./src/gui-overloads";
39
+ import "./src/gui-texture-removal";
38
40
  import "./generated/html5";
39
41
  import "./generated/http";
40
42
  import "./generated/image";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defold-typescript/types",
3
- "version": "0.51.0",
3
+ "version": "0.52.0",
4
4
  "description": "TypeScript types for the Defold engine's Lua APIs.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -93,6 +93,7 @@
93
93
  "!scripts/example-typecheck.ts",
94
94
  "!scripts/example-variant-drift.ts",
95
95
  "!scripts/engine-binding-extract.ts",
96
+ "!scripts/go-instance-functions.ts",
96
97
  "!scripts/binding-pin.ts",
97
98
  "!scripts/sync-engine-bindings.ts",
98
99
  "!scripts/engine-binding-diff.ts",
@@ -28,37 +28,17 @@ import {
28
28
  } from "../src/emit-dts";
29
29
  import { splitTopLevel } from "../src/luals-type-expr";
30
30
  import { type ApiTarget, loadApiTargets, loadTargetModules } from "./regen";
31
+ import { compareVersions, versionOf } from "./target-version";
31
32
 
32
33
  const PACKAGE_ROOT = resolve(import.meta.dir, "..");
33
34
  const MIGRATIONS_PATH = resolve(PACKAGE_ROOT, "api-migrations.json");
34
35
  const AVAILABILITY_PATH = resolve(PACKAGE_ROOT, "api-availability.json");
35
36
 
36
- const VERSION_FROM_ID = /^defold-(\d+\.\d+\.\d+)$/;
37
-
38
37
  export interface AvailabilityArtifact {
39
38
  readonly versions: readonly string[];
40
39
  readonly records: readonly ApiAvailability[];
41
40
  }
42
41
 
43
- export function versionOf(target: ApiTarget): string {
44
- const match = VERSION_FROM_ID.exec(target.id);
45
- if (!match?.[1]) throw new Error(`cannot derive a release version from target id "${target.id}"`);
46
- return match[1];
47
- }
48
-
49
- function versionTuple(version: string): number[] {
50
- return version.split(".").map((part) => Number.parseInt(part, 10));
51
- }
52
-
53
- function compareVersions(a: string, b: string): number {
54
- const [ta, tb] = [versionTuple(a), versionTuple(b)];
55
- for (let index = 0; index < Math.max(ta.length, tb.length); index += 1) {
56
- const diff = (ta[index] ?? 0) - (tb[index] ?? 0);
57
- if (diff !== 0) return diff;
58
- }
59
- return 0;
60
- }
61
-
62
42
  // Every complete committed surface, newest first. The committed targets are the
63
43
  // `source == null` entries of `api-targets.json` (ref-doc-sourced historical
64
44
  // targets are resolved on demand and never a committed-derivation input). This
@@ -1,16 +1,18 @@
1
1
  import { resolve } from "node:path";
2
2
  import { symbolIdentityKey } from "../src/api-availability";
3
- import type { SlotTypes } from "../src/emit-dts";
4
- import { selectCompleteVersionSurfaces, versionOf } from "./generate-api-availability";
3
+ import type { SlotType, SlotTypes } from "../src/emit-dts";
4
+ import { signatureArmsFor } from "../src/signature-store";
5
+ import { selectCompleteVersionSurfaces } from "./generate-api-availability";
5
6
  import {
6
7
  type ApiTarget,
7
- type GenerateOptions,
8
8
  generateModuleSignatures,
9
9
  loadApiTargets,
10
10
  loadTargetModules,
11
11
  type ModuleManifestEntry,
12
+ type TargetBindingOptions,
12
13
  } from "./regen";
13
14
  import { loadSignatureFile } from "./signature-store-fs";
15
+ import { versionOf } from "./target-version";
14
16
 
15
17
  const PACKAGE_ROOT = resolve(import.meta.dir, "..");
16
18
  const SIGNATURES_PATH = resolve(PACKAGE_ROOT, "api-signatures.json");
@@ -35,9 +37,7 @@ export interface BuildSignaturesOptions {
35
37
  // every target is emitted ungated and with no binding-pinned correction.
36
38
  // Supplied by the in-repo callers only: the vendored bindings it reads are not
37
39
  // published.
38
- readonly emitOptionsOf?: (
39
- target: ApiTarget,
40
- ) => Pick<GenerateOptions, "registeredConstants" | "bindingEvidence">;
40
+ readonly emitOptionsOf?: (target: ApiTarget) => TargetBindingOptions;
41
41
  }
42
42
 
43
43
  // The authored replacement for a symbol the skip filter withheld, read from the
@@ -45,22 +45,59 @@ export interface BuildSignaturesOptions {
45
45
  // One seam keeps all three artifacts consistent: `overloads-signature-parity`
46
46
  // pins the store to the `src/*-overloads.d.ts` declarations, so folding the
47
47
  // store in cannot drift from the surface a consumer actually compiles against.
48
- function authoredSignature(packageRoot: string, namespace: string, fqn: string): string | null {
48
+ // Only the arms the target's version declares are folded.
49
+ function authoredSignature(
50
+ packageRoot: string,
51
+ namespace: string,
52
+ fqn: string,
53
+ version: string,
54
+ ): string | null {
49
55
  const store = loadSignatureFile(resolve(packageRoot, "signatures", `${namespace}.json`));
50
- const forms = store[fqn]?.signatures ?? [];
56
+ const override = store[fqn];
57
+ const forms = override ? signatureArmsFor(override, version).signatures : [];
51
58
  return forms.length > 0 ? forms.join("\n") : null;
52
59
  }
53
60
 
61
+ interface UnfilteredSurface {
62
+ readonly entries: readonly ModuleManifestEntry[];
63
+ readonly of: ReadonlyMap<ModuleManifestEntry, ModuleManifestEntry>;
64
+ }
65
+
66
+ const unfilteredSurfaces = new WeakMap<readonly ModuleManifestEntry[], UnfilteredSurface>();
67
+
68
+ // The surface with every member's `skipFunctions` cleared, built once per
69
+ // surface: dropping functions moves no type declaration, so it routes exactly
70
+ // as the filtered one does.
71
+ function unfilteredSurfaceOf(surface: readonly ModuleManifestEntry[]): UnfilteredSurface {
72
+ let unfiltered = unfilteredSurfaces.get(surface);
73
+ if (unfiltered === undefined) {
74
+ const of = new Map(surface.map((member) => [member, { ...member, skipFunctions: [] }]));
75
+ unfiltered = { entries: [...of.values()], of };
76
+ unfilteredSurfaces.set(surface, unfiltered);
77
+ }
78
+ return unfiltered;
79
+ }
80
+
54
81
  // The symbols `skipFunctions` removed from this module, as the difference
55
82
  // between the unfiltered and filtered signature emits. Derived rather than
56
83
  // re-matched so the withholding rules stay owned by `prepareGeneratedModule`.
57
- export function withheldSymbols(entry: ModuleManifestEntry): { key: string; fqn: string }[] {
84
+ // Both emits route in `surface`, the modules the entry is emitted beside, so a
85
+ // slot naming a sibling's type resolves in the unfiltered emit too.
86
+ export function withheldSymbols(
87
+ entry: ModuleManifestEntry,
88
+ surface: readonly ModuleManifestEntry[],
89
+ ): { key: string; fqn: string }[] {
58
90
  if ((entry.skipFunctions ?? []).length === 0) return [];
59
91
  const kept = new Set(
60
- generateModuleSignatures(entry).map(({ identity }) => symbolIdentityKey(identity)),
92
+ generateModuleSignatures(entry, { surface }).map(({ identity }) => symbolIdentityKey(identity)),
61
93
  );
94
+ const unfiltered = unfilteredSurfaceOf(surface);
95
+ const self = unfiltered.of.get(entry);
96
+ if (self === undefined) {
97
+ throw new Error(`module "${entry.namespace}" is not a member of the surface it is emitted in`);
98
+ }
62
99
  const withheld: { key: string; fqn: string }[] = [];
63
- for (const { identity } of generateModuleSignatures({ ...entry, skipFunctions: [] })) {
100
+ for (const { identity } of generateModuleSignatures(self, { surface: unfiltered.entries })) {
64
101
  const key = symbolIdentityKey(identity);
65
102
  if (kept.has(key)) continue;
66
103
  const fqn = key.split("\0")[2] as string;
@@ -69,6 +106,18 @@ export function withheldSymbols(entry: ModuleManifestEntry): { key: string; fqn:
69
106
  return withheld;
70
107
  }
71
108
 
109
+ // The slots two arms record identically. One ledger cannot describe arms whose
110
+ // types differ at a slot, so that slot is dropped and its row falls back to the
111
+ // ref-doc token.
112
+ function commonSlots(a: SlotTypes, b: SlotTypes): SlotTypes {
113
+ const common: Record<string, SlotType> = {};
114
+ for (const [slot, record] of Object.entries(a)) {
115
+ const other = b[slot];
116
+ if (other?.type === record.type && other.optional === record.optional) common[slot] = record;
117
+ }
118
+ return common;
119
+ }
120
+
72
121
  function sortObjectKeys<T>(record: Record<string, T>): Record<string, T> {
73
122
  const sorted: Record<string, T> = {};
74
123
  for (const key of Object.keys(record).sort()) sorted[key] = record[key] as T;
@@ -86,9 +135,21 @@ export function buildSignaturesArtifact(options: BuildSignaturesOptions = {}): S
86
135
  const perSymbol: Record<string, string> = {};
87
136
  const perSymbolSlots: Record<string, SlotTypes> = {};
88
137
  const emitOptions = options.emitOptionsOf?.(target);
89
- for (const entry of loadTargetModules(target, packageRoot)) {
138
+ const surface = loadTargetModules(target, packageRoot);
139
+ for (const entry of surface) {
90
140
  for (const signature of generateModuleSignatures(entry, emitOptions)) {
91
141
  const key = symbolIdentityKey(signature.identity);
142
+ // Two ref-doc elements can normalize to one identity (the Box2D backend
143
+ // forms of a `b2d.world` query), so each keeps its arms in fixture order
144
+ // and the key keeps only the slots every arm shares.
145
+ const earlier = perSymbol[key];
146
+ if (earlier !== undefined) {
147
+ perSymbol[key] = `${earlier}\n${signature.tsSignature}`;
148
+ const common = commonSlots(perSymbolSlots[key] ?? {}, signature.slotTypes);
149
+ if (Object.keys(common).length > 0) perSymbolSlots[key] = common;
150
+ else delete perSymbolSlots[key];
151
+ continue;
152
+ }
92
153
  perSymbol[key] = signature.tsSignature;
93
154
  if (Object.keys(signature.slotTypes).length > 0) {
94
155
  perSymbolSlots[key] = sortObjectKeys({ ...signature.slotTypes });
@@ -96,8 +157,8 @@ export function buildSignaturesArtifact(options: BuildSignaturesOptions = {}): S
96
157
  }
97
158
  // An authored fold replaces the declaration text wholesale, so whatever
98
159
  // slots the generated emit had recorded no longer describe it.
99
- for (const { key, fqn } of withheldSymbols(entry)) {
100
- const authored = authoredSignature(packageRoot, entry.namespace, fqn);
160
+ for (const { key, fqn } of withheldSymbols(entry, surface)) {
161
+ const authored = authoredSignature(packageRoot, entry.namespace, fqn, version);
101
162
  if (authored !== null) {
102
163
  perSymbol[key] = authored;
103
164
  delete perSymbolSlots[key];
@@ -2,19 +2,23 @@ import { mkdirSync, writeFileSync } from "node:fs";
2
2
  import { dirname, resolve } from "node:path";
3
3
  import {
4
4
  type ApiTarget,
5
- type GenerateOptions,
5
+ GO_INSTANCE_SRC_AUGMENTATIONS,
6
6
  generateBuiltinMessagesDeclaration,
7
7
  generateModuleDeclaration,
8
8
  generateVersionIndex,
9
+ goInstanceFreeSurface,
10
+ goInstanceWalls,
9
11
  KIND_MODULE_MANIFEST,
10
12
  type KindManifestEntry,
11
13
  kindStdlibReferences,
14
+ loadGoInstanceFunctions,
12
15
  loadSrcAugmentations,
13
16
  loadTargetEditorModules,
14
17
  MESSAGES_MANIFEST,
15
18
  type ModuleManifestEntry,
16
19
  type ResolveTargetOptions,
17
20
  resolveTargetModules,
21
+ type TargetBindingOptions,
18
22
  } from "./regen";
19
23
 
20
24
  export {
@@ -41,6 +45,11 @@ export interface RenderMaterializedKindIndexOptions {
41
45
  // the universal set outright — an editor kind is disjoint from the runtime
42
46
  // surface, not a narrowing of it.
43
47
  readonly editorModules?: readonly string[];
48
+ // The universal modules the surface also carries as copies without the
49
+ // functions that need a game object, set when the target records which those
50
+ // are. A kind with no game object imports the copies instead and drops the
51
+ // augmentations marked as needing one; every other kind ignores it.
52
+ readonly goInstanceFreeModules?: readonly string[];
44
53
  }
45
54
 
46
55
  // The installed subpath a materialized kind re-exports its factory from: the
@@ -57,11 +66,21 @@ function installedFactoryModule(entry: KindManifestEntry): string {
57
66
  export function renderMaterializedKindIndex(opts: RenderMaterializedKindIndexOptions): string {
58
67
  const entry = KIND_MODULE_MANIFEST.find((e) => e.kind === opts.kind);
59
68
  if (!entry) throw new Error(`unknown script kind: ${opts.kind}`);
69
+ const freeDir = entry.goInstanceFreeDir;
70
+ const copied =
71
+ freeDir === undefined || opts.goInstanceFreeModules === undefined
72
+ ? null
73
+ : new Set(opts.goInstanceFreeModules);
74
+ const universal = opts.universalModules.filter(
75
+ (mod) => copied === null || !GO_INSTANCE_SRC_AUGMENTATIONS.includes(mod),
76
+ );
60
77
  const modules =
61
78
  entry.only === undefined
62
- ? [...new Set(["engine-globals", ...opts.universalModules])].sort()
79
+ ? [...new Set(["engine-globals", ...universal])].sort()
63
80
  : [...(opts.editorModules ?? [])];
64
- const lines = modules.map((mod) => `import "../${mod}";`);
81
+ const lines = modules.map((mod) =>
82
+ copied?.has(mod) ? `import "../${freeDir}/${mod}";` : `import "../${mod}";`,
83
+ );
65
84
  if (entry.only === undefined && opts.restrictedModule) {
66
85
  lines.push(`import "../${opts.restrictedModule}";`);
67
86
  }
@@ -89,14 +108,15 @@ export interface BuildVersionedSurfaceOptions {
89
108
  // script kind without the generator knowing what a script kind is.
90
109
  readonly excludeModules?: readonly string[];
91
110
  // The hand-authored `src/*` augmentations to carry beside the modules.
92
- // Defaults to reading them from the types package on disk; a caller with no
93
- // filesystem (a Worker) supplies the bytes and gets an identical file map.
111
+ // Defaults to reading the target's set (`srcAugmentationModulesFor`) from the
112
+ // types package on disk; a caller with no filesystem (a Worker) supplies the
113
+ // same bytes and gets an identical file map.
94
114
  readonly augmentations?: readonly VersionedSurfaceFile[];
95
115
  // What the target's own engine source decides for its emit
96
116
  // (`targetBindingOptions`). Only an in-repo caller rebuilding a vendored
97
117
  // target's committed surface passes it; a published install vendors no engine
98
118
  // source, and the ref-doc targets it materializes have none to read.
99
- readonly emitOptions?: Pick<GenerateOptions, "registeredConstants" | "bindingEvidence">;
119
+ readonly emitOptions?: TargetBindingOptions;
100
120
  }
101
121
 
102
122
  export interface MaterializeVersionedSurfaceOptions extends BuildVersionedSurfaceOptions {
@@ -142,7 +162,7 @@ export async function buildVersionedSurfaceFiles(
142
162
  ).filter((entry) => kept(entry.outFile));
143
163
 
144
164
  const augmentations = (
145
- opts.augmentations ?? loadSrcAugmentations(opts.resolveOpts?.packageRoot ?? undefined)
165
+ opts.augmentations ?? loadSrcAugmentations(opts.resolveOpts?.packageRoot ?? undefined, target)
146
166
  ).filter((file) => kept(file.path));
147
167
 
148
168
  // Re-rooting an entry makes it a new object no committed manifest holds, so
@@ -158,6 +178,27 @@ export async function buildVersionedSurfaceFiles(
158
178
  })),
159
179
  );
160
180
 
181
+ // A target whose engine source records the functions that need a game object
182
+ // carries, for each kind without one, copies of the modules declaring them
183
+ // with those functions withheld. Nothing else differs, so a target with no
184
+ // record writes no copy.
185
+ const walls = goInstanceWalls(
186
+ modules,
187
+ loadGoInstanceFunctions(target, opts.resolveOpts?.packageRoot ?? undefined),
188
+ );
189
+ for (const kind of KIND_MODULE_MANIFEST) {
190
+ const dir = kind.goInstanceFreeDir;
191
+ if (dir === undefined || walls.size === 0) continue;
192
+ const surface = rerooted(goInstanceFreeSurface(modules, walls, dir).surface);
193
+ for (const entry of surface) {
194
+ if (!entry.outFile.startsWith(`${dir}/`)) continue;
195
+ files.push({
196
+ path: entry.outFile,
197
+ contents: generateModuleDeclaration(entry, { ...opts.emitOptions, surface }).contents,
198
+ });
199
+ }
200
+ }
201
+
161
202
  files.push(...augmentations);
162
203
  files.push({ path: "core-types.d.ts", contents: CORE_TYPES_REEXPORT });
163
204