@defold-typescript/types 0.4.3 → 0.5.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.
- package/generated/b2d.d.ts +11 -0
- package/generated/buffer.d.ts +142 -0
- package/generated/collectionfactory.d.ts +118 -0
- package/generated/collectionproxy.d.ts +52 -0
- package/generated/crash.d.ts +109 -0
- package/generated/factory.d.ts +94 -0
- package/generated/go.d.ts +880 -0
- package/generated/graphics.d.ts +108 -0
- package/generated/gui.d.ts +1892 -0
- package/generated/http.d.ts +50 -0
- package/generated/iac.d.ts +7 -0
- package/generated/iap.d.ts +41 -0
- package/generated/image.d.ts +95 -0
- package/generated/json.d.ts +59 -0
- package/generated/label.d.ts +64 -0
- package/generated/liveupdate.d.ts +96 -0
- package/generated/model.d.ts +156 -0
- package/generated/msg.d.ts +56 -0
- package/generated/particlefx.d.ts +122 -0
- package/generated/physics.d.ts +451 -0
- package/generated/profiler.d.ts +188 -0
- package/generated/push.d.ts +48 -0
- package/generated/render.d.ts +944 -0
- package/generated/resource.d.ts +1227 -0
- package/generated/socket.d.ts +125 -0
- package/generated/sound.d.ts +246 -0
- package/generated/sprite.d.ts +111 -0
- package/generated/sys.d.ts +513 -0
- package/generated/tilemap.d.ts +151 -0
- package/generated/timer.d.ts +93 -0
- package/generated/vmath.d.ts +914 -0
- package/generated/webview.d.ts +50 -0
- package/generated/window.d.ts +141 -0
- package/generated/zlib.d.ts +28 -0
- package/package.json +1 -1
- package/src/api-doc.ts +10 -1
- package/src/doc-comment.ts +119 -0
- package/src/emit-dts.ts +63 -2
- package/src/index.ts +1 -0
- package/src/lifecycle.ts +28 -7
package/generated/socket.d.ts
CHANGED
|
@@ -6,18 +6,143 @@ declare global {
|
|
|
6
6
|
type client = Opaque<"client">;
|
|
7
7
|
type master = Opaque<"master">;
|
|
8
8
|
type unconnected = Opaque<"unconnected">;
|
|
9
|
+
/**
|
|
10
|
+
* This constant contains the maximum number of sockets that the select function can handle.
|
|
11
|
+
*/
|
|
9
12
|
const _SETSIZE: number & { readonly __brand: "socket._SETSIZE" };
|
|
13
|
+
/**
|
|
14
|
+
* This constant has a string describing the current LuaSocket version.
|
|
15
|
+
*/
|
|
10
16
|
const _VERSION: number & { readonly __brand: "socket._VERSION" };
|
|
17
|
+
/**
|
|
18
|
+
* This function is a shortcut that creates and returns a TCP client object connected to a remote
|
|
19
|
+
* address at a given port. Optionally, the user can also specify the local address and port to
|
|
20
|
+
* bind (`locaddr` and `locport`), or restrict the socket family to `"inet"` or `"inet6"`.
|
|
21
|
+
* Without specifying family to connect, whether a tcp or tcp6 connection is created depends on
|
|
22
|
+
* your system configuration.
|
|
23
|
+
*
|
|
24
|
+
* @param address - the address to connect to.
|
|
25
|
+
* @param port - the port to connect to.
|
|
26
|
+
* @param locaddr - optional local address to bind to.
|
|
27
|
+
* @param locport - optional local port to bind to.
|
|
28
|
+
* @param family - optional socket family to use, `"inet"` or `"inet6"`.
|
|
29
|
+
*/
|
|
11
30
|
function connect(address: string, port: number, locaddr?: string, locport?: number, family?: string): LuaMultiReturn<[Opaque<"client"> | unknown, string | unknown]>;
|
|
31
|
+
/**
|
|
32
|
+
* Returns the time in seconds, relative to the system epoch (Unix epoch time since January 1, 1970 (UTC) or Windows file time since January 1, 1601 (UTC)).
|
|
33
|
+
* You should use the values returned by this function for relative measurements only.
|
|
34
|
+
*
|
|
35
|
+
* @returns the number of seconds elapsed.
|
|
36
|
+
* @example
|
|
37
|
+
* ```lua
|
|
38
|
+
* How to use the gettime() function to measure running time:
|
|
39
|
+
* t = socket.gettime()
|
|
40
|
+
* -- do stuff
|
|
41
|
+
* print(socket.gettime() - t .. " seconds elapsed")
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
12
44
|
function gettime(): number;
|
|
45
|
+
/**
|
|
46
|
+
* This function creates and returns a clean try function that allows for cleanup before the exception is raised.
|
|
47
|
+
* The `finalizer` function will be called in protected mode (see protect).
|
|
48
|
+
*
|
|
49
|
+
* @param finalizer - a function that will be called before the try throws the exception.
|
|
50
|
+
* @returns the customized try function.
|
|
51
|
+
* @example
|
|
52
|
+
* ```lua
|
|
53
|
+
* Perform operations on an open socket c:
|
|
54
|
+
* -- create a try function that closes 'c' on error
|
|
55
|
+
* local try = socket.newtry(function() c:close() end)
|
|
56
|
+
* -- do everything reassured c will be closed
|
|
57
|
+
* try(c:send("hello there?\r\n"))
|
|
58
|
+
* local answer = try(c:receive())
|
|
59
|
+
* ...
|
|
60
|
+
* try(c:send("good bye\r\n"))
|
|
61
|
+
* c:close()
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
13
64
|
function newtry(finalizer: () => void): (...args: unknown[]) => unknown;
|
|
65
|
+
/**
|
|
66
|
+
* Converts a function that throws exceptions into a safe function. This function only catches exceptions thrown by try functions. It does not catch normal Lua errors.
|
|
67
|
+
* Beware that if your function performs some illegal operation that raises an error, the protected function will catch the error and return it as a string. This is because try functions uses errors as the mechanism to throw exceptions.
|
|
68
|
+
*
|
|
69
|
+
* @param func - a function that calls a try function (or assert, or error) to throw exceptions.
|
|
70
|
+
* @returns an equivalent function that instead of throwing exceptions, returns `nil` followed by an error message.
|
|
71
|
+
* @example
|
|
72
|
+
* ```lua
|
|
73
|
+
* local dostuff = socket.protect(function()
|
|
74
|
+
* local try = socket.newtry()
|
|
75
|
+
* local c = try(socket.connect("myserver.com", 80))
|
|
76
|
+
* try = socket.newtry(function() c:close() end)
|
|
77
|
+
* try(c:send("hello?\r\n"))
|
|
78
|
+
* local answer = try(c:receive())
|
|
79
|
+
* c:close()
|
|
80
|
+
* end)
|
|
81
|
+
*
|
|
82
|
+
* local n, error = dostuff()
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
14
85
|
function protect(func: (...args: unknown[]) => unknown): (arg0: unknown) => void;
|
|
86
|
+
/**
|
|
87
|
+
* The function returns a list with the sockets ready for reading, a list with the sockets ready for writing and an error message. The error message is "timeout" if a timeout condition was met and nil otherwise. The returned tables are doubly keyed both by integers and also by the sockets themselves, to simplify the test if a specific socket has changed status.
|
|
88
|
+
* `Recvt` and `sendt` parameters can be empty tables or `nil`. Non-socket values (or values with non-numeric indices) in these arrays will be silently ignored.
|
|
89
|
+
* The returned tables are doubly keyed both by integers and also by the sockets themselves, to simplify the test if a specific socket has changed status.
|
|
90
|
+
* This function can monitor a limited number of sockets, as defined by the constant socket._SETSIZE. This number may be as high as 1024 or as low as 64 by default, depending on the system. It is usually possible to change this at compile time. Invoking select with a larger number of sockets will raise an error.
|
|
91
|
+
* A known bug in WinSock causes select to fail on non-blocking TCP sockets. The function may return a socket as writable even though the socket is not ready for sending.
|
|
92
|
+
* Calling select with a server socket in the receive parameter before a call to accept does not guarantee accept will return immediately. Use the settimeout method or accept might block forever.
|
|
93
|
+
* If you close a socket and pass it to select, it will be ignored.
|
|
94
|
+
* (Using select with non-socket objects: Any object that implements `getfd` and `dirty` can be used with select, allowing objects from other libraries to be used within a socket.select driven loop.)
|
|
95
|
+
*
|
|
96
|
+
* @param recvt - array with the sockets to test for characters available for reading.
|
|
97
|
+
* @param sendt - array with sockets that are watched to see if it is OK to immediately write on them.
|
|
98
|
+
* @param timeout - the maximum amount of time (in seconds) to wait for a change in status. Nil, negative or omitted timeout value allows the function to block indefinitely.
|
|
99
|
+
*/
|
|
15
100
|
function select(recvt: Record<string | number, unknown>, sendt: Record<string | number, unknown>, timeout?: number): LuaMultiReturn<[Record<string | number, unknown>, Record<string | number, unknown>, string | unknown]>;
|
|
101
|
+
/**
|
|
102
|
+
* This function drops a number of arguments and returns the remaining.
|
|
103
|
+
* It is useful to avoid creation of dummy variables:
|
|
104
|
+
* `D` is the number of arguments to drop. `Ret1` to `retN` are the arguments.
|
|
105
|
+
* The function returns `retD+1` to `retN`.
|
|
106
|
+
*
|
|
107
|
+
* @param d - the number of arguments to drop.
|
|
108
|
+
* @param ret1 - argument 1.
|
|
109
|
+
* @param ret2 - argument 2.
|
|
110
|
+
* @param retN - argument N.
|
|
111
|
+
* @example
|
|
112
|
+
* ```lua
|
|
113
|
+
* Instead of doing the following with dummy variables:
|
|
114
|
+
* -- get the status code and separator from SMTP server reply
|
|
115
|
+
* local dummy1, dummy2, code, sep = string.find(line, "^(%d%d%d)(.?)")
|
|
116
|
+
*
|
|
117
|
+
* You can skip a number of variables:
|
|
118
|
+
* -- get the status code and separator from SMTP server reply
|
|
119
|
+
* local code, sep = socket.skip(2, string.find(line, "^(%d%d%d)(.?)"))
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
16
122
|
function skip(d: number, ret1?: unknown, ret2?: unknown, retN?: unknown): LuaMultiReturn<[unknown, unknown, unknown]>;
|
|
123
|
+
/**
|
|
124
|
+
* Freezes the program execution during a given amount of time.
|
|
125
|
+
*
|
|
126
|
+
* @param time - the number of seconds to sleep for.
|
|
127
|
+
*/
|
|
17
128
|
function sleep(time: number): void;
|
|
129
|
+
/**
|
|
130
|
+
* Creates and returns an IPv4 TCP master object. A master object can be transformed into a server object with the method `listen` (after a call to `bind`) or into a client object with the method `connect`. The only other method supported by a master object is the `close` method.
|
|
131
|
+
*/
|
|
18
132
|
function tcp(): LuaMultiReturn<[Opaque<"master"> | unknown, string | unknown]>;
|
|
133
|
+
/**
|
|
134
|
+
* Creates and returns an IPv6 TCP master object. A master object can be transformed into a server object with the method `listen` (after a call to `bind`) or into a client object with the method connect. The only other method supported by a master object is the close method.
|
|
135
|
+
* Note: The TCP object returned will have the option "ipv6-v6only" set to true.
|
|
136
|
+
*/
|
|
19
137
|
function tcp6(): LuaMultiReturn<[Opaque<"master"> | unknown, string | unknown]>;
|
|
138
|
+
/**
|
|
139
|
+
* Creates and returns an unconnected IPv4 UDP object. Unconnected objects support the `sendto`, `receive`, `receivefrom`, `getoption`, `getsockname`, `setoption`, `settimeout`, `setpeername`, `setsockname`, and `close` methods. The `setpeername` method is used to connect the object.
|
|
140
|
+
*/
|
|
20
141
|
function udp(): LuaMultiReturn<[Opaque<"unconnected"> | unknown, string | unknown]>;
|
|
142
|
+
/**
|
|
143
|
+
* Creates and returns an unconnected IPv6 UDP object. Unconnected objects support the `sendto`, `receive`, `receivefrom`, `getoption`, `getsockname`, `setoption`, `settimeout`, `setpeername`, `setsockname`, and `close` methods. The `setpeername` method is used to connect the object.
|
|
144
|
+
* Note: The UDP object returned will have the option "ipv6-v6only" set to true.
|
|
145
|
+
*/
|
|
21
146
|
function udp6(): LuaMultiReturn<[Opaque<"unconnected"> | unknown, string | unknown]>;
|
|
22
147
|
}
|
|
23
148
|
}
|
package/generated/sound.d.ts
CHANGED
|
@@ -3,23 +3,269 @@ import type { Hash, Url } from "../src/core-types";
|
|
|
3
3
|
|
|
4
4
|
declare global {
|
|
5
5
|
namespace sound {
|
|
6
|
+
/**
|
|
7
|
+
* Get mixer group gain
|
|
8
|
+
*
|
|
9
|
+
* @param group - group name
|
|
10
|
+
* @returns gain in [0 1] range ([-60dB.. 0dB])
|
|
11
|
+
* @example
|
|
12
|
+
* ```lua
|
|
13
|
+
* Get the mixer group gain for the "soundfx" and convert to dB:
|
|
14
|
+
* local gain = sound.get_group_gain("soundfx")
|
|
15
|
+
* local gain_db = 60 * gain
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
6
18
|
function get_group_gain(group: string | Hash): number;
|
|
19
|
+
/**
|
|
20
|
+
* Get a mixer group name as a string.
|
|
21
|
+
* This function is to be used for debugging and
|
|
22
|
+
* development tooling only. The function does a reverse hash lookup, which does not
|
|
23
|
+
* return a proper string value when the game is built in release mode.
|
|
24
|
+
*
|
|
25
|
+
* @param group - group name
|
|
26
|
+
* @returns group name
|
|
27
|
+
* @example
|
|
28
|
+
* ```lua
|
|
29
|
+
* Get the mixer group string names so we can show them as labels on a dev mixer overlay:
|
|
30
|
+
* local groups = sound.get_groups()
|
|
31
|
+
* for _,group in ipairs(groups) do
|
|
32
|
+
* local name = sound.get_group_name(group)
|
|
33
|
+
* msg.post("/mixer_overlay#gui", "set_mixer_label", { group = group, label = name})
|
|
34
|
+
* end
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
7
37
|
function get_group_name(group: string | Hash): string;
|
|
38
|
+
/**
|
|
39
|
+
* Get a table of all mixer group names (hashes).
|
|
40
|
+
*
|
|
41
|
+
* @returns table of mixer group names
|
|
42
|
+
* @example
|
|
43
|
+
* ```lua
|
|
44
|
+
* Get the mixer groups, set all gains to 0 except for "master" and "soundfx"
|
|
45
|
+
* where gain is set to 1:
|
|
46
|
+
* local groups = sound.get_groups()
|
|
47
|
+
* for _,group in ipairs(groups) do
|
|
48
|
+
* if group == hash("master") or group == hash("soundfx") then
|
|
49
|
+
* sound.set_group_gain(group, 1)
|
|
50
|
+
* else
|
|
51
|
+
* sound.set_group_gain(group, 0)
|
|
52
|
+
* end
|
|
53
|
+
* end
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
8
56
|
function get_groups(): Hash[];
|
|
57
|
+
/**
|
|
58
|
+
* Get peak value from mixer group.
|
|
59
|
+
* Note that gain is in linear scale, between 0 and 1.
|
|
60
|
+
* To get the dB value from the gain, use the formula `20 * log(gain)`.
|
|
61
|
+
* Inversely, to find the linear value from a dB value, use the formula
|
|
62
|
+
* `10db/20`.
|
|
63
|
+
* Also note that the returned value might be an approximation and in particular
|
|
64
|
+
* the effective window might be larger than specified.
|
|
65
|
+
*
|
|
66
|
+
* @param group - group name
|
|
67
|
+
* @param window - window length in seconds
|
|
68
|
+
* @example
|
|
69
|
+
* ```lua
|
|
70
|
+
* Get the peak gain from the "master" group and convert to dB for displaying:
|
|
71
|
+
* local left_p, right_p = sound.get_peak("master", 0.1)
|
|
72
|
+
* left_p_db = 20 * log(left_p)
|
|
73
|
+
* right_p_db = 20 * log(right_p)
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
9
76
|
function get_peak(group: string | Hash, window: number): LuaMultiReturn<[number, number]>;
|
|
77
|
+
/**
|
|
78
|
+
* Get RMS (Root Mean Square) value from mixer group. This value is the
|
|
79
|
+
* square root of the mean (average) value of the squared function of
|
|
80
|
+
* the instantaneous values.
|
|
81
|
+
* For instance: for a sinewave signal with a peak gain of -1.94 dB (0.8 linear),
|
|
82
|
+
* the RMS is `0.8 × 1/sqrt(2)` which is about 0.566.
|
|
83
|
+
* Note the returned value might be an approximation and in particular
|
|
84
|
+
* the effective window might be larger than specified.
|
|
85
|
+
*
|
|
86
|
+
* @param group - group name
|
|
87
|
+
* @param window - window length in seconds
|
|
88
|
+
* @example
|
|
89
|
+
* ```lua
|
|
90
|
+
* Get the RMS from the "master" group where a mono -1.94 dB sinewave is playing:
|
|
91
|
+
* local rms = sound.get_rms("master", 0.1) -- throw away right channel.
|
|
92
|
+
* print(rms) --> 0.56555819511414
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
10
95
|
function get_rms(group: string | Hash, window: number): LuaMultiReturn<[number, number]>;
|
|
96
|
+
/**
|
|
97
|
+
* Checks if background music is playing, e.g. from iTunes.
|
|
98
|
+
* On non mobile platforms,
|
|
99
|
+
* this function always return `false`.
|
|
100
|
+
* On Android you can only get a correct reading
|
|
101
|
+
* of this state if your game is not playing any sounds itself. This is a limitation
|
|
102
|
+
* in the Android SDK. If your game is playing any sounds, *even with a gain of zero*, this
|
|
103
|
+
* function will return `false`.
|
|
104
|
+
* The best time to call this function is:
|
|
105
|
+
* - In the `init` function of your main collection script before any sounds are triggered
|
|
106
|
+
* - In a window listener callback when the window.WINDOW_EVENT_FOCUS_GAINED event is received
|
|
107
|
+
* Both those times will give you a correct reading of the state even when your application is
|
|
108
|
+
* swapped out and in while playing sounds and it works equally well on Android and iOS.
|
|
109
|
+
*
|
|
110
|
+
* @returns `true` if music is playing, otherwise `false`.
|
|
111
|
+
* @example
|
|
112
|
+
* ```lua
|
|
113
|
+
* If music is playing, mute "master":
|
|
114
|
+
* if sound.is_music_playing() then
|
|
115
|
+
* -- mute "master"
|
|
116
|
+
* sound.set_group_gain("master", 0)
|
|
117
|
+
* end
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
11
120
|
function is_music_playing(): boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Checks if a phone call is active. If there is an active phone call all
|
|
123
|
+
* other sounds will be muted until the phone call is finished.
|
|
124
|
+
* On non mobile platforms,
|
|
125
|
+
* this function always return `false`.
|
|
126
|
+
*
|
|
127
|
+
* @returns `true` if there is an active phone call, `false` otherwise.
|
|
128
|
+
* @example
|
|
129
|
+
* ```lua
|
|
130
|
+
* Test if a phone call is on-going:
|
|
131
|
+
* if sound.is_phone_call_active() then
|
|
132
|
+
* -- do something sensible.
|
|
133
|
+
* end
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
12
136
|
function is_phone_call_active(): boolean;
|
|
137
|
+
/**
|
|
138
|
+
* Pause all active voices
|
|
139
|
+
*
|
|
140
|
+
* @param url - the sound that should pause
|
|
141
|
+
* @param pause - true if the sound should pause
|
|
142
|
+
* @example
|
|
143
|
+
* ```lua
|
|
144
|
+
* Assuming the script belongs to an instance with a sound-component with id "sound", this will make the component pause all playing voices:
|
|
145
|
+
* sound.pause("#sound", true)
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
13
148
|
function pause(url: string | Hash | Url, pause: boolean): void;
|
|
149
|
+
/**
|
|
150
|
+
* Make the sound component play its sound. Multiple voices are supported. The limit is set to 32 voices per sound component.
|
|
151
|
+
* A sound will continue to play even if the game object the sound component belonged to is deleted. You can call `sound.stop()` to stop the sound.
|
|
152
|
+
*
|
|
153
|
+
* @param url - the sound that should play
|
|
154
|
+
* @param play_properties - optional table with properties:
|
|
155
|
+
`delay`
|
|
156
|
+
number delay in seconds before the sound starts playing, default is 0.
|
|
157
|
+
`gain`
|
|
158
|
+
number sound gain between 0 and 1, default is 1. The final gain of the sound will be a combination of this gain, the group gain and the master gain.
|
|
159
|
+
`pan`
|
|
160
|
+
number sound pan between -1 and 1, default is 0. The final pan of the sound will be an addition of this pan and the sound pan.
|
|
161
|
+
`speed`
|
|
162
|
+
number sound speed where 1.0 is normal speed, 0.5 is half speed and 2.0 is double speed. Valid range is 0.0 to 50.0. The final speed of the sound will be a multiplication of this speed and the sound speed.
|
|
163
|
+
`start_time`
|
|
164
|
+
number start playback offset (seconds). Optional, mutually exclusive with `start_frame`.
|
|
165
|
+
`start_frame`
|
|
166
|
+
number start playback offset (frames/samples). Optional, mutually exclusive with `start_time`. If both are provided, `start_frame` is used.
|
|
167
|
+
* @param complete_function - function to call when the sound has finished playing or stopped manually via sound.stop.
|
|
168
|
+
`self`
|
|
169
|
+
object The current object.
|
|
170
|
+
`message_id`
|
|
171
|
+
hash The name of the completion message, which can be either `"sound_done"` if the sound has finished playing, or `"sound_stopped"` if it was stopped manually.
|
|
172
|
+
`message`
|
|
173
|
+
table Information about the completion:
|
|
174
|
+
- number `play_id` - the sequential play identifier that was given by the sound.play function.
|
|
175
|
+
`sender`
|
|
176
|
+
url The invoker of the callback: the sound component.
|
|
177
|
+
* @returns The identifier for the sound voice
|
|
178
|
+
* @example
|
|
179
|
+
* ```lua
|
|
180
|
+
* Assuming the script belongs to an instance with a sound-component with id "sound", this will make the component play its sound after 1 second:
|
|
181
|
+
* sound.play("#sound", { delay = 1, gain = 0.9, pan = -1.0 } )
|
|
182
|
+
*
|
|
183
|
+
* Using the callback argument, you can chain several sounds together:
|
|
184
|
+
* local function sound_done(self, message_id, message, sender)
|
|
185
|
+
* -- play 'boom' sound fx when the countdown has completed
|
|
186
|
+
* if message_id == hash("sound_done") and message.play_id == self.countdown_id then
|
|
187
|
+
* sound.play("#boom", nil, sound_done)
|
|
188
|
+
* end
|
|
189
|
+
* end
|
|
190
|
+
*
|
|
191
|
+
* function init(self)
|
|
192
|
+
* self.countdown_id = sound.play("#countdown", nil, sound_done)
|
|
193
|
+
* end
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
14
196
|
function play(url: string | Hash | Url, play_properties?: { delay?: number; gain?: number; pan?: number; speed?: number; start_time?: number; start_frame?: number }, complete_function?: (self: unknown, message_id: unknown, message: unknown, sender: unknown) => void): number;
|
|
197
|
+
/**
|
|
198
|
+
* Set gain on all active playing voices of a sound.
|
|
199
|
+
*
|
|
200
|
+
* @param url - the sound to set the gain of
|
|
201
|
+
* @param gain - sound gain between 0 and 1 [-60dB .. 0dB]. The final gain of the sound will be a combination of this gain, the group gain and the master gain.
|
|
202
|
+
* @example
|
|
203
|
+
* ```lua
|
|
204
|
+
* Assuming the script belongs to an instance with a sound-component with id "sound", this will set the gain to 0.9
|
|
205
|
+
* sound.set_gain("#sound", 0.9)
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
15
208
|
function set_gain(url: string | Hash | Url, gain?: number): void;
|
|
209
|
+
/**
|
|
210
|
+
* Set mixer group gain
|
|
211
|
+
*
|
|
212
|
+
* @param group - group name
|
|
213
|
+
* @param gain - gain in range [0..1] mapped to [0 .. -60dB]
|
|
214
|
+
* @example
|
|
215
|
+
* ```lua
|
|
216
|
+
* Set mixer group gain on the "soundfx" group to 50% (-30dB):
|
|
217
|
+
* sound.set_group_gain("soundfx", 0.5)
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
16
220
|
function set_group_gain(group: string | Hash, gain: number): void;
|
|
221
|
+
/**
|
|
222
|
+
* Set panning on all active playing voices of a sound.
|
|
223
|
+
* The valid range is from -1.0 to 1.0, representing -45 degrees left, to +45 degrees right.
|
|
224
|
+
*
|
|
225
|
+
* @param url - the sound to set the panning value to
|
|
226
|
+
* @param pan - sound panning between -1.0 and 1.0
|
|
227
|
+
* @example
|
|
228
|
+
* ```lua
|
|
229
|
+
* Assuming the script belongs to an instance with a sound-component with id "sound", this will set the gain to 0.5
|
|
230
|
+
* sound.set_pan("#sound", 0.5) -- pan to the right
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
17
233
|
function set_pan(url: string | Hash | Url, pan?: number): void;
|
|
234
|
+
/**
|
|
235
|
+
* Stop playing all active voices or just one voice if `play_id` provided
|
|
236
|
+
*
|
|
237
|
+
* @param url - the sound component that should stop
|
|
238
|
+
* @param stop_properties - optional table with properties:
|
|
239
|
+
`play_id`
|
|
240
|
+
number the sequential play identifier that should be stopped (was given by the sound.play() function)
|
|
241
|
+
* @example
|
|
242
|
+
* ```lua
|
|
243
|
+
* Assuming the script belongs to an instance with a sound-component with id "sound", this will make the component stop all playing voices:
|
|
244
|
+
* sound.stop("#sound")
|
|
245
|
+
* local id = sound.play("#sound")
|
|
246
|
+
* sound.stop("#sound", {play_id = id})
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
18
249
|
function stop(url: string | Hash | Url, stop_properties?: { play_id?: number }): void;
|
|
19
250
|
interface properties {
|
|
251
|
+
/**
|
|
252
|
+
* The gain on the sound-component. Note that gain is in linear scale,
|
|
253
|
+
* between 0 and 1.
|
|
254
|
+
*/
|
|
20
255
|
gain: number;
|
|
256
|
+
/**
|
|
257
|
+
* The pan on the sound-component. The valid range is from -1.0 to 1.0,
|
|
258
|
+
* representing -45 degrees left, to +45 degrees right.
|
|
259
|
+
*/
|
|
21
260
|
pan: number;
|
|
261
|
+
/**
|
|
262
|
+
* The sound data used when playing the sound. The type of the property is hash.
|
|
263
|
+
*/
|
|
22
264
|
sound: Hash;
|
|
265
|
+
/**
|
|
266
|
+
* The speed on the sound-component where 1.0 is normal speed, 0.5 is half
|
|
267
|
+
* speed and 2.0 is double speed. Valid range is 0.0 to 50.0.
|
|
268
|
+
*/
|
|
23
269
|
speed: number;
|
|
24
270
|
}
|
|
25
271
|
}
|
package/generated/sprite.d.ts
CHANGED
|
@@ -3,18 +3,129 @@ import type { Hash, Url, Vector3, Vector4 } from "../src/core-types";
|
|
|
3
3
|
|
|
4
4
|
declare global {
|
|
5
5
|
namespace sprite {
|
|
6
|
+
/**
|
|
7
|
+
* Play an animation on a sprite component from its tile set
|
|
8
|
+
* An optional completion callback function can be provided that will be called when
|
|
9
|
+
* the animation has completed playing. If no function is provided,
|
|
10
|
+
* a animation_done message is sent to the script that started the animation.
|
|
11
|
+
*
|
|
12
|
+
* @param url - the sprite that should play the animation
|
|
13
|
+
* @param id - hashed id of the animation to play
|
|
14
|
+
* @param complete_function - function to call when the animation has completed.
|
|
15
|
+
`self`
|
|
16
|
+
object The current object.
|
|
17
|
+
`message_id`
|
|
18
|
+
hash The name of the completion message, `"animation_done"`.
|
|
19
|
+
`message`
|
|
20
|
+
table Information about the completion:
|
|
21
|
+
- number `current_tile` - the current tile of the sprite.
|
|
22
|
+
- hash `id` - id of the animation that was completed.
|
|
23
|
+
`sender`
|
|
24
|
+
url The invoker of the callback: the sprite component.
|
|
25
|
+
* @param play_properties - optional table with properties:
|
|
26
|
+
`offset`
|
|
27
|
+
number the normalized initial value of the animation cursor when the animation starts playing.
|
|
28
|
+
`playback_rate`
|
|
29
|
+
number the rate with which the animation will be played. Must be positive.
|
|
30
|
+
* @example
|
|
31
|
+
* ```lua
|
|
32
|
+
* The following examples assumes that the model has id "sprite".
|
|
33
|
+
* How to play the "jump" animation followed by the "run" animation:
|
|
34
|
+
* local function anim_done(self, message_id, message, sender)
|
|
35
|
+
* if message_id == hash("animation_done") then
|
|
36
|
+
* if message.id == hash("jump") then
|
|
37
|
+
* -- jump animation done, chain with "run"
|
|
38
|
+
* sprite.play_flipbook(url, "run")
|
|
39
|
+
* end
|
|
40
|
+
* end
|
|
41
|
+
* end
|
|
42
|
+
*
|
|
43
|
+
* function init(self)
|
|
44
|
+
* local url = msg.url("#sprite")
|
|
45
|
+
* sprite.play_flipbook(url, "jump", anim_done)
|
|
46
|
+
* end
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
6
49
|
function play_flipbook(url: string | Hash | Url, id: string | Hash, complete_function?: (self: unknown, message_id: unknown, message: unknown, sender: unknown) => void, play_properties?: { offset?: number; playback_rate?: number }): void;
|
|
50
|
+
/**
|
|
51
|
+
* Sets horizontal flipping of the provided sprite's animations.
|
|
52
|
+
* The sprite is identified by its URL.
|
|
53
|
+
* If the currently playing animation is flipped by default, flipping it again will make it appear like the original texture.
|
|
54
|
+
*
|
|
55
|
+
* @param url - the sprite that should flip its animations
|
|
56
|
+
* @param flip - `true` if the sprite should flip its animations, `false` if not
|
|
57
|
+
* @example
|
|
58
|
+
* ```lua
|
|
59
|
+
* How to flip a sprite so it faces the horizontal movement:
|
|
60
|
+
* function update(self, dt)
|
|
61
|
+
* -- calculate self.velocity somehow
|
|
62
|
+
* sprite.set_hflip("#sprite", self.velocity.x < 0)
|
|
63
|
+
* end
|
|
64
|
+
*
|
|
65
|
+
* It is assumed that the sprite component has id "sprite" and that the original animations faces right.
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
7
68
|
function set_hflip(url: string | Hash | Url, flip: boolean): void;
|
|
69
|
+
/**
|
|
70
|
+
* Sets vertical flipping of the provided sprite's animations.
|
|
71
|
+
* The sprite is identified by its URL.
|
|
72
|
+
* If the currently playing animation is flipped by default, flipping it again will make it appear like the original texture.
|
|
73
|
+
*
|
|
74
|
+
* @param url - the sprite that should flip its animations
|
|
75
|
+
* @param flip - `true` if the sprite should flip its animations, `false` if not
|
|
76
|
+
* @example
|
|
77
|
+
* ```lua
|
|
78
|
+
* How to flip a sprite in a game which negates gravity as a game mechanic:
|
|
79
|
+
* function update(self, dt)
|
|
80
|
+
* -- calculate self.up_side_down somehow, then:
|
|
81
|
+
* sprite.set_vflip("#sprite", self.up_side_down)
|
|
82
|
+
* end
|
|
83
|
+
*
|
|
84
|
+
* It is assumed that the sprite component has id "sprite" and that the original animations are up-right.
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
8
87
|
function set_vflip(url: string | Hash | Url, flip: boolean): void;
|
|
9
88
|
interface properties {
|
|
89
|
+
/**
|
|
90
|
+
* READ ONLY The current animation id. An animation that plays currently for the sprite. The type of the property is hash.
|
|
91
|
+
*/
|
|
10
92
|
animation: Hash;
|
|
93
|
+
/**
|
|
94
|
+
* The normalized animation cursor. The type of the property is number.
|
|
95
|
+
*/
|
|
11
96
|
cursor: number;
|
|
97
|
+
/**
|
|
98
|
+
* READ ONLY The frame count of the currently playing animation.
|
|
99
|
+
*/
|
|
12
100
|
frame_count: Hash;
|
|
101
|
+
/**
|
|
102
|
+
* The image used when rendering the sprite. The type of the property is hash.
|
|
103
|
+
*/
|
|
13
104
|
image: Hash;
|
|
105
|
+
/**
|
|
106
|
+
* The material used when rendering the sprite. The type of the property is hash.
|
|
107
|
+
*/
|
|
14
108
|
material: Hash;
|
|
109
|
+
/**
|
|
110
|
+
* The animation playback rate. A multiplier to the animation playback rate. The type of the property is number.
|
|
111
|
+
* The playback_rate is a non-negative number, a negative value will be clamped to 0.
|
|
112
|
+
*/
|
|
15
113
|
playback_rate: number;
|
|
114
|
+
/**
|
|
115
|
+
* The non-uniform scale of the sprite. The type of the property is vector3.
|
|
116
|
+
*/
|
|
16
117
|
scale: Vector3;
|
|
118
|
+
/**
|
|
119
|
+
* The size of the sprite, not allowing for any additional scaling that may be applied.
|
|
120
|
+
* The type of the property is vector3. It is not possible to set the size if the size mode
|
|
121
|
+
* of the sprite is set to auto.
|
|
122
|
+
*/
|
|
17
123
|
size: Vector3;
|
|
124
|
+
/**
|
|
125
|
+
* The slice values of the sprite. The type of the property is a vector4 that corresponds to
|
|
126
|
+
* the left, top, right, bottom values of the sprite in the editor.
|
|
127
|
+
* It is not possible to set the slice property if the size mode of the sprite is set to auto.
|
|
128
|
+
*/
|
|
18
129
|
slice: Vector4;
|
|
19
130
|
}
|
|
20
131
|
}
|