@ts-defold/types 1.2.75 → 1.2.77
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.
- package/index.d.ts +200 -57
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -3,35 +3,8 @@
|
|
|
3
3
|
/// <reference types="lua-types/5.1" />
|
|
4
4
|
/// <reference types="lua-types/special/jit-only" />
|
|
5
5
|
|
|
6
|
-
// DEFOLD. stable version 1.
|
|
6
|
+
// DEFOLD. stable version 1.12.0 (3206f699aaff89f357c9d549050b8453e080c5d2)
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* All ids in the engine are represented as hashes, so a string needs to be hashed
|
|
10
|
-
before it can be compared with an id.
|
|
11
|
-
* @param s string to hash
|
|
12
|
-
* @returns a hashed string
|
|
13
|
-
* @example To compare a message_id in an on-message callback function:
|
|
14
|
-
```lua
|
|
15
|
-
function on_message(self, message_id, message, sender)
|
|
16
|
-
if message_id == hash("my_message") then
|
|
17
|
-
-- Act on the message here
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
```
|
|
21
|
-
*/
|
|
22
|
-
declare function hash(s: string): hash;
|
|
23
|
-
/**
|
|
24
|
-
* Returns a hexadecimal representation of a hash value.
|
|
25
|
-
The returned string is always padded with leading zeros.
|
|
26
|
-
* @param h hash value to get hex string for
|
|
27
|
-
* @returns hex representation of the hash
|
|
28
|
-
* @example ```lua
|
|
29
|
-
local h = hash("my_hash")
|
|
30
|
-
local hexstr = hash_to_hex(h)
|
|
31
|
-
print(hexstr) --> a2bc06d97f580aab
|
|
32
|
-
```
|
|
33
|
-
*/
|
|
34
|
-
declare function hash_to_hex(h: hash): string;
|
|
35
8
|
/**
|
|
36
9
|
* Pretty printing of Lua values. This function prints Lua values
|
|
37
10
|
in a manner similar to +print()+, but will also recurse into tables
|
|
@@ -61,6 +34,33 @@ Lua tables is undefined):
|
|
|
61
34
|
```
|
|
62
35
|
*/
|
|
63
36
|
declare function pprint(...v: any[]): void;
|
|
37
|
+
/**
|
|
38
|
+
* All ids in the engine are represented as hashes, so a string needs to be hashed
|
|
39
|
+
before it can be compared with an id.
|
|
40
|
+
* @param s string to hash
|
|
41
|
+
* @returns a hashed string
|
|
42
|
+
* @example To compare a message_id in an on-message callback function:
|
|
43
|
+
```lua
|
|
44
|
+
function on_message(self, message_id, message, sender)
|
|
45
|
+
if message_id == hash("my_message") then
|
|
46
|
+
-- Act on the message here
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
```
|
|
50
|
+
*/
|
|
51
|
+
declare function hash(s: string): hash;
|
|
52
|
+
/**
|
|
53
|
+
* Returns a hexadecimal representation of a hash value.
|
|
54
|
+
The returned string is always padded with leading zeros.
|
|
55
|
+
* @param h hash value to get hex string for
|
|
56
|
+
* @returns hex representation of the hash
|
|
57
|
+
* @example ```lua
|
|
58
|
+
local h = hash("my_hash")
|
|
59
|
+
local hexstr = hash_to_hex(h)
|
|
60
|
+
print(hexstr) --> a2bc06d97f580aab
|
|
61
|
+
```
|
|
62
|
+
*/
|
|
63
|
+
declare function hash_to_hex(h: hash): string;
|
|
64
64
|
/**
|
|
65
65
|
* A unique identifier used to reference resources, messages, properties, and other entities within the game.
|
|
66
66
|
*/
|
|
@@ -83,6 +83,33 @@ declare type buffer = object;
|
|
|
83
83
|
declare type bufferstream = LuaUserdata & number[] & object;
|
|
84
84
|
|
|
85
85
|
|
|
86
|
+
declare namespace missingName {
|
|
87
|
+
/**
|
|
88
|
+
* Enables engine throttling.
|
|
89
|
+
* @param enable true if throttling should be enabled
|
|
90
|
+
* @param cooldown the time period to do update + render for (seconds)
|
|
91
|
+
* @example Disable throttling
|
|
92
|
+
```lua
|
|
93
|
+
sys.set_engine_throttle(false)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Enable throttling
|
|
97
|
+
```lua
|
|
98
|
+
sys.set_engine_throttle(true, 1.5)
|
|
99
|
+
```
|
|
100
|
+
*/
|
|
101
|
+
export function set_engine_throttle(enable: boolean, cooldown: number): void;
|
|
102
|
+
/**
|
|
103
|
+
* Disables rendering
|
|
104
|
+
* @param enable true if throttling should be enabled
|
|
105
|
+
* @example Disable rendering
|
|
106
|
+
```lua
|
|
107
|
+
sys.set_render_enable(false)
|
|
108
|
+
```
|
|
109
|
+
*/
|
|
110
|
+
export function set_render_enable(enable: boolean): void;
|
|
111
|
+
}
|
|
112
|
+
|
|
86
113
|
declare namespace b2d {
|
|
87
114
|
/**
|
|
88
115
|
* Get the Box2D body from a collision object
|
|
@@ -637,6 +664,48 @@ export function get_projection(camera: url | number | undefined): vmath.matrix4;
|
|
|
637
664
|
* @returns the view matrix.
|
|
638
665
|
*/
|
|
639
666
|
export function get_view(camera: url | number | undefined): vmath.matrix4;
|
|
667
|
+
/**
|
|
668
|
+
* Converts a screen-space 2D point with view depth to a 3D world point.
|
|
669
|
+
z is the view depth in world units measured from the camera plane along the camera forward axis.
|
|
670
|
+
If a camera isn't specified, the last enabled camera is used.
|
|
671
|
+
* @param pos Screen-space position (x, y) with z as view depth in world units
|
|
672
|
+
* @param camera optional camera id
|
|
673
|
+
* @returns the world coordinate
|
|
674
|
+
* @example Place objects at the touch point with a random Z position, keeping them within the visible view zone.
|
|
675
|
+
```lua
|
|
676
|
+
function on_input(self, action_id, action)
|
|
677
|
+
if action_id == hash("touch") then
|
|
678
|
+
if action.pressed then
|
|
679
|
+
local percpective_camera = msg.url("#perspective_camera")
|
|
680
|
+
local random_z = math.random(camera.get_near_z(percpective_camera) + 0.01, camera.get_far_z(percpective_camera) - 0.01)
|
|
681
|
+
local world_position = camera.screen_to_world(vmath.vector3(action.screen_x, action.screen_y, random_z), percpective_camera)
|
|
682
|
+
go.set_position(world_position, "/go1")
|
|
683
|
+
end
|
|
684
|
+
end
|
|
685
|
+
end
|
|
686
|
+
```
|
|
687
|
+
*/
|
|
688
|
+
export function screen_to_world(pos: vmath.vector3, camera?: url | number | undefined): vmath.vector3;
|
|
689
|
+
/**
|
|
690
|
+
* Converts 2D screen coordinates (x,y) to the 3D world-space point on the camera's near plane for that pixel.
|
|
691
|
+
If a camera isn't specified, the last enabled camera is used.
|
|
692
|
+
* @param x X coordinate on screen.
|
|
693
|
+
* @param y Y coordinate on screen.
|
|
694
|
+
* @param camera optional camera id
|
|
695
|
+
* @returns the world coordinate on the camera near plane
|
|
696
|
+
* @example Place objects at the touch point.
|
|
697
|
+
```lua
|
|
698
|
+
function on_input(self, action_id, action)
|
|
699
|
+
if action_id == hash("touch") then
|
|
700
|
+
if action.pressed then
|
|
701
|
+
local world_position = camera.screen_xy_to_world(action.screen_x, action.screen_y)
|
|
702
|
+
go.set_position(world_position, "/go1")
|
|
703
|
+
end
|
|
704
|
+
end
|
|
705
|
+
end
|
|
706
|
+
```
|
|
707
|
+
*/
|
|
708
|
+
export function screen_xy_to_world(x: number, y: number, camera?: url | number | undefined): vmath.vector3;
|
|
640
709
|
/**
|
|
641
710
|
* Sets the manual aspect ratio for the camera. This value is only used when
|
|
642
711
|
auto aspect ratio is disabled. To disable auto aspect ratio and use this
|
|
@@ -683,6 +752,23 @@ export function set_orthographic_mode(camera: url | number | undefined, mode: nu
|
|
|
683
752
|
* @param orthographic_zoom the zoom level when the camera uses orthographic projection.
|
|
684
753
|
*/
|
|
685
754
|
export function set_orthographic_zoom(camera: url | number | undefined, orthographic_zoom: number): void;
|
|
755
|
+
/**
|
|
756
|
+
* Converts a 3D world position to screen-space coordinates with view depth.
|
|
757
|
+
Returns a vector3 where x and y are in screen pixels and z is the view depth in world units
|
|
758
|
+
measured from the camera plane along the camera forward axis. The returned z can be used with
|
|
759
|
+
camera.screen_to_world to reconstruct the world position on the same pixel ray.
|
|
760
|
+
If a camera isn't specified, the last enabled camera is used.
|
|
761
|
+
* @param world_pos World-space position
|
|
762
|
+
* @param camera optional camera id
|
|
763
|
+
* @returns Screen position (x,y in pixels, z is view depth)
|
|
764
|
+
* @example Convert go position into screen pisition
|
|
765
|
+
```lua
|
|
766
|
+
go.update_world_transform("/go1")
|
|
767
|
+
local world_pos = go.get_world_position("/go1")
|
|
768
|
+
local screen_pos = camera.world_to_screen(world_pos)
|
|
769
|
+
```
|
|
770
|
+
*/
|
|
771
|
+
export function world_to_screen(world_pos: vmath.vector3, camera?: url | number | undefined): vmath.vector3;
|
|
686
772
|
}
|
|
687
773
|
|
|
688
774
|
declare namespace collectionfactory {
|
|
@@ -1133,9 +1219,25 @@ export function unload(url?: string | hash | url): void;
|
|
|
1133
1219
|
|
|
1134
1220
|
declare namespace font {
|
|
1135
1221
|
/**
|
|
1136
|
-
*
|
|
1137
|
-
* @param
|
|
1138
|
-
* @param
|
|
1222
|
+
* associates a ttf resource to a .fontc file.
|
|
1223
|
+
* @param fontc The path to the .fontc resource
|
|
1224
|
+
* @param ttf The path to the .ttf resource
|
|
1225
|
+
* @example ```lua
|
|
1226
|
+
local font_hash = hash("/assets/fonts/roboto.fontc")
|
|
1227
|
+
local ttf_hash = hash("/assets/fonts/Roboto/Roboto-Bold.ttf")
|
|
1228
|
+
font.add_font(font_hash, ttf_hash)
|
|
1229
|
+
```
|
|
1230
|
+
*/
|
|
1231
|
+
export function add_font(fontc: string | hash, ttf: string | hash): void;
|
|
1232
|
+
/**
|
|
1233
|
+
* Gets information about a font, such as the associated font files
|
|
1234
|
+
* @param fontc The path to the .fontc resource
|
|
1235
|
+
*/
|
|
1236
|
+
export function get_info(fontc: string | hash): { path: hash, fonts: { path: string, path_hash: hash }[] };
|
|
1237
|
+
/**
|
|
1238
|
+
* prepopulates the font glyph cache with rasterised glyphs
|
|
1239
|
+
* @param fontc The path to the .fontc resource
|
|
1240
|
+
* @param text The text to layout
|
|
1139
1241
|
* @param callback (optional) A callback function that is called after the request is finished
|
|
1140
1242
|
|
|
1141
1243
|
`self`
|
|
@@ -1149,26 +1251,24 @@ string `nil` if the request was successful
|
|
|
1149
1251
|
|
|
1150
1252
|
* @returns Returns the asynchronous request id
|
|
1151
1253
|
* @example ```lua
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
--
|
|
1155
|
-
-- and we're ready to present the text
|
|
1156
|
-
self.dialog_text_ready = true
|
|
1254
|
+
local font_hash = hash("/assets/fonts/roboto.fontc")
|
|
1255
|
+
font.prewarm_text(font_hash, "Some text", function (self, request_id, result, errstring)
|
|
1256
|
+
-- cache is warm, show the text!
|
|
1157
1257
|
end)
|
|
1158
|
-
```
|
|
1159
|
-
|
|
1160
|
-
```lua
|
|
1161
|
-
-- Remove glyphs
|
|
1162
|
-
local requestid = font.remove_glyphs("/path/to/my.fontc", "abcABC123")
|
|
1163
1258
|
```
|
|
1164
1259
|
*/
|
|
1165
|
-
export function
|
|
1260
|
+
export function prewarm_text(fontc: string | hash, text: string, callback?: ((this: any, request_id: any, result: any, errstring: any) => void)): number;
|
|
1166
1261
|
/**
|
|
1167
|
-
*
|
|
1168
|
-
* @param
|
|
1169
|
-
* @param
|
|
1262
|
+
* associates a ttf resource to a .fontc file
|
|
1263
|
+
* @param fontc The path to the .fontc resource
|
|
1264
|
+
* @param ttf The path to the .ttf resource
|
|
1265
|
+
* @example ```lua
|
|
1266
|
+
local font_hash = hash("/assets/fonts/roboto.fontc")
|
|
1267
|
+
local ttf_hash = hash("/assets/fonts/Roboto/Roboto-Bold.ttf")
|
|
1268
|
+
font.remove_font(font_hash, ttf_hash)
|
|
1269
|
+
```
|
|
1170
1270
|
*/
|
|
1171
|
-
export function
|
|
1271
|
+
export function remove_font(fontc: string | hash, ttf: string | hash): void;
|
|
1172
1272
|
}
|
|
1173
1273
|
|
|
1174
1274
|
declare namespace go {
|
|
@@ -3718,6 +3818,7 @@ export function new_text_node(pos: vmath.vector3 | vmath.vector4, text: string):
|
|
|
3718
3818
|
`"rgb"` - RGB
|
|
3719
3819
|
`"rgba"` - RGBA
|
|
3720
3820
|
`"l"` - LUMINANCE
|
|
3821
|
+
`"astc"` - ASTC compressed format
|
|
3721
3822
|
|
|
3722
3823
|
* @param buffer texture data
|
|
3723
3824
|
* @param flip flip texture vertically
|
|
@@ -3746,6 +3847,16 @@ function init(self)
|
|
|
3746
3847
|
end
|
|
3747
3848
|
end
|
|
3748
3849
|
end
|
|
3850
|
+
```How to create a texture using .astc format
|
|
3851
|
+
|
|
3852
|
+
```lua
|
|
3853
|
+
local path = "/assets/images/logo_4x4.astc"
|
|
3854
|
+
local buffer = sys.load_resource(path)
|
|
3855
|
+
local n = gui.new_box_node(pos, vmath.vector3(size, size, 0))
|
|
3856
|
+
-- size is read from the .astc buffer
|
|
3857
|
+
-- flip is not supported
|
|
3858
|
+
gui.new_texture(path, 0, 0, "astc", buffer, false)
|
|
3859
|
+
gui.set_texture(n, path)
|
|
3749
3860
|
```
|
|
3750
3861
|
*/
|
|
3751
3862
|
export function new_texture(texture_id: string | hash, width: number, height: number, type: string | number, buffer: string, flip: boolean): LuaMultiReturn<[boolean, number]>;
|
|
@@ -4554,6 +4665,7 @@ export function set_texture(node: node, texture: string | hash): void;
|
|
|
4554
4665
|
`"rgb"` - RGB
|
|
4555
4666
|
`"rgba"` - RGBA
|
|
4556
4667
|
`"l"` - LUMINANCE
|
|
4668
|
+
`"astc"` - ASTC compressed format
|
|
4557
4669
|
|
|
4558
4670
|
* @param buffer texture data
|
|
4559
4671
|
* @param flip flip texture vertically
|
|
@@ -4808,6 +4920,24 @@ export const TYPE_RGB: number;
|
|
|
4808
4920
|
* RGBA image type
|
|
4809
4921
|
*/
|
|
4810
4922
|
export const TYPE_RGBA: number;
|
|
4923
|
+
/**
|
|
4924
|
+
* get the header of an .astc buffer
|
|
4925
|
+
* @param buffer .astc file data buffer
|
|
4926
|
+
* @example How to get the block size and dimensions from a .astc file
|
|
4927
|
+
```lua
|
|
4928
|
+
local s = sys.load_resource("/assets/cat.astc")
|
|
4929
|
+
local header = image.get_astc_header(s)
|
|
4930
|
+
pprint(s)
|
|
4931
|
+
```
|
|
4932
|
+
*/
|
|
4933
|
+
export function get_astc_header(buffer: string): {
|
|
4934
|
+
width: number;
|
|
4935
|
+
height: number;
|
|
4936
|
+
depth: number;
|
|
4937
|
+
block_size_x: number;
|
|
4938
|
+
block_size_y: number;
|
|
4939
|
+
block_size_z: number;
|
|
4940
|
+
} | undefined;
|
|
4811
4941
|
/**
|
|
4812
4942
|
* Load image (PNG or JPEG) from buffer.
|
|
4813
4943
|
* @param buffer image data buffer
|
|
@@ -9909,7 +10039,7 @@ export const REQUEST_STATUS_ERROR_NOT_FOUND: number;
|
|
|
9909
10039
|
*/
|
|
9910
10040
|
export const REQUEST_STATUS_FINISHED: number;
|
|
9911
10041
|
/**
|
|
9912
|
-
*
|
|
10042
|
+
* This function will raise a Lua error if an error occurs while deserializing the buffer.
|
|
9913
10043
|
* @param buffer buffer to deserialize from
|
|
9914
10044
|
* @example Deserialize a lua table that was previously serialized:
|
|
9915
10045
|
```lua
|
|
@@ -9981,6 +10111,7 @@ end
|
|
|
9981
10111
|
export function get_application_info(app_string: string): {installed: boolean};
|
|
9982
10112
|
/**
|
|
9983
10113
|
* The path from which the application is run.
|
|
10114
|
+
This function will raise a Lua error if unable to get the application support path.
|
|
9984
10115
|
* @returns path to application executable
|
|
9985
10116
|
* @example Find a path where we can store data (the example path is on the macOS platform):
|
|
9986
10117
|
```lua
|
|
@@ -10005,6 +10136,17 @@ print(application_path) --> http://www.foobar.com/my_game
|
|
|
10005
10136
|
```
|
|
10006
10137
|
*/
|
|
10007
10138
|
export function get_application_path(): string;
|
|
10139
|
+
/**
|
|
10140
|
+
* Get boolean config value from the game.project configuration file with optional default value
|
|
10141
|
+
* @param key key to get value for. The syntax is SECTION.KEY
|
|
10142
|
+
* @param default_value (optional) default value to return if the value does not exist
|
|
10143
|
+
* @returns config value as a boolean. default_value if the config key does not exist. false if no default value was supplied.
|
|
10144
|
+
* @example Get user config value
|
|
10145
|
+
```lua
|
|
10146
|
+
local vsync = sys.get_config_boolean("display.vsync", false)
|
|
10147
|
+
```
|
|
10148
|
+
*/
|
|
10149
|
+
export function get_config_boolean(key: string, default_value?: boolean): boolean;
|
|
10008
10150
|
/**
|
|
10009
10151
|
* Get integer config value from the game.project configuration file with optional default value
|
|
10010
10152
|
* @param key key to get value for. The syntax is SECTION.KEY
|
|
@@ -10118,6 +10260,7 @@ end
|
|
|
10118
10260
|
export function get_ifaddrs(): { name: string, address: string | undefined, mac: string | undefined, up: boolean, running: boolean }[];
|
|
10119
10261
|
/**
|
|
10120
10262
|
* The save-file path is operating system specific and is typically located under the user's home directory.
|
|
10263
|
+
This function will raise a Lua error if unable to get the save file path.
|
|
10121
10264
|
* @param application_id user defined id of the application, which helps define the location of the save-file
|
|
10122
10265
|
* @param file_name file-name to get path for
|
|
10123
10266
|
* @returns path to save-file
|
|
@@ -10161,6 +10304,7 @@ end
|
|
|
10161
10304
|
export function get_sys_info(options?: { ignore_secure: boolean }): {device_model?: string, manufacturer?: string, system_name: string, system_version: string, api_version: string, language: string, device_language: string, territory: string, gmt_offset: number, device_ident?: string, user_agent?: string};
|
|
10162
10305
|
/**
|
|
10163
10306
|
* If the file exists, it must have been created by `sys.save` to be loaded.
|
|
10307
|
+
This function will raise a Lua error if an error occurs while loading the file.
|
|
10164
10308
|
* @param filename file to read from
|
|
10165
10309
|
* @example Load data that was previously saved, e.g. an earlier game session:
|
|
10166
10310
|
```lua
|
|
@@ -10335,23 +10479,22 @@ Additionally, the total number of rows that any one table may contain is limited
|
|
|
10335
10479
|
(i.e. a 16 bit range). When tables are used to represent arrays, the values of
|
|
10336
10480
|
keys are permitted to fall within a 32 bit range, supporting sparse arrays, however
|
|
10337
10481
|
the limit on the total number of rows remains in effect.
|
|
10482
|
+
This function will raise a Lua error if an error occurs while saving the table.
|
|
10338
10483
|
* @param filename file to write to
|
|
10339
10484
|
* @param table lua table to save
|
|
10340
|
-
* @returns a boolean indicating if the table could be saved or not
|
|
10341
10485
|
* @example Save data:
|
|
10342
10486
|
```lua
|
|
10343
10487
|
local my_table = {}
|
|
10344
10488
|
table.insert(my_table, "my_value")
|
|
10345
10489
|
local my_file_path = sys.get_save_file("my_game", "my_file")
|
|
10346
|
-
|
|
10347
|
-
-- Alert user that the data could not be saved
|
|
10348
|
-
end
|
|
10490
|
+
sys.save(my_file_path, my_table)
|
|
10349
10491
|
```
|
|
10350
10492
|
*/
|
|
10351
|
-
export function save(filename: string, table: object):
|
|
10493
|
+
export function save(filename: string, table: object): void;
|
|
10352
10494
|
/**
|
|
10353
10495
|
* The buffer can later deserialized by `sys.deserialize`.
|
|
10354
|
-
This
|
|
10496
|
+
This function has all the same limitations as `sys.save`.
|
|
10497
|
+
This function will raise a Lua error if an error occurs while serializing the table.
|
|
10355
10498
|
* @param table lua table to serialize
|
|
10356
10499
|
* @returns serialized data buffer
|
|
10357
10500
|
* @example Serialize table:
|
|
@@ -11600,22 +11743,22 @@ export type matrix4 = number & {
|
|
|
11600
11743
|
c1: vmath.vector4;
|
|
11601
11744
|
c2: vmath.vector4;
|
|
11602
11745
|
c3: vmath.vector4;
|
|
11746
|
+
m00: number;
|
|
11603
11747
|
m01: number;
|
|
11604
11748
|
m02: number;
|
|
11605
11749
|
m03: number;
|
|
11606
|
-
|
|
11750
|
+
m10: number;
|
|
11607
11751
|
m11: number;
|
|
11608
11752
|
m12: number;
|
|
11609
11753
|
m13: number;
|
|
11610
|
-
|
|
11754
|
+
m20: number;
|
|
11611
11755
|
m21: number;
|
|
11612
11756
|
m22: number;
|
|
11613
11757
|
m23: number;
|
|
11614
|
-
|
|
11758
|
+
m30: number;
|
|
11615
11759
|
m31: number;
|
|
11616
11760
|
m32: number;
|
|
11617
11761
|
m33: number;
|
|
11618
|
-
m34: number;
|
|
11619
11762
|
};
|
|
11620
11763
|
export function mul_per_elem(v1: vmath.vector3, v2: vmath.vector3): vmath.vector3;
|
|
11621
11764
|
export function mul_per_elem(v1: vmath.vector4, v2: vmath.vector4): vmath.vector4;
|