@defold-typescript/types 0.38.0 → 0.40.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 (109) hide show
  1. package/api-availability.json +117 -0
  2. package/api-signatures.json +586 -480
  3. package/examples/translations.json +356 -180
  4. package/generated/b2d_body.d.ts +7 -4
  5. package/generated/b2d_shape.d.ts +23 -1
  6. package/generated/buffer.d.ts +34 -19
  7. package/generated/camera.d.ts +3 -2
  8. package/generated/collectionfactory.d.ts +17 -12
  9. package/generated/collectionproxy.d.ts +2 -2
  10. package/generated/compute.d.ts +1 -1
  11. package/generated/factory.d.ts +2 -1
  12. package/generated/go.d.ts +150 -91
  13. package/generated/graphics.d.ts +54 -0
  14. package/generated/gui.d.ts +117 -71
  15. package/generated/html5.d.ts +4 -2
  16. package/generated/http.d.ts +8 -2
  17. package/generated/image.d.ts +24 -15
  18. package/generated/kinds/gui-script.d.ts +1 -0
  19. package/generated/kinds/render-script.d.ts +1 -0
  20. package/generated/kinds/script.d.ts +1 -0
  21. package/generated/material.d.ts +1 -1
  22. package/generated/model.d.ts +41 -7
  23. package/generated/particlefx.d.ts +1 -1
  24. package/generated/physics.d.ts +29 -20
  25. package/generated/profiler.d.ts +10 -3
  26. package/generated/render.d.ts +293 -111
  27. package/generated/resource.d.ts +243 -226
  28. package/generated/socket.d.ts +33 -18
  29. package/generated/sound.d.ts +6 -5
  30. package/generated/sprite.d.ts +9 -1
  31. package/generated/sys.d.ts +44 -27
  32. package/generated/tilemap.d.ts +25 -19
  33. package/generated/timer.d.ts +33 -24
  34. package/generated/versions/defold-1.12.4/buffer.d.ts +34 -19
  35. package/generated/versions/defold-1.12.4/camera.d.ts +3 -2
  36. package/generated/versions/defold-1.12.4/collectionfactory.d.ts +17 -12
  37. package/generated/versions/defold-1.12.4/collectionproxy.d.ts +1 -1
  38. package/generated/versions/defold-1.12.4/factory.d.ts +2 -1
  39. package/generated/versions/defold-1.12.4/go.d.ts +150 -91
  40. package/generated/versions/defold-1.12.4/graphics.d.ts +2 -0
  41. package/generated/versions/defold-1.12.4/gui.d.ts +109 -69
  42. package/generated/versions/defold-1.12.4/html5.d.ts +4 -2
  43. package/generated/versions/defold-1.12.4/http.d.ts +8 -2
  44. package/generated/versions/defold-1.12.4/image.d.ts +24 -15
  45. package/generated/versions/defold-1.12.4/index.d.ts +1 -0
  46. package/generated/versions/defold-1.12.4/model.d.ts +41 -7
  47. package/generated/versions/defold-1.12.4/particlefx.d.ts +1 -1
  48. package/generated/versions/defold-1.12.4/physics.d.ts +29 -20
  49. package/generated/versions/defold-1.12.4/profiler.d.ts +10 -3
  50. package/generated/versions/defold-1.12.4/render.d.ts +292 -110
  51. package/generated/versions/defold-1.12.4/resource.d.ts +243 -226
  52. package/generated/versions/defold-1.12.4/socket.d.ts +33 -18
  53. package/generated/versions/defold-1.12.4/sound.d.ts +6 -5
  54. package/generated/versions/defold-1.12.4/sprite.d.ts +9 -1
  55. package/generated/versions/defold-1.12.4/sys.d.ts +44 -27
  56. package/generated/versions/defold-1.12.4/tilemap.d.ts +25 -19
  57. package/generated/versions/defold-1.12.4/timer.d.ts +33 -24
  58. package/generated/versions/defold-1.12.4/vmath.d.ts +18 -10
  59. package/generated/versions/defold-1.12.4/window.d.ts +5 -3
  60. package/generated/versions/defold-1.13.0/b2d_body.d.ts +7 -4
  61. package/generated/versions/defold-1.13.0/b2d_shape.d.ts +23 -1
  62. package/generated/versions/defold-1.13.0/buffer.d.ts +34 -19
  63. package/generated/versions/defold-1.13.0/camera.d.ts +3 -2
  64. package/generated/versions/defold-1.13.0/collectionfactory.d.ts +17 -12
  65. package/generated/versions/defold-1.13.0/collectionproxy.d.ts +1 -1
  66. package/generated/versions/defold-1.13.0/compute.d.ts +1 -1
  67. package/generated/versions/defold-1.13.0/factory.d.ts +2 -1
  68. package/generated/versions/defold-1.13.0/go.d.ts +150 -91
  69. package/generated/versions/defold-1.13.0/graphics.d.ts +50 -0
  70. package/generated/versions/defold-1.13.0/gui.d.ts +109 -69
  71. package/generated/versions/defold-1.13.0/html5.d.ts +4 -2
  72. package/generated/versions/defold-1.13.0/http.d.ts +8 -2
  73. package/generated/versions/defold-1.13.0/image.d.ts +24 -15
  74. package/generated/versions/defold-1.13.0/index.d.ts +1 -0
  75. package/generated/versions/defold-1.13.0/material.d.ts +1 -1
  76. package/generated/versions/defold-1.13.0/model.d.ts +41 -7
  77. package/generated/versions/defold-1.13.0/particlefx.d.ts +1 -1
  78. package/generated/versions/defold-1.13.0/physics.d.ts +29 -20
  79. package/generated/versions/defold-1.13.0/profiler.d.ts +10 -3
  80. package/generated/versions/defold-1.13.0/render.d.ts +293 -111
  81. package/generated/versions/defold-1.13.0/resource.d.ts +243 -226
  82. package/generated/versions/defold-1.13.0/socket.d.ts +33 -18
  83. package/generated/versions/defold-1.13.0/sound.d.ts +6 -5
  84. package/generated/versions/defold-1.13.0/sprite.d.ts +9 -1
  85. package/generated/versions/defold-1.13.0/sys.d.ts +44 -27
  86. package/generated/versions/defold-1.13.0/tilemap.d.ts +25 -19
  87. package/generated/versions/defold-1.13.0/timer.d.ts +33 -24
  88. package/generated/versions/defold-1.13.0/vmath.d.ts +18 -10
  89. package/generated/versions/defold-1.13.0/window.d.ts +5 -3
  90. package/generated/vmath.d.ts +18 -10
  91. package/generated/window.d.ts +5 -3
  92. package/index.d.ts +1 -0
  93. package/package.json +2 -1
  94. package/scripts/generate-api-signatures.ts +2 -1
  95. package/scripts/prose-constants.ts +96 -0
  96. package/scripts/regen.ts +6 -2
  97. package/src/api-doc.ts +8 -0
  98. package/src/component-properties.d.ts +33 -0
  99. package/src/core-types.ts +4 -2
  100. package/src/custom-messages.d.ts +4 -3
  101. package/src/doc-comment.ts +247 -43
  102. package/src/emit-dts.ts +958 -57
  103. package/src/engine-globals.d.ts +2 -2
  104. package/src/example-store.ts +26 -0
  105. package/src/go-overloads.d.ts +11 -10
  106. package/src/index.ts +9 -0
  107. package/src/param-correction-provenance.ts +67 -0
  108. package/src/render-overloads.d.ts +15 -17
  109. package/src/script-api.ts +3 -1
@@ -1,5 +1,5 @@
1
1
  /** @noSelfInFile */
2
- import type { Hash, Opaque, Quaternion, Url, Vector, Vector3, Vector4 } from "../../../src/core-types";
2
+ import type { Hash, Matrix4, Opaque, Quaternion, Url, Vector, Vector3, Vector4 } from "../../../src/core-types";
3
3
 
4
4
  declare global {
5
5
  /**
@@ -8,6 +8,20 @@ declare global {
8
8
  * accessible only from gui scripts.
9
9
  */
10
10
  namespace gui {
11
+ type AdjustMode = typeof gui.ADJUST_FIT | typeof gui.ADJUST_ZOOM | typeof gui.ADJUST_STRETCH;
12
+ type BlendMode = typeof gui.BLEND_ALPHA | typeof gui.BLEND_ADD | typeof gui.BLEND_ADD_ALPHA | typeof gui.BLEND_MULT | typeof gui.BLEND_SCREEN;
13
+ type ClippingMode = typeof gui.CLIPPING_MODE_NONE | typeof gui.CLIPPING_MODE_STENCIL;
14
+ type Easing = typeof gui.EASING_INBACK | typeof gui.EASING_INBOUNCE | typeof gui.EASING_INCIRC | typeof gui.EASING_INCUBIC | typeof gui.EASING_INELASTIC | typeof gui.EASING_INEXPO | typeof gui.EASING_INOUTBACK | typeof gui.EASING_INOUTBOUNCE | typeof gui.EASING_INOUTCIRC | typeof gui.EASING_INOUTCUBIC | typeof gui.EASING_INOUTELASTIC | typeof gui.EASING_INOUTEXPO | typeof gui.EASING_INOUTQUAD | typeof gui.EASING_INOUTQUART | typeof gui.EASING_INOUTQUINT | typeof gui.EASING_INOUTSINE | typeof gui.EASING_INQUAD | typeof gui.EASING_INQUART | typeof gui.EASING_INQUINT | typeof gui.EASING_INSINE | typeof gui.EASING_LINEAR | typeof gui.EASING_OUTBACK | typeof gui.EASING_OUTBOUNCE | typeof gui.EASING_OUTCIRC | typeof gui.EASING_OUTCUBIC | typeof gui.EASING_OUTELASTIC | typeof gui.EASING_OUTEXPO | typeof gui.EASING_OUTINBACK | typeof gui.EASING_OUTINBOUNCE | typeof gui.EASING_OUTINCIRC | typeof gui.EASING_OUTINCUBIC | typeof gui.EASING_OUTINELASTIC | typeof gui.EASING_OUTINEXPO | typeof gui.EASING_OUTINQUAD | typeof gui.EASING_OUTINQUART | typeof gui.EASING_OUTINQUINT | typeof gui.EASING_OUTINSINE | typeof gui.EASING_OUTQUAD | typeof gui.EASING_OUTQUART | typeof gui.EASING_OUTQUINT | typeof gui.EASING_OUTSINE;
15
+ type KeyboardType = typeof gui.KEYBOARD_TYPE_DEFAULT | typeof gui.KEYBOARD_TYPE_EMAIL | typeof gui.KEYBOARD_TYPE_NUMBER_PAD | typeof gui.KEYBOARD_TYPE_PASSWORD;
16
+ type NodeType = typeof gui.TYPE_BOX | typeof gui.TYPE_TEXT | typeof gui.TYPE_PIE | typeof gui.TYPE_PARTICLEFX | typeof gui.TYPE_CUSTOM;
17
+ type PieBounds = typeof gui.PIEBOUNDS_RECTANGLE | typeof gui.PIEBOUNDS_ELLIPSE;
18
+ type Pivot = typeof gui.PIVOT_CENTER | typeof gui.PIVOT_N | typeof gui.PIVOT_NE | typeof gui.PIVOT_E | typeof gui.PIVOT_SE | typeof gui.PIVOT_S | typeof gui.PIVOT_SW | typeof gui.PIVOT_W | typeof gui.PIVOT_NW;
19
+ type Playback = typeof gui.PLAYBACK_ONCE_FORWARD | typeof gui.PLAYBACK_ONCE_BACKWARD | typeof gui.PLAYBACK_ONCE_PINGPONG | typeof gui.PLAYBACK_LOOP_FORWARD | typeof gui.PLAYBACK_LOOP_BACKWARD | typeof gui.PLAYBACK_LOOP_PINGPONG;
20
+ type Property = typeof gui.PROP_POSITION | typeof gui.PROP_ROTATION | typeof gui.PROP_EULER | typeof gui.PROP_SCALE | typeof gui.PROP_COLOR | typeof gui.PROP_OUTLINE | typeof gui.PROP_SHADOW | typeof gui.PROP_SIZE | typeof gui.PROP_FILL_ANGLE | typeof gui.PROP_INNER_RADIUS | typeof gui.PROP_LEADING | typeof gui.PROP_TRACKING | typeof gui.PROP_SLICE9;
21
+ type SafeAreaMode = typeof gui.SAFE_AREA_NONE | typeof gui.SAFE_AREA_LONG | typeof gui.SAFE_AREA_SHORT | typeof gui.SAFE_AREA_BOTH;
22
+ type SizeMode = typeof gui.SIZE_MODE_MANUAL | typeof gui.SIZE_MODE_AUTO;
23
+ type XAnchor = typeof gui.ANCHOR_NONE | typeof gui.ANCHOR_LEFT | typeof gui.ANCHOR_RIGHT;
24
+ type YAnchor = typeof gui.ANCHOR_NONE | typeof gui.ANCHOR_TOP | typeof gui.ANCHOR_BOTTOM;
11
25
  /**
12
26
  * Adjust mode is used when the screen resolution differs from the project settings.
13
27
  * The fit mode ensures that the entire node is visible in the adjusted gui scene.
@@ -524,19 +538,24 @@ declare global {
524
538
  *
525
539
  * - `gui.PLAYBACK_LOOP_PINGPONG`
526
540
  * @example
541
+ * How to start a simple color animation, where the node fades in to white during 0.5 seconds:
527
542
  * ```ts
528
543
  * // How to start a simple color animation, where the node fades in to white during 0.5 seconds:
544
+ * const node = gui.get_node("my_node");
529
545
  * gui.set_color(node, vmath.vector4(0, 0, 0, 0)); // node is fully transparent
530
546
  * gui.animate(node, gui.PROP_COLOR, vmath.vector4(1, 1, 1, 1), gui.EASING_INOUTQUAD, 0.5); // start animation
531
- *
547
+ * ```
548
+ * @example
549
+ * How to start a sequenced animation where the node fades in to white during 0.5 seconds, stays visible for 2 seconds and then fades out:
550
+ * ```ts
532
551
  * // How to start a sequenced animation where the node fades in to white during 0.5
533
552
  * // seconds, stays visible for 2 seconds and then fades out:
534
- * function on_animation_done(self, node) {
553
+ * function on_animation_done(self: unknown, node: unknown) {
535
554
  * // fade out node, but wait 2 seconds before the animation starts
536
- * gui.animate(node, gui.PROP_COLOR, vmath.vector4(0, 0, 0, 0), gui.EASING_OUTQUAD, 0.5, 2.0);
555
+ * gui.animate(node as Opaque<"node">, gui.PROP_COLOR, vmath.vector4(0, 0, 0, 0), gui.EASING_OUTQUAD, 0.5, 2.0);
537
556
  * }
538
557
  *
539
- * export default defineScript({
558
+ * export default defineGuiScript({
540
559
  * init(self) {
541
560
  * // fetch the node we want to animate
542
561
  * const my_node = gui.get_node("my_node");
@@ -546,9 +565,12 @@ declare global {
546
565
  * gui.animate(my_node, gui.PROP_COLOR, vmath.vector4(1, 1, 1, 1), gui.EASING_INOUTQUAD, 0.5, 0.0, on_animation_done);
547
566
  * },
548
567
  * });
549
- *
568
+ * ```
569
+ * @example
570
+ * How to animate a node's y position using a crazy custom easing curve:
571
+ * ```ts
550
572
  * // How to animate a node's y position using a crazy custom easing curve:
551
- * export default defineScript({
573
+ * export default defineGuiScript({
552
574
  * init(self) {
553
575
  * const values = [
554
576
  * 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
@@ -563,7 +585,7 @@ declare global {
563
585
  * });
564
586
  * ```
565
587
  */
566
- function animate(node: Opaque<"node">, property: string | number & { readonly __brand: "gui.PROP_POSITION" } | number & { readonly __brand: "gui.PROP_ROTATION" } | number & { readonly __brand: "gui.PROP_EULER" } | number & { readonly __brand: "gui.PROP_SCALE" } | number & { readonly __brand: "gui.PROP_COLOR" } | number & { readonly __brand: "gui.PROP_OUTLINE" } | number & { readonly __brand: "gui.PROP_SHADOW" } | number & { readonly __brand: "gui.PROP_SIZE" } | number & { readonly __brand: "gui.PROP_FILL_ANGLE" } | number & { readonly __brand: "gui.PROP_INNER_RADIUS" } | number & { readonly __brand: "gui.PROP_LEADING" } | number & { readonly __brand: "gui.PROP_TRACKING" } | number & { readonly __brand: "gui.PROP_SLICE9" }, to: number | Vector3 | Vector4 | Quaternion, easing: number & { readonly __brand: "gui.EASING_INBACK" } | number & { readonly __brand: "gui.EASING_INBOUNCE" } | number & { readonly __brand: "gui.EASING_INCIRC" } | number & { readonly __brand: "gui.EASING_INCUBIC" } | number & { readonly __brand: "gui.EASING_INELASTIC" } | number & { readonly __brand: "gui.EASING_INEXPO" } | number & { readonly __brand: "gui.EASING_INOUTBACK" } | number & { readonly __brand: "gui.EASING_INOUTBOUNCE" } | number & { readonly __brand: "gui.EASING_INOUTCIRC" } | number & { readonly __brand: "gui.EASING_INOUTCUBIC" } | number & { readonly __brand: "gui.EASING_INOUTELASTIC" } | number & { readonly __brand: "gui.EASING_INOUTEXPO" } | number & { readonly __brand: "gui.EASING_INOUTQUAD" } | number & { readonly __brand: "gui.EASING_INOUTQUART" } | number & { readonly __brand: "gui.EASING_INOUTQUINT" } | number & { readonly __brand: "gui.EASING_INOUTSINE" } | number & { readonly __brand: "gui.EASING_INQUAD" } | number & { readonly __brand: "gui.EASING_INQUART" } | number & { readonly __brand: "gui.EASING_INQUINT" } | number & { readonly __brand: "gui.EASING_INSINE" } | number & { readonly __brand: "gui.EASING_LINEAR" } | number & { readonly __brand: "gui.EASING_OUTBACK" } | number & { readonly __brand: "gui.EASING_OUTBOUNCE" } | number & { readonly __brand: "gui.EASING_OUTCIRC" } | number & { readonly __brand: "gui.EASING_OUTCUBIC" } | number & { readonly __brand: "gui.EASING_OUTELASTIC" } | number & { readonly __brand: "gui.EASING_OUTEXPO" } | number & { readonly __brand: "gui.EASING_OUTINBACK" } | number & { readonly __brand: "gui.EASING_OUTINBOUNCE" } | number & { readonly __brand: "gui.EASING_OUTINCIRC" } | number & { readonly __brand: "gui.EASING_OUTINCUBIC" } | number & { readonly __brand: "gui.EASING_OUTINELASTIC" } | number & { readonly __brand: "gui.EASING_OUTINEXPO" } | number & { readonly __brand: "gui.EASING_OUTINQUAD" } | number & { readonly __brand: "gui.EASING_OUTINQUART" } | number & { readonly __brand: "gui.EASING_OUTINQUINT" } | number & { readonly __brand: "gui.EASING_OUTINSINE" } | number & { readonly __brand: "gui.EASING_OUTQUAD" } | number & { readonly __brand: "gui.EASING_OUTQUART" } | number & { readonly __brand: "gui.EASING_OUTQUINT" } | number & { readonly __brand: "gui.EASING_OUTSINE" } | Vector, duration: number, delay?: number, complete_function?: (self: unknown, node: unknown) => void, playback?: number & { readonly __brand: "gui.PLAYBACK_ONCE_FORWARD" } | number & { readonly __brand: "gui.PLAYBACK_ONCE_BACKWARD" } | number & { readonly __brand: "gui.PLAYBACK_ONCE_PINGPONG" } | number & { readonly __brand: "gui.PLAYBACK_LOOP_FORWARD" } | number & { readonly __brand: "gui.PLAYBACK_LOOP_BACKWARD" } | number & { readonly __brand: "gui.PLAYBACK_LOOP_PINGPONG" }): void;
588
+ function animate(node: Opaque<"node">, property: string | gui.Property, to: number | Vector3 | Vector4 | Quaternion, easing: gui.Easing | Vector, duration: number, delay?: number, complete_function?: (self: unknown, node: unknown) => void, playback?: gui.Playback): void;
567
589
  /**
568
590
  * If one or more animations of the specified node is currently running (started by `gui.animate`), they will immediately be canceled.
569
591
  *
@@ -602,21 +624,21 @@ declare global {
602
624
  * const node = gui.get_node("my_node");
603
625
  * // animate to new position
604
626
  * const pos = vmath.vector3(100, 100, 0);
605
- * gui.animate(node, "position", pos, go.EASING_LINEAR, 2);
627
+ * gui.animate(node, "position", pos, gui.EASING_LINEAR, 2);
606
628
  * // ...
607
629
  * // cancel animation of the x component.
608
630
  * gui.cancel_animations(node, "position.x");
609
631
  *
610
632
  * // Cancels all property animations on a node in a single call:
611
633
  * // animate to new position and scale
612
- * gui.animate(node, "position", vmath.vector3(100, 100, 0), go.EASING_LINEAR, 5);
613
- * gui.animate(node, "scale", vmath.vector3(0.5), go.EASING_LINEAR, 5);
634
+ * gui.animate(node, "position", vmath.vector3(100, 100, 0), gui.EASING_LINEAR, 5);
635
+ * gui.animate(node, "scale", vmath.vector3(0.5), gui.EASING_LINEAR, 5);
614
636
  * // ...
615
637
  * // cancel positioning and scaling at once
616
638
  * gui.cancel_animations(node);
617
639
  * ```
618
640
  */
619
- function cancel_animations(node: Opaque<"node">, property?: string | number & { readonly __brand: "gui.PROP_POSITION" } | number & { readonly __brand: "gui.PROP_ROTATION" } | number & { readonly __brand: "gui.PROP_EULER" } | number & { readonly __brand: "gui.PROP_SCALE" } | number & { readonly __brand: "gui.PROP_COLOR" } | number & { readonly __brand: "gui.PROP_OUTLINE" } | number & { readonly __brand: "gui.PROP_SHADOW" } | number & { readonly __brand: "gui.PROP_SIZE" } | number & { readonly __brand: "gui.PROP_FILL_ANGLE" } | number & { readonly __brand: "gui.PROP_INNER_RADIUS" } | number & { readonly __brand: "gui.PROP_LEADING" } | number & { readonly __brand: "gui.PROP_TRACKING" } | number & { readonly __brand: "gui.PROP_SLICE9" }): void;
641
+ function cancel_animations(node: Opaque<"node">, property?: string | gui.Property): void;
620
642
  /**
621
643
  * Cancels any running flipbook animation on the specified node.
622
644
  *
@@ -666,7 +688,7 @@ declare global {
666
688
  * @param texture - texture id
667
689
  * @example
668
690
  * ```ts
669
- * export default defineScript({
691
+ * export default defineGuiScript({
670
692
  * init(self) {
671
693
  * // Create a texture.
672
694
  * if (gui.new_texture("temp_tx", 10, 10, "rgb", "\0".repeat(10 * 10 * 3))) {
@@ -691,6 +713,10 @@ declare global {
691
713
  * @example
692
714
  * ```ts
693
715
  * export default defineScript({
716
+ * init() {
717
+ * return { some_value: 0 };
718
+ * },
719
+ *
694
720
  * final(self) {
695
721
  * // report finalization
696
722
  * msg.post("my_friend_instance", "im_dead", { my_stats: self.some_value });
@@ -738,7 +764,7 @@ declare global {
738
764
  * @param node - node to get the property for
739
765
  * @param property - the property to retrieve
740
766
  * @param options - optional options table (only applicable for material constants)
741
- * - `index` number index into array property (1 based)
767
+ * - `index` number zero-based index into array property; the transpiler emits Defold's 1-based index
742
768
  * @example
743
769
  * ```ts
744
770
  * // Get properties on existing nodes:
@@ -746,7 +772,7 @@ declare global {
746
772
  * const node_position = gui.get(node, "position");
747
773
  * ```
748
774
  */
749
- function get(node: Opaque<"node">, property: string | Hash | number & { readonly __brand: "gui.PROP_POSITION" } | number & { readonly __brand: "gui.PROP_ROTATION" } | number & { readonly __brand: "gui.PROP_EULER" } | number & { readonly __brand: "gui.PROP_SCALE" } | number & { readonly __brand: "gui.PROP_COLOR" } | number & { readonly __brand: "gui.PROP_OUTLINE" } | number & { readonly __brand: "gui.PROP_SHADOW" } | number & { readonly __brand: "gui.PROP_SIZE" } | number & { readonly __brand: "gui.PROP_FILL_ANGLE" } | number & { readonly __brand: "gui.PROP_INNER_RADIUS" } | number & { readonly __brand: "gui.PROP_LEADING" } | number & { readonly __brand: "gui.PROP_TRACKING" } | number & { readonly __brand: "gui.PROP_SLICE9" }, options?: { index?: number }): unknown;
775
+ function get(node: Opaque<"node">, property: string | Hash | gui.Property, options?: { index?: number }): unknown;
750
776
  /**
751
777
  * Returns the adjust mode of a node.
752
778
  * The adjust mode defines how the node will adjust itself to screen
@@ -761,7 +787,7 @@ declare global {
761
787
  *
762
788
  * - `gui.ADJUST_STRETCH`
763
789
  */
764
- function get_adjust_mode(node: Opaque<"node">): number & { readonly __brand: "gui.ADJUST_FIT" } | number & { readonly __brand: "gui.ADJUST_ZOOM" } | number & { readonly __brand: "gui.ADJUST_STRETCH" };
790
+ function get_adjust_mode(node: Opaque<"node">): gui.AdjustMode;
765
791
  /**
766
792
  * gets the node alpha
767
793
  *
@@ -786,7 +812,7 @@ declare global {
786
812
  *
787
813
  * - `gui.BLEND_SCREEN`
788
814
  */
789
- function get_blend_mode(node: Opaque<"node">): number & { readonly __brand: "gui.BLEND_ALPHA" } | number & { readonly __brand: "gui.BLEND_ADD" } | number & { readonly __brand: "gui.BLEND_ADD_ALPHA" } | number & { readonly __brand: "gui.BLEND_MULT" } | number & { readonly __brand: "gui.BLEND_SCREEN" };
815
+ function get_blend_mode(node: Opaque<"node">): gui.BlendMode;
790
816
  /**
791
817
  * If node is set as an inverted clipping node, it will clip anything inside as opposed to outside.
792
818
  *
@@ -804,7 +830,7 @@ declare global {
804
830
  *
805
831
  * - `gui.CLIPPING_MODE_STENCIL`
806
832
  */
807
- function get_clipping_mode(node: Opaque<"node">): number & { readonly __brand: "gui.CLIPPING_MODE_NONE" } | number & { readonly __brand: "gui.CLIPPING_MODE_STENCIL" };
833
+ function get_clipping_mode(node: Opaque<"node">): gui.ClippingMode;
808
834
  /**
809
835
  * If node is set as visible clipping node, it will be shown as well as clipping. Otherwise, it will only clip but not show visually.
810
836
  *
@@ -886,7 +912,7 @@ declare global {
886
912
  * @example
887
913
  * ```ts
888
914
  * // Get the text metrics for a text
889
- * export default defineScript({
915
+ * export default defineGuiScript({
890
916
  * init(self) {
891
917
  * const node = gui.get_node("name");
892
918
  * const font_name = gui.get_font(node);
@@ -1030,7 +1056,7 @@ declare global {
1030
1056
  *
1031
1057
  * - `gui.PIEBOUNDS_ELLIPSE`
1032
1058
  */
1033
- function get_outer_bounds(node: Opaque<"node">): number & { readonly __brand: "gui.PIEBOUNDS_RECTANGLE" } | number & { readonly __brand: "gui.PIEBOUNDS_ELLIPSE" };
1059
+ function get_outer_bounds(node: Opaque<"node">): gui.PieBounds;
1034
1060
  /**
1035
1061
  * Returns the outline color of the supplied node.
1036
1062
  * See gui.get_color for info how vectors encode color values.
@@ -1086,7 +1112,7 @@ declare global {
1086
1112
  *
1087
1113
  * - `gui.PIVOT_NW`
1088
1114
  */
1089
- function get_pivot(node: Opaque<"node">): number & { readonly __brand: "gui.PIVOT_CENTER" } | number & { readonly __brand: "gui.PIVOT_N" } | number & { readonly __brand: "gui.PIVOT_NE" } | number & { readonly __brand: "gui.PIVOT_E" } | number & { readonly __brand: "gui.PIVOT_SE" } | number & { readonly __brand: "gui.PIVOT_S" } | number & { readonly __brand: "gui.PIVOT_SW" } | number & { readonly __brand: "gui.PIVOT_W" } | number & { readonly __brand: "gui.PIVOT_NW" };
1115
+ function get_pivot(node: Opaque<"node">): gui.Pivot;
1090
1116
  /**
1091
1117
  * Returns the position of the supplied node.
1092
1118
  *
@@ -1148,7 +1174,7 @@ declare global {
1148
1174
  *
1149
1175
  * - `gui.SIZE_MODE_AUTO`
1150
1176
  */
1151
- function get_size_mode(node: Opaque<"node">): number & { readonly __brand: "gui.SIZE_MODE_MANUAL" } | number & { readonly __brand: "gui.SIZE_MODE_AUTO" };
1177
+ function get_size_mode(node: Opaque<"node">): gui.SizeMode;
1152
1178
  /**
1153
1179
  * Returns the slice9 configuration values for the node.
1154
1180
  *
@@ -1191,7 +1217,7 @@ declare global {
1191
1217
  *
1192
1218
  * @param node - node from which to get the type
1193
1219
  */
1194
- function get_type(node: Opaque<"node">): LuaMultiReturn<[number & { readonly __brand: "gui.TYPE_BOX" } | number & { readonly __brand: "gui.TYPE_TEXT" } | number & { readonly __brand: "gui.TYPE_PIE" } | number & { readonly __brand: "gui.TYPE_PARTICLEFX" } | number & { readonly __brand: "gui.TYPE_CUSTOM" }, number | undefined]>;
1220
+ function get_type(node: Opaque<"node">): LuaMultiReturn<[gui.NodeType, number | undefined]>;
1195
1221
  /**
1196
1222
  * Returns `true` if a node is visible and `false` if it's not.
1197
1223
  * Invisible nodes are not rendered.
@@ -1218,7 +1244,7 @@ declare global {
1218
1244
  *
1219
1245
  * - `gui.ANCHOR_RIGHT`
1220
1246
  */
1221
- function get_xanchor(node: Opaque<"node">): number & { readonly __brand: "gui.ANCHOR_NONE" } | number & { readonly __brand: "gui.ANCHOR_LEFT" } | number & { readonly __brand: "gui.ANCHOR_RIGHT" };
1247
+ function get_xanchor(node: Opaque<"node">): gui.XAnchor;
1222
1248
  /**
1223
1249
  * The y-anchor specifies how the node is moved when the game is run in a different resolution.
1224
1250
  *
@@ -1231,7 +1257,7 @@ declare global {
1231
1257
  *
1232
1258
  * - `gui.ANCHOR_BOTTOM`
1233
1259
  */
1234
- function get_yanchor(node: Opaque<"node">): number & { readonly __brand: "gui.ANCHOR_NONE" } | number & { readonly __brand: "gui.ANCHOR_TOP" } | number & { readonly __brand: "gui.ANCHOR_BOTTOM" };
1260
+ function get_yanchor(node: Opaque<"node">): gui.YAnchor;
1235
1261
  /**
1236
1262
  * Hides the on-display touch keyboard on the device.
1237
1263
  */
@@ -1331,7 +1357,7 @@ declare global {
1331
1357
  * @example
1332
1358
  * ```ts
1333
1359
  * // How to create a texture and apply it to a new box node:
1334
- * export default defineScript({
1360
+ * export default defineGuiScript({
1335
1361
  * init(self) {
1336
1362
  * const w = 200;
1337
1363
  * const h = 300;
@@ -1357,13 +1383,17 @@ declare global {
1357
1383
  * });
1358
1384
  *
1359
1385
  * // How to create a texture using .astc format
1386
+ * const size = 4;
1387
+ * const pos = vmath.vector3(200, 200, 0);
1360
1388
  * const path = "/assets/images/logo_4x4.astc";
1361
- * const buffer = sys.load_resource(path);
1362
- * const n = gui.new_box_node(pos, vmath.vector3(size, size, 0));
1363
- * // size is read from the .astc buffer
1364
- * // flip is not supported
1365
- * gui.new_texture(path, 0, 0, "astc", buffer, false);
1366
- * gui.set_texture(n, path);
1389
+ * const [data] = sys.load_resource(path);
1390
+ * if (data !== undefined) {
1391
+ * const n = gui.new_box_node(pos, vmath.vector3(size, size, 0));
1392
+ * // size is read from the .astc buffer
1393
+ * // flip is not supported
1394
+ * gui.new_texture(path, 0, 0, "astc", data, false);
1395
+ * gui.set_texture(n, path);
1396
+ * }
1367
1397
  * ```
1368
1398
  */
1369
1399
  function new_texture(texture_id: string | Hash, width: number, height: number, type: string | Opaque<"constant">, buffer: string, flip?: boolean): LuaMultiReturn<[boolean, number]>;
@@ -1507,7 +1537,11 @@ declare global {
1507
1537
  * @returns optional boolean to signal if the input should be consumed (not passed on to others) or not, default is false
1508
1538
  * @example
1509
1539
  * ```ts
1510
- * export default defineScript({
1540
+ * export default defineGuiScript({
1541
+ * init(): { my_value: number | undefined } {
1542
+ * return { my_value: undefined };
1543
+ * },
1544
+ *
1511
1545
  * on_input(self, action_id, action) {
1512
1546
  * // check for input
1513
1547
  * if (action_id === hash("my_action")) {
@@ -1541,6 +1575,10 @@ declare global {
1541
1575
  * @example
1542
1576
  * ```ts
1543
1577
  * export default defineGuiScript({
1578
+ * init() {
1579
+ * return { my_original_color: gui.get_color(gui.get_node("my_node")) };
1580
+ * },
1581
+ *
1544
1582
  * on_reload(self) {
1545
1583
  * // restore some color (or similar)
1546
1584
  * gui.set_color(gui.get_node("my_node"), self.my_original_color);
@@ -1584,11 +1622,11 @@ declare global {
1584
1622
  * @example
1585
1623
  * ```ts
1586
1624
  * // Set the texture of a node to a flipbook animation from an atlas:
1587
- * function anim_callback(self, node) {
1625
+ * function anim_callback(self: unknown, node: unknown) {
1588
1626
  * // Take action after animation has played.
1589
1627
  * }
1590
1628
  *
1591
- * export default defineScript({
1629
+ * export default defineGuiScript({
1592
1630
  * init(self) {
1593
1631
  * // Create a new node and set the texture to a flipbook animation
1594
1632
  * const node = gui.get_node("button_node");
@@ -1632,13 +1670,13 @@ declare global {
1632
1670
  * // How to play a particle fx when a gui node is created.
1633
1671
  * // The callback receives the gui node, the hash of the id
1634
1672
  * // of the emitter, and the new state of the emitter as particlefx.EMITTER_STATE_.
1635
- * function emitter_state_change(self, node, emitter, state) {
1673
+ * function emitter_state_change(self: unknown, node: unknown, emitter: unknown, state: unknown) {
1636
1674
  * if (emitter === hash("exhaust") && state === particlefx.EMITTER_STATE_POSTSPAWN) {
1637
1675
  * // exhaust is done spawning particles...
1638
1676
  * }
1639
1677
  * }
1640
1678
  *
1641
- * export default defineScript({
1679
+ * export default defineGuiScript({
1642
1680
  * init(self) {
1643
1681
  * gui.play_particlefx(gui.get_node("particlefx"), emitter_state_change);
1644
1682
  * },
@@ -1723,13 +1761,13 @@ declare global {
1723
1761
  * @param property - the property to set
1724
1762
  * @param value - the property to set
1725
1763
  * @param options - optional options table (only applicable for material constants)
1726
- * - `index` number index into array property (1 based)
1764
+ * - `index` number zero-based index into array property; the transpiler emits Defold's 1-based index
1727
1765
  * - `key` hash name of internal property
1728
1766
  * @example
1729
1767
  * ```ts
1730
1768
  * // Updates the position property on an existing node:
1731
1769
  * const node = gui.get_node("my_box_node");
1732
- * const node_position = gui.get(node, "position");
1770
+ * const node_position = gui.get(node, "position") as Vector3;
1733
1771
  * gui.set(node, "position.x", node_position.x + 128);
1734
1772
  *
1735
1773
  * // Updates the rotation property on an existing node:
@@ -1746,23 +1784,23 @@ declare global {
1746
1784
  * // matrix4 is also supported
1747
1785
  * gui.set(node, "light_matrix", vmath.matrix4());
1748
1786
  * // update a constant in an array at position 4. the array is specified in the shader as:
1749
- * // uniform vec4 tint_array[4]; // lua is 1 based, shader is 0 based
1750
- * gui.set(node, "tint_array", vmath.vector4(1, 0, 0, 1), { index: 4 });
1787
+ * // uniform vec4 tint_array[4]; // TypeScript and the shader are both 0 based
1788
+ * gui.set(node, "tint_array", vmath.vector4(1, 0, 0, 1), { index: 3 });
1751
1789
  * // update a matrix constant in an array at position 4. the array is specified in the shader as:
1752
1790
  * // uniform mat4 light_matrix_array[4];
1753
- * gui.set(node, "light_matrix_array", vmath.matrix4(), { index: 4 });
1791
+ * gui.set(node, "light_matrix_array", vmath.matrix4(), { index: 3 });
1754
1792
  * // update a sub-element in a constant
1755
1793
  * gui.set(node, "tint.x", 1);
1756
1794
  * // update a sub-element in an array constant at position 4
1757
- * gui.set(node, "tint_array.x", 1, { index: 4 });
1795
+ * gui.set(node, "tint_array.x", 1, { index: 3 });
1758
1796
  *
1759
1797
  * // Set a named property
1760
- * export default defineScript({
1798
+ * export default defineGuiScript({
1761
1799
  * on_message(self, message_id, message) {
1762
- * if (message_id === hash("set_font")) {
1800
+ * if (message_id === hash("set_font") && types.is_hash(message.font)) {
1763
1801
  * gui.set(msg.url(), "fonts", message.font, { key: "my_font_name" });
1764
1802
  * gui.set_font(gui.get_node("text"), "my_font_name");
1765
- * } else if (message_id === hash("set_texture")) {
1803
+ * } else if (message_id === hash("set_texture") && types.is_hash(message.texture)) {
1766
1804
  * gui.set(msg.url(), "textures", message.texture, { key: "my_texture" });
1767
1805
  * gui.set_texture(gui.get_node("box"), "my_texture");
1768
1806
  * gui.play_flipbook(gui.get_node("box"), "logo_256");
@@ -1771,7 +1809,7 @@ declare global {
1771
1809
  * });
1772
1810
  * ```
1773
1811
  */
1774
- function set(node: Opaque<"node"> | Url, property: string | Hash | number & { readonly __brand: "gui.PROP_POSITION" } | number & { readonly __brand: "gui.PROP_ROTATION" } | number & { readonly __brand: "gui.PROP_EULER" } | number & { readonly __brand: "gui.PROP_SCALE" } | number & { readonly __brand: "gui.PROP_COLOR" } | number & { readonly __brand: "gui.PROP_OUTLINE" } | number & { readonly __brand: "gui.PROP_SHADOW" } | number & { readonly __brand: "gui.PROP_SIZE" } | number & { readonly __brand: "gui.PROP_FILL_ANGLE" } | number & { readonly __brand: "gui.PROP_INNER_RADIUS" } | number & { readonly __brand: "gui.PROP_LEADING" } | number & { readonly __brand: "gui.PROP_TRACKING" } | number & { readonly __brand: "gui.PROP_SLICE9" }, value: number | Vector4 | Vector3 | Quaternion, options?: { index?: number; key?: Hash }): void;
1812
+ function set(node: Opaque<"node"> | Url, property: string | Hash | gui.Property, value: number | Vector4 | Vector3 | Quaternion | Matrix4 | Hash, options?: { index?: number; key?: string | Hash }): void;
1775
1813
  /**
1776
1814
  * Sets the adjust mode on a node.
1777
1815
  * The adjust mode defines how the node will adjust itself to screen
@@ -1786,7 +1824,7 @@ declare global {
1786
1824
  *
1787
1825
  * - `gui.ADJUST_STRETCH`
1788
1826
  */
1789
- function set_adjust_mode(node: Opaque<"node">, adjust_mode: number & { readonly __brand: "gui.ADJUST_FIT" } | number & { readonly __brand: "gui.ADJUST_ZOOM" } | number & { readonly __brand: "gui.ADJUST_STRETCH" }): void;
1827
+ function set_adjust_mode(node: Opaque<"node">, adjust_mode: gui.AdjustMode): void;
1790
1828
  /**
1791
1829
  * sets the node alpha
1792
1830
  *
@@ -1811,7 +1849,7 @@ declare global {
1811
1849
  *
1812
1850
  * - `gui.BLEND_SCREEN`
1813
1851
  */
1814
- function set_blend_mode(node: Opaque<"node">, blend_mode: number & { readonly __brand: "gui.BLEND_ALPHA" } | number & { readonly __brand: "gui.BLEND_ADD" } | number & { readonly __brand: "gui.BLEND_ADD_ALPHA" } | number & { readonly __brand: "gui.BLEND_MULT" } | number & { readonly __brand: "gui.BLEND_SCREEN" }): void;
1852
+ function set_blend_mode(node: Opaque<"node">, blend_mode: gui.BlendMode): void;
1815
1853
  /**
1816
1854
  * If node is set as an inverted clipping node, it will clip anything inside as opposed to outside.
1817
1855
  *
@@ -1829,7 +1867,7 @@ declare global {
1829
1867
  *
1830
1868
  * - `gui.CLIPPING_MODE_STENCIL`
1831
1869
  */
1832
- function set_clipping_mode(node: Opaque<"node">, clipping_mode: number & { readonly __brand: "gui.CLIPPING_MODE_NONE" } | number & { readonly __brand: "gui.CLIPPING_MODE_STENCIL" }): void;
1870
+ function set_clipping_mode(node: Opaque<"node">, clipping_mode: gui.ClippingMode): void;
1833
1871
  /**
1834
1872
  * If node is set as an visible clipping node, it will be shown as well as clipping. Otherwise, it will only clip but not show visually.
1835
1873
  *
@@ -1997,7 +2035,7 @@ declare global {
1997
2035
  *
1998
2036
  * - `gui.PIEBOUNDS_ELLIPSE`
1999
2037
  */
2000
- function set_outer_bounds(node: Opaque<"node">, bounds_mode: number & { readonly __brand: "gui.PIEBOUNDS_RECTANGLE" } | number & { readonly __brand: "gui.PIEBOUNDS_ELLIPSE" }): void;
2038
+ function set_outer_bounds(node: Opaque<"node">, bounds_mode: gui.PieBounds): void;
2001
2039
  /**
2002
2040
  * Sets the outline color of the supplied node.
2003
2041
  * See gui.set_color for info how vectors encode color values.
@@ -2052,7 +2090,7 @@ declare global {
2052
2090
  *
2053
2091
  * - `gui.PIVOT_NW`
2054
2092
  */
2055
- function set_pivot(node: Opaque<"node">, pivot: number & { readonly __brand: "gui.PIVOT_CENTER" } | number & { readonly __brand: "gui.PIVOT_N" } | number & { readonly __brand: "gui.PIVOT_NE" } | number & { readonly __brand: "gui.PIVOT_E" } | number & { readonly __brand: "gui.PIVOT_SE" } | number & { readonly __brand: "gui.PIVOT_S" } | number & { readonly __brand: "gui.PIVOT_SW" } | number & { readonly __brand: "gui.PIVOT_W" } | number & { readonly __brand: "gui.PIVOT_NW" }): void;
2093
+ function set_pivot(node: Opaque<"node">, pivot: gui.Pivot): void;
2056
2094
  /**
2057
2095
  * Sets the position of the supplied node.
2058
2096
  *
@@ -2077,7 +2115,7 @@ declare global {
2077
2115
  * @param node - node to set the rotation for
2078
2116
  * @param rotation - new rotation
2079
2117
  */
2080
- function set_rotation(node: Opaque<"node">, rotation: Quaternion | Vector4): void;
2118
+ function set_rotation(node: Opaque<"node">, rotation: Quaternion | Vector4 | Vector3): void;
2081
2119
  /**
2082
2120
  * Sets how the safe area is applied to this gui scene.
2083
2121
  *
@@ -2091,7 +2129,7 @@ declare global {
2091
2129
  *
2092
2130
  * - `gui.SAFE_AREA_BOTH`
2093
2131
  */
2094
- function set_safe_area_mode(mode: number & { readonly __brand: "gui.SAFE_AREA_NONE" } | number & { readonly __brand: "gui.SAFE_AREA_LONG" } | number & { readonly __brand: "gui.SAFE_AREA_SHORT" } | number & { readonly __brand: "gui.SAFE_AREA_BOTH" }): void;
2132
+ function set_safe_area_mode(mode: gui.SafeAreaMode): void;
2095
2133
  /**
2096
2134
  * Sets the scaling of the supplied node.
2097
2135
  *
@@ -2137,7 +2175,7 @@ declare global {
2137
2175
  *
2138
2176
  * - `gui.SIZE_MODE_AUTO`
2139
2177
  */
2140
- function set_size_mode(node: Opaque<"node">, size_mode: number & { readonly __brand: "gui.SIZE_MODE_MANUAL" } | number & { readonly __brand: "gui.SIZE_MODE_AUTO" }): void;
2178
+ function set_size_mode(node: Opaque<"node">, size_mode: gui.SizeMode): void;
2141
2179
  /**
2142
2180
  * Set the slice9 configuration values for the node.
2143
2181
  *
@@ -2202,7 +2240,7 @@ declare global {
2202
2240
  * @returns setting the data was successful
2203
2241
  * @example
2204
2242
  * ```ts
2205
- * export default defineScript({
2243
+ * export default defineGuiScript({
2206
2244
  * init(self) {
2207
2245
  * const w = 200;
2208
2246
  * const h = 300;
@@ -2257,7 +2295,7 @@ declare global {
2257
2295
  *
2258
2296
  * - `gui.ANCHOR_RIGHT`
2259
2297
  */
2260
- function set_xanchor(node: Opaque<"node">, anchor: number & { readonly __brand: "gui.ANCHOR_NONE" } | number & { readonly __brand: "gui.ANCHOR_LEFT" } | number & { readonly __brand: "gui.ANCHOR_RIGHT" }): void;
2298
+ function set_xanchor(node: Opaque<"node">, anchor: gui.XAnchor): void;
2261
2299
  /**
2262
2300
  * The y-anchor specifies how the node is moved when the game is run in a different resolution.
2263
2301
  *
@@ -2270,7 +2308,7 @@ declare global {
2270
2308
  *
2271
2309
  * - `gui.ANCHOR_BOTTOM`
2272
2310
  */
2273
- function set_yanchor(node: Opaque<"node">, anchor: number & { readonly __brand: "gui.ANCHOR_NONE" } | number & { readonly __brand: "gui.ANCHOR_TOP" } | number & { readonly __brand: "gui.ANCHOR_BOTTOM" }): void;
2311
+ function set_yanchor(node: Opaque<"node">, anchor: gui.YAnchor): void;
2274
2312
  /**
2275
2313
  * Shows the on-display touch keyboard.
2276
2314
  * The specified type of keyboard is displayed if it is available on
@@ -2288,7 +2326,7 @@ declare global {
2288
2326
  * - `gui.KEYBOARD_TYPE_PASSWORD`
2289
2327
  * @param autoclose - if the keyboard should automatically close when clicking outside
2290
2328
  */
2291
- function show_keyboard(type: number & { readonly __brand: "gui.KEYBOARD_TYPE_DEFAULT" } | number & { readonly __brand: "gui.KEYBOARD_TYPE_EMAIL" } | number & { readonly __brand: "gui.KEYBOARD_TYPE_NUMBER_PAD" } | number & { readonly __brand: "gui.KEYBOARD_TYPE_PASSWORD" }, autoclose: boolean): void;
2329
+ function show_keyboard(type: gui.KeyboardType, autoclose: boolean): void;
2292
2330
  /**
2293
2331
  * Stops the particle fx for a gui node
2294
2332
  *
@@ -2310,15 +2348,17 @@ declare global {
2310
2348
  * // in a counting fashion. It is assumed that the gui component receives messages
2311
2349
  * // from the game when a new score is to be shown.
2312
2350
  * export default defineGuiScript({
2313
- * init(self) {
2314
- * // fetch the score text node for later use (assumes it is called "score")
2315
- * self.score_node = gui.get_node("score");
2316
- * // keep track of the current score counted up so far
2317
- * self.current_score = 0;
2318
- * // keep track of the target score we should count up to
2319
- * self.target_score = 0;
2320
- * // how fast we will update the score, in score/second
2321
- * self.score_update_speed = 1;
2351
+ * init() {
2352
+ * return {
2353
+ * // fetch the score text node for later use (assumes it is called "score")
2354
+ * score_node: gui.get_node("score"),
2355
+ * // keep track of the current score counted up so far
2356
+ * current_score: 0,
2357
+ * // keep track of the target score we should count up to
2358
+ * target_score: 0,
2359
+ * // how fast we will update the score, in score/second
2360
+ * score_update_speed: 1,
2361
+ * };
2322
2362
  * },
2323
2363
  *
2324
2364
  * update(self, dt) {
@@ -2337,7 +2377,7 @@ declare global {
2337
2377
  *
2338
2378
  * on_message(self, message_id, message) {
2339
2379
  * // check the message
2340
- * if (message_id === hash("set_score")) {
2380
+ * if (message_id === hash("set_score") && typeof message.score === "number") {
2341
2381
  * self.target_score = message.score;
2342
2382
  * }
2343
2383
  * },
@@ -18,7 +18,9 @@ declare global {
18
18
  * const res = html5.run("10 + 20"); // returns the string "30"
19
19
  * print(res);
20
20
  * const res_num = tonumber(res); // convert to number
21
- * print(res_num - 20); // prints 10
21
+ * if (res_num !== undefined) {
22
+ * print(res_num - 20); // prints 10
23
+ * }
22
24
  * ```
23
25
  */
24
26
  function run(code: string): string;
@@ -34,7 +36,7 @@ declare global {
34
36
  * object The calling script
35
37
  * @example
36
38
  * ```ts
37
- * function on_interaction(self) {
39
+ * function on_interaction(self: unknown) {
38
40
  * print("on_interaction called");
39
41
  * html5.set_interaction_listener(undefined);
40
42
  * }
@@ -1,4 +1,6 @@
1
1
  /** @noSelfInFile */
2
+ import type { Hash } from "../../../src/core-types";
3
+
2
4
  declare global {
3
5
  /**
4
6
  * Functions for performing HTTP and HTTPS requests.
@@ -53,6 +55,10 @@ declare global {
53
55
  * - boolean `report_progress`: when it is true, the amount of bytes sent and/or received for a request will be passed into the callback function
54
56
  * @example
55
57
  * ```ts
58
+ * function update_my_progress_bar(self: unknown, fraction: number) {
59
+ * // draw the progress bar at the given fraction
60
+ * }
61
+ *
56
62
  * // Basic HTTP-GET request. The callback receives a table with the response
57
63
  * // in the fields status, the response (the data) and headers (a table).
58
64
  * export default defineScript({
@@ -61,7 +67,7 @@ declare global {
61
67
  * "http://www.google.com",
62
68
  * "GET",
63
69
  * (self, _id, response) => {
64
- * if (response.bytes_total !== undefined) {
70
+ * if (response.bytes_received !== undefined && response.bytes_total !== undefined) {
65
71
  * update_my_progress_bar(self, response.bytes_received / response.bytes_total);
66
72
  * } else {
67
73
  * print(response.status);
@@ -77,7 +83,7 @@ declare global {
77
83
  * });
78
84
  * ```
79
85
  */
80
- function request(url: string, method: string, callback: (self: unknown, id: unknown, response: unknown) => void, headers?: LuaMap<string, string>, post_data?: string, options?: { timeout?: number; path?: string; ignore_cache?: boolean; chunked_transfer?: boolean; report_progress?: boolean }): void;
86
+ function request(url: string, method: string, callback: (self: unknown, id: Hash, response: { status: number; response?: string; headers?: LuaMap<string, string>; path?: string; error?: string; bytes_received?: number; bytes_total?: number; range_start?: number; range_end?: number; document_size?: number }) => void, headers?: LuaMap<string, string> | Record<string, string>, post_data?: string, options?: { timeout?: number; path?: string; ignore_cache?: boolean; chunked_transfer?: boolean; report_progress?: boolean }): void;
81
87
  }
82
88
  }
83
89
 
@@ -43,8 +43,10 @@ declare global {
43
43
  * ```ts
44
44
  * // How to get the block size and dimensions from a .astc file
45
45
  * const [s] = sys.load_resource("/assets/cat.astc");
46
- * const header = image.get_astc_header(s);
47
- * pprint(s);
46
+ * if (s !== undefined) {
47
+ * const header = image.get_astc_header(s);
48
+ * pprint(s);
49
+ * }
48
50
  * ```
49
51
  */
50
52
  function get_astc_header(buffer: string): { width: number; height: number; depth: number; block_size_x: number; block_size_y: number; block_size_z: number } | undefined;
@@ -80,8 +82,10 @@ declare global {
80
82
  * // How to load an image from an URL and create a GUI texture from it:
81
83
  * const imgurl = "http://www.site.com/image.png";
82
84
  * http.request(imgurl, "GET", (self, id, response) => {
83
- * const img = image.load(response.response);
84
- * const tx = gui.new_texture("image_node", img.width, img.height, img.type, img.buffer);
85
+ * const img = response.response !== undefined ? image.load(response.response) : undefined;
86
+ * if (img !== undefined) {
87
+ * const tx = gui.new_texture("image_node", img.width, img.height, img.type, img.buffer);
88
+ * }
85
89
  * });
86
90
  * ```
87
91
  */
@@ -118,17 +122,22 @@ declare global {
118
122
  * // Load an image from an URL as a buffer and create a texture resource from it:
119
123
  * const imgurl = "http://www.site.com/image.png";
120
124
  * http.request(imgurl, "GET", (self, id, response) => {
121
- * const img = image.load_buffer(response.response, { flip_vertically: true });
122
- * const tparams = {
123
- * width: img.width,
124
- * height: img.height,
125
- * type: graphics.TEXTURE_TYPE_2D,
126
- * format: graphics.TEXTURE_FORMAT_RGBA,
127
- * };
128
- *
129
- * const my_texture_id = resource.create_texture("/my_custom_texture.texturec", tparams, img.buffer);
130
- * // Apply the texture to a model
131
- * go.set("/go1#model", "texture0", my_texture_id);
125
+ * const img =
126
+ * response.response !== undefined
127
+ * ? image.load_buffer(response.response, { flip_vertically: true })
128
+ * : undefined;
129
+ * if (img !== undefined) {
130
+ * const tparams = {
131
+ * width: img.width,
132
+ * height: img.height,
133
+ * type: graphics.TEXTURE_TYPE_2D,
134
+ * format: graphics.TEXTURE_FORMAT_RGBA,
135
+ * };
136
+ *
137
+ * const my_texture_id = resource.create_texture("/my_custom_texture.texturec", tparams, img.buffer);
138
+ * // Apply the texture to a model
139
+ * go.set("/go1#model", "texture0", my_texture_id);
140
+ * }
132
141
  * });
133
142
  * ```
134
143
  */