warscript 0.0.1-dev.effa673 → 0.0.1-dev.f024cc2
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/attributes.d.ts +5 -0
- package/attributes.lua +8 -1
- package/core/types/frame.lua +10 -12
- package/core/types/player.lua +3 -1
- package/core/types/playerCamera.d.ts +2 -0
- package/core/types/playerCamera.lua +79 -5
- package/core/types/sound.lua +5 -0
- package/core/types/timer.d.ts +8 -8
- package/core/types/timer.lua +25 -23
- package/decl/native.d.ts +844 -788
- package/engine/behavior.d.ts +2 -0
- package/engine/behavior.lua +53 -27
- package/engine/behaviour/ability/apply-buff.lua +1 -1
- package/engine/behaviour/ability/damage.d.ts +6 -3
- package/engine/behaviour/ability/damage.lua +24 -36
- package/engine/behaviour/ability/emulate-impact.d.ts +1 -1
- package/engine/behaviour/ability/emulate-impact.lua +18 -3
- package/engine/behaviour/ability/restore-mana.d.ts +1 -1
- package/engine/behaviour/ability/restore-mana.lua +6 -6
- package/engine/behaviour/ability.lua +8 -17
- package/engine/behaviour/unit/stun-immunity.d.ts +5 -3
- package/engine/behaviour/unit/stun-immunity.lua +43 -27
- package/engine/behaviour/unit.d.ts +26 -0
- package/engine/behaviour/unit.lua +163 -4
- package/engine/buff.d.ts +2 -1
- package/engine/buff.lua +9 -3
- package/engine/internal/ability.d.ts +4 -0
- package/engine/internal/ability.lua +23 -0
- package/engine/internal/item/ability.lua +63 -11
- package/engine/internal/item+owner.lua +12 -6
- package/engine/internal/item.d.ts +5 -2
- package/engine/internal/item.lua +75 -3
- package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
- package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
- package/engine/internal/misc/frame-coordinates.d.ts +2 -0
- package/engine/internal/misc/frame-coordinates.lua +21 -0
- package/engine/internal/misc/get-terrain-z.d.ts +2 -0
- package/engine/internal/misc/get-terrain-z.lua +11 -0
- package/engine/internal/misc/player-local-handle.d.ts +2 -0
- package/engine/internal/misc/player-local-handle.lua +5 -0
- package/engine/internal/unit/ability.d.ts +35 -0
- package/engine/internal/unit/ability.lua +62 -0
- package/engine/internal/unit/allowed-targets.d.ts +1 -1
- package/engine/internal/unit/allowed-targets.lua +9 -1
- package/engine/internal/unit/order.d.ts +20 -0
- package/engine/internal/unit/order.lua +136 -0
- package/engine/internal/unit+ability.lua +1 -1
- package/engine/internal/unit+damage.d.ts +2 -11
- package/engine/internal/unit+damage.lua +10 -14
- package/engine/internal/unit+spellSteal.lua +1 -2
- package/engine/internal/unit-missile-launch.lua +9 -2
- package/engine/internal/unit.d.ts +24 -7
- package/engine/internal/unit.lua +242 -99
- package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
- package/engine/object-data/auxiliary/armor-type.lua +46 -0
- package/engine/object-data/auxiliary/attachment-preset.d.ts +1 -1
- package/engine/object-data/auxiliary/attachment-preset.lua +3 -2
- package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
- package/engine/object-data/auxiliary/attack-type.lua +42 -0
- package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
- package/engine/object-data/auxiliary/movement-type.lua +22 -0
- package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
- package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
- package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
- package/engine/object-data/entry/ability-type/berserk.lua +13 -0
- package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
- package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
- package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
- package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
- package/engine/object-data/entry/ability-type.lua +8 -3
- package/engine/object-data/entry/buff-type/applicable.lua +5 -0
- package/engine/object-data/entry/buff-type.d.ts +5 -11
- package/engine/object-data/entry/buff-type.lua +11 -27
- package/engine/object-data/entry/unit-type.d.ts +13 -4
- package/engine/object-data/entry/unit-type.lua +153 -85
- package/engine/object-field/ability.d.ts +1 -1
- package/engine/object-field/unit.d.ts +57 -3
- package/engine/object-field/unit.lua +207 -7
- package/engine/object-field.d.ts +15 -4
- package/engine/object-field.lua +184 -90
- package/engine/standard/entries/buff-type.d.ts +3 -0
- package/engine/standard/entries/buff-type.lua +3 -0
- package/engine/standard/fields/unit.d.ts +4 -0
- package/engine/standard/fields/unit.lua +7 -0
- package/engine/text-tag.d.ts +36 -2
- package/engine/text-tag.lua +249 -10
- package/engine/unit.d.ts +1 -0
- package/engine/unit.lua +1 -0
- package/objutil/buff.lua +1 -2
- package/package.json +2 -2
- package/utility/arrays.d.ts +1 -0
- package/utility/arrays.lua +3 -0
- package/utility/functions.d.ts +8 -0
- package/utility/functions.lua +13 -0
- package/utility/linked-set.d.ts +1 -0
- package/utility/linked-set.lua +3 -0
- package/utility/lua-maps.d.ts +4 -0
- package/utility/lua-maps.lua +20 -0
- package/utility/lua-sets.d.ts +2 -0
- package/utility/lua-sets.lua +7 -0
- package/core/types/order.d.ts +0 -25
- package/core/types/order.lua +0 -55
package/attributes.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
/** @noSelfInFile */
|
|
2
|
+
declare const marker: {};
|
|
2
3
|
export type Attribute<T> = {
|
|
3
4
|
readonly __attribute: unique symbol;
|
|
4
5
|
readonly __type: T;
|
|
6
|
+
readonly __marker: typeof marker;
|
|
5
7
|
} & symbol;
|
|
8
|
+
export declare const attribute: <T>() => Attribute<T>;
|
|
9
|
+
export declare const isAttribute: (value: unknown) => value is Attribute<unknown>;
|
|
6
10
|
export declare namespace Attribute {
|
|
7
11
|
const create: <T>() => Attribute<T>;
|
|
8
12
|
}
|
|
@@ -10,3 +14,4 @@ export declare class AttributesHolder {
|
|
|
10
14
|
readonly get: (<T>(attribute: Attribute<T>) => T | undefined) & LuaExtension<"TableGetMethod">;
|
|
11
15
|
readonly set: (<T>(attribute: Attribute<T>, value: T | undefined) => void) & LuaExtension<"TableSetMethod">;
|
|
12
16
|
}
|
|
17
|
+
export {};
|
package/attributes.lua
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
local ____lualib = require("lualib_bundle")
|
|
2
2
|
local __TS__Class = ____lualib.__TS__Class
|
|
3
3
|
local ____exports = {}
|
|
4
|
+
local marker = {}
|
|
5
|
+
____exports.attribute = function()
|
|
6
|
+
return {__marker = marker}
|
|
7
|
+
end
|
|
8
|
+
____exports.isAttribute = function(value)
|
|
9
|
+
return type(value) == "table" and rawget(value, "__marker") == marker
|
|
10
|
+
end
|
|
4
11
|
____exports.Attribute = {}
|
|
5
12
|
local Attribute = ____exports.Attribute
|
|
6
13
|
do
|
|
7
14
|
Attribute.create = function()
|
|
8
|
-
return {}
|
|
15
|
+
return {__marker = marker}
|
|
9
16
|
end
|
|
10
17
|
end
|
|
11
18
|
____exports.AttributesHolder = __TS__Class()
|
package/core/types/frame.lua
CHANGED
|
@@ -15,6 +15,10 @@ local Event = ____event.Event
|
|
|
15
15
|
local TriggerEvent = ____event.TriggerEvent
|
|
16
16
|
local ____timer = require("core.types.timer")
|
|
17
17
|
local Timer = ____timer.Timer
|
|
18
|
+
local ____frame_2Dcoordinates = require("engine.internal.misc.frame-coordinates")
|
|
19
|
+
local FRAME_MAX_Y = ____frame_2Dcoordinates.FRAME_MAX_Y
|
|
20
|
+
local FRAME_MIN_Y = ____frame_2Dcoordinates.FRAME_MIN_Y
|
|
21
|
+
local getFrameMinXMaxX = ____frame_2Dcoordinates.getFrameMinXMaxX
|
|
18
22
|
local frameClick = BlzFrameClick
|
|
19
23
|
local frameGetEnable = BlzFrameGetEnable
|
|
20
24
|
local frameIsVisible = BlzFrameIsVisible
|
|
@@ -344,27 +348,21 @@ __TS__ObjectDefineProperty(
|
|
|
344
348
|
Frame,
|
|
345
349
|
"minX",
|
|
346
350
|
{get = function(self)
|
|
347
|
-
local
|
|
348
|
-
|
|
349
|
-
local width4by3 = (w - h / 600 * 800) / 2
|
|
350
|
-
local pxtodpi = 0.6 / h
|
|
351
|
-
return -width4by3 * pxtodpi
|
|
351
|
+
local minX = getFrameMinXMaxX()
|
|
352
|
+
return minX
|
|
352
353
|
end}
|
|
353
354
|
)
|
|
354
355
|
__TS__ObjectDefineProperty(
|
|
355
356
|
Frame,
|
|
356
357
|
"maxX",
|
|
357
358
|
{get = function(self)
|
|
358
|
-
local
|
|
359
|
-
|
|
360
|
-
local width4by3 = (w - h / 600 * 800) / 2
|
|
361
|
-
local pxtodpi = 0.6 / h
|
|
362
|
-
return (-width4by3 + w) * pxtodpi
|
|
359
|
+
local ____, maxX = getFrameMinXMaxX()
|
|
360
|
+
return maxX
|
|
363
361
|
end}
|
|
364
362
|
)
|
|
365
363
|
Frame.centerX = 0.4
|
|
366
|
-
Frame.minY =
|
|
367
|
-
Frame.maxY =
|
|
364
|
+
Frame.minY = FRAME_MIN_Y
|
|
365
|
+
Frame.maxY = FRAME_MAX_Y
|
|
368
366
|
Frame.centerY = 0.3
|
|
369
367
|
__TS__SetDescriptor(
|
|
370
368
|
Frame.prototype,
|
package/core/types/player.lua
CHANGED
|
@@ -21,6 +21,8 @@ local ____exception = require("exception")
|
|
|
21
21
|
local IllegalStateException = ____exception.IllegalStateException
|
|
22
22
|
local ____math = require("math")
|
|
23
23
|
local MAXIMUM_INTEGER = ____math.MAXIMUM_INTEGER
|
|
24
|
+
local ____player_2Dlocal_2Dhandle = require("engine.internal.misc.player-local-handle")
|
|
25
|
+
local PLAYER_LOCAL_HANDLE = ____player_2Dlocal_2Dhandle.PLAYER_LOCAL_HANDLE
|
|
24
26
|
local getPlayerColor = GetPlayerColor
|
|
25
27
|
local getPlayerName = GetPlayerName
|
|
26
28
|
local getPlayerTechCount = GetPlayerTechCount
|
|
@@ -249,7 +251,7 @@ Player.all = (function()
|
|
|
249
251
|
end
|
|
250
252
|
return all
|
|
251
253
|
end)()
|
|
252
|
-
Player["local"] = ____exports.Player:of(
|
|
254
|
+
Player["local"] = ____exports.Player:of(PLAYER_LOCAL_HANDLE)
|
|
253
255
|
Player.neutralPassive = ____exports.Player.all[PLAYER_NEUTRAL_PASSIVE + 1]
|
|
254
256
|
Player.neutralAggressive = ____exports.Player.all[PLAYER_NEUTRAL_AGGRESSIVE + 1]
|
|
255
257
|
Player.neutralVictim = ____exports.Player.all[bj_PLAYER_NEUTRAL_VICTIM + 1]
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** @noSelfInFile */
|
|
2
|
+
import type { Unit } from "../../engine/internal/unit";
|
|
2
3
|
export declare class PlayerCamera {
|
|
3
4
|
private readonly player;
|
|
4
5
|
private readonly isLocal;
|
|
@@ -28,5 +29,6 @@ export declare class PlayerCamera {
|
|
|
28
29
|
get roll(): number;
|
|
29
30
|
set roll(v: number);
|
|
30
31
|
reset(): void;
|
|
32
|
+
static isUnitInView(unit: Unit): boolean;
|
|
31
33
|
static of(player: jplayer): PlayerCamera;
|
|
32
34
|
}
|
|
@@ -3,33 +3,49 @@ local __TS__Class = ____lualib.__TS__Class
|
|
|
3
3
|
local __TS__New = ____lualib.__TS__New
|
|
4
4
|
local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
|
|
5
5
|
local ____exports = {}
|
|
6
|
+
local ____timer = require("core.types.timer")
|
|
7
|
+
local Timer = ____timer.Timer
|
|
8
|
+
local ____player_2Dlocal_2Dhandle = require("engine.internal.misc.player-local-handle")
|
|
9
|
+
local PLAYER_LOCAL_HANDLE = ____player_2Dlocal_2Dhandle.PLAYER_LOCAL_HANDLE
|
|
10
|
+
local ____preconditions = require("utility.preconditions")
|
|
11
|
+
local check = ____preconditions.check
|
|
12
|
+
local ____frame_2Dcoordinates = require("engine.internal.misc.frame-coordinates")
|
|
13
|
+
local FRAME_MAX_Y = ____frame_2Dcoordinates.FRAME_MAX_Y
|
|
14
|
+
local FRAME_MIN_Y = ____frame_2Dcoordinates.FRAME_MIN_Y
|
|
15
|
+
local getFrameMinXMaxX = ____frame_2Dcoordinates.getFrameMinXMaxX
|
|
6
16
|
local getHandleId = GetHandleId
|
|
7
17
|
local setCameraField = SetCameraField
|
|
8
18
|
local getCameraField = GetCameraField
|
|
9
19
|
local setCameraPosition = SetCameraPosition
|
|
20
|
+
local getCameraEyePositionX = GetCameraEyePositionX
|
|
21
|
+
local getCameraEyePositionY = GetCameraEyePositionY
|
|
22
|
+
local getCameraEyePositionZ = GetCameraEyePositionZ
|
|
10
23
|
local getCameraTargetPositionX = GetCameraTargetPositionX
|
|
11
24
|
local getCameraTargetPositionY = GetCameraTargetPositionY
|
|
12
25
|
local resetToGameCamera = ResetToGameCamera
|
|
26
|
+
local cos = math.cos
|
|
13
27
|
local deg = math.deg
|
|
14
|
-
local
|
|
28
|
+
local sin = math.sin
|
|
15
29
|
local memoized = {}
|
|
16
30
|
____exports.PlayerCamera = __TS__Class()
|
|
17
31
|
local PlayerCamera = ____exports.PlayerCamera
|
|
18
32
|
PlayerCamera.name = "PlayerCamera"
|
|
19
33
|
function PlayerCamera.prototype.____constructor(self, player)
|
|
20
34
|
local id = getHandleId(player)
|
|
21
|
-
|
|
22
|
-
error("Double-constructor run player camera!")
|
|
23
|
-
end
|
|
35
|
+
check(memoized[id] == nil)
|
|
24
36
|
memoized[id] = self
|
|
25
37
|
self.player = player
|
|
26
|
-
self.isLocal = player ==
|
|
38
|
+
self.isLocal = player == PLAYER_LOCAL_HANDLE
|
|
27
39
|
end
|
|
28
40
|
function PlayerCamera.prototype.reset(self)
|
|
29
41
|
if self.isLocal then
|
|
30
42
|
resetToGameCamera(0)
|
|
31
43
|
end
|
|
32
44
|
end
|
|
45
|
+
function PlayerCamera.isUnitInView(self, unit)
|
|
46
|
+
local ____, ____, isInView = ____exports.worldCoordinatesToFrame(unit.x, unit.y, unit.z)
|
|
47
|
+
return isInView
|
|
48
|
+
end
|
|
33
49
|
function PlayerCamera.of(self, player)
|
|
34
50
|
return memoized[getHandleId(player)] or __TS__New(____exports.PlayerCamera, player)
|
|
35
51
|
end
|
|
@@ -159,4 +175,62 @@ __TS__SetDescriptor(
|
|
|
159
175
|
},
|
|
160
176
|
true
|
|
161
177
|
)
|
|
178
|
+
local cameraEyeX = 0
|
|
179
|
+
local cameraEyeY = 0
|
|
180
|
+
local cameraEyeZ = 0
|
|
181
|
+
local cameraAngleOfAttack = 0
|
|
182
|
+
local cameraAngleOfAttackCos = 0
|
|
183
|
+
local cameraAngleOfAttackSin = 0
|
|
184
|
+
local cameraRotation = 0
|
|
185
|
+
local cameraRotationCos = 0
|
|
186
|
+
local cameraRotationSin = 0
|
|
187
|
+
local cameraAngleOfAttackCosRotationCos = 0
|
|
188
|
+
local cameraAngleOfAttackCosRotationSin = 0
|
|
189
|
+
local cameraAngleOfAttackSinRotationCos = 0
|
|
190
|
+
local cameraAngleOfAttackSinRotationSin = 0
|
|
191
|
+
local yCenterScreenShift = 0
|
|
192
|
+
local scaleFactor = 0
|
|
193
|
+
local frameMinX = 0
|
|
194
|
+
local frameMaxX = 0
|
|
195
|
+
local isCameraViewPrecalculated = false
|
|
196
|
+
local function precalculateCameraView()
|
|
197
|
+
cameraEyeX = getCameraEyePositionX()
|
|
198
|
+
cameraEyeY = getCameraEyePositionY()
|
|
199
|
+
cameraEyeZ = getCameraEyePositionZ()
|
|
200
|
+
cameraAngleOfAttack = getCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK)
|
|
201
|
+
cameraAngleOfAttackCos = cos(cameraAngleOfAttack)
|
|
202
|
+
cameraAngleOfAttackSin = sin(cameraAngleOfAttack)
|
|
203
|
+
cameraRotation = getCameraField(CAMERA_FIELD_ROTATION)
|
|
204
|
+
cameraRotationCos = cos(cameraRotation)
|
|
205
|
+
cameraRotationSin = sin(cameraRotation)
|
|
206
|
+
cameraAngleOfAttackCosRotationCos = cameraAngleOfAttackCos * cameraRotationCos
|
|
207
|
+
cameraAngleOfAttackCosRotationSin = cameraAngleOfAttackCos * cameraRotationSin
|
|
208
|
+
cameraAngleOfAttackSinRotationCos = cameraAngleOfAttackSin * cameraRotationCos
|
|
209
|
+
cameraAngleOfAttackSinRotationSin = cameraAngleOfAttackSin * cameraRotationSin
|
|
210
|
+
yCenterScreenShift = 0.1284 * cameraAngleOfAttackCos
|
|
211
|
+
local cameraFieldOfView = getCameraField(CAMERA_FIELD_FIELD_OF_VIEW)
|
|
212
|
+
scaleFactor = 0.0524 * cameraFieldOfView ^ 3 - 0.0283 * cameraFieldOfView ^ 2 + 1.061 * cameraFieldOfView
|
|
213
|
+
frameMinX, frameMaxX = getFrameMinXMaxX()
|
|
214
|
+
isCameraViewPrecalculated = true
|
|
215
|
+
end
|
|
216
|
+
Timer.onPeriod[1 / 64]:addListener(
|
|
217
|
+
4,
|
|
218
|
+
function()
|
|
219
|
+
isCameraViewPrecalculated = false
|
|
220
|
+
end
|
|
221
|
+
)
|
|
222
|
+
---
|
|
223
|
+
-- @internal For use by internal systems only.
|
|
224
|
+
____exports.worldCoordinatesToFrame = function(x, y, z)
|
|
225
|
+
if not isCameraViewPrecalculated then
|
|
226
|
+
precalculateCameraView()
|
|
227
|
+
end
|
|
228
|
+
local dx = x - cameraEyeX
|
|
229
|
+
local dy = y - cameraEyeY
|
|
230
|
+
local dz = z - cameraEyeZ
|
|
231
|
+
local xPrime = scaleFactor * (-cameraAngleOfAttackCosRotationCos * dx - cameraAngleOfAttackCosRotationSin * dy - cameraAngleOfAttackSin * dz)
|
|
232
|
+
local frameX = 0.4 + (cameraRotationCos * dy - cameraRotationSin * dx) / xPrime
|
|
233
|
+
local frameY = 0.42625 - yCenterScreenShift + (cameraAngleOfAttackSinRotationCos * dx + cameraAngleOfAttackSinRotationSin * dy - cameraAngleOfAttackCos * dz) / xPrime
|
|
234
|
+
return frameX, frameY, xPrime < 0 and frameX >= frameMinX and frameX <= frameMaxX and frameY >= FRAME_MIN_Y and frameY <= FRAME_MAX_Y
|
|
235
|
+
end
|
|
162
236
|
return ____exports
|
package/core/types/sound.lua
CHANGED
|
@@ -121,6 +121,11 @@ local customSoundPresetDataByLabel = postcompile(function()
|
|
|
121
121
|
end
|
|
122
122
|
return customSoundPresetDataByLabel
|
|
123
123
|
end)
|
|
124
|
+
---
|
|
125
|
+
-- @internal For use by internal systems only.
|
|
126
|
+
____exports.isSoundLabelCustom = function(label)
|
|
127
|
+
return customSoundPresetDataByLabel[label] ~= nil
|
|
128
|
+
end
|
|
124
129
|
local function createPresetSound(fileName, preset)
|
|
125
130
|
local ____fileName_1 = fileName
|
|
126
131
|
local ____preset_looping_0 = preset.looping
|
package/core/types/timer.d.ts
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
/** @noSelfInFile */
|
|
2
2
|
import { Event } from "../../event";
|
|
3
|
+
import { AbstractDestroyable, Destructor } from "../../destroyable";
|
|
3
4
|
declare const enum TimerPropertyKey {
|
|
4
5
|
HANDLE = 0,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
ARGS_LENGTH = 4
|
|
6
|
+
DESTROY_ON_EXPIRATION = 1,
|
|
7
|
+
CALLBACK = 2,
|
|
8
|
+
ARGS_LENGTH = 3
|
|
9
9
|
}
|
|
10
|
-
export declare class Timer
|
|
10
|
+
export declare class Timer extends AbstractDestroyable {
|
|
11
11
|
private readonly [TimerPropertyKey.HANDLE];
|
|
12
|
-
private [TimerPropertyKey.DESTROYED]?;
|
|
13
12
|
private [TimerPropertyKey.DESTROY_ON_EXPIRATION]?;
|
|
14
13
|
private [TimerPropertyKey.CALLBACK]?;
|
|
15
14
|
private [TimerPropertyKey.ARGS_LENGTH]?;
|
|
16
15
|
private constructor();
|
|
17
16
|
get handle(): jtimer;
|
|
18
17
|
start<Args extends any[]>(timeout: number, periodic: boolean, callback: (...args: Args) => void, ...args: Args): void;
|
|
18
|
+
onDestroy(): Destructor;
|
|
19
19
|
get elapsed(): number;
|
|
20
20
|
get remaining(): number;
|
|
21
21
|
get timeout(): number;
|
|
22
22
|
pause(): void;
|
|
23
23
|
resume(): void;
|
|
24
|
-
destroy(): void;
|
|
25
24
|
static create(): Timer;
|
|
26
|
-
static run<
|
|
25
|
+
static run<T, K extends KeysOfType<T, (this: T, ...args: any) => any>>(object: T, key: K, ...parameters: T[K] extends (this: T, ...args: any) => any ? Parameters<T[K]> : never): void;
|
|
26
|
+
static run<Args extends any[]>(callback: (this: void, ...args: Args) => void, ...args: Args): void;
|
|
27
27
|
static simple<Args extends any[]>(timeout: number, callback: (...args: Args) => void, ...args: Args): Timer;
|
|
28
28
|
static periodic<Args extends any[]>(period: number, callback: (this: void, timer: Timer, ...args: Args) => void, ...args: Args): Timer;
|
|
29
29
|
static counted(period: number, count: number, callback: (this: void, timer: Timer) => void): Timer;
|
package/core/types/timer.lua
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
local ____lualib = require("lualib_bundle")
|
|
2
2
|
local __TS__New = ____lualib.__TS__New
|
|
3
3
|
local __TS__Class = ____lualib.__TS__Class
|
|
4
|
+
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
|
|
4
5
|
local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
|
|
5
6
|
local __TS__Promise = ____lualib.__TS__Promise
|
|
6
7
|
local ____exports = {}
|
|
@@ -9,8 +10,8 @@ local Event = ____event.Event
|
|
|
9
10
|
local InitializingEvent = ____event.InitializingEvent
|
|
10
11
|
local ____objectPool = require("util.objectPool")
|
|
11
12
|
local ObjectPool = ____objectPool.ObjectPool
|
|
12
|
-
local
|
|
13
|
-
local
|
|
13
|
+
local ____destroyable = require("destroyable")
|
|
14
|
+
local AbstractDestroyable = ____destroyable.AbstractDestroyable
|
|
14
15
|
local createTimer = CreateTimer
|
|
15
16
|
local timerStart = TimerStart
|
|
16
17
|
local pauseTimer = PauseTimer
|
|
@@ -23,6 +24,7 @@ local getHandleId = GetHandleId
|
|
|
23
24
|
local ____pcall = _G.pcall
|
|
24
25
|
local ____print = _G.print
|
|
25
26
|
local select = _G.select
|
|
27
|
+
local ____type = _G.type
|
|
26
28
|
local safeCall = warpack.safeCall
|
|
27
29
|
local corunning = coroutine.running
|
|
28
30
|
local coresume = coroutine.resume
|
|
@@ -35,14 +37,14 @@ local timerByHandleId = {}
|
|
|
35
37
|
local function timerSafeCall()
|
|
36
38
|
local timer = timerByHandleId[getHandleId(getExpiredTimer())]
|
|
37
39
|
if timer ~= nil then
|
|
38
|
-
if timer[
|
|
40
|
+
if timer[1] then
|
|
39
41
|
timer:destroy()
|
|
40
42
|
end
|
|
41
|
-
local callback = timer[
|
|
43
|
+
local callback = timer[2]
|
|
42
44
|
if callback ~= nil then
|
|
43
45
|
safeCall(
|
|
44
46
|
callback,
|
|
45
|
-
____unpack(timer,
|
|
47
|
+
____unpack(timer, 3 + 1, 3 + (timer[3] or 0))
|
|
46
48
|
)
|
|
47
49
|
end
|
|
48
50
|
end
|
|
@@ -50,46 +52,46 @@ end
|
|
|
50
52
|
____exports.Timer = __TS__Class()
|
|
51
53
|
local Timer = ____exports.Timer
|
|
52
54
|
Timer.name = "Timer"
|
|
55
|
+
__TS__ClassExtends(Timer, AbstractDestroyable)
|
|
53
56
|
function Timer.prototype.____constructor(self)
|
|
57
|
+
AbstractDestroyable.prototype.____constructor(self)
|
|
54
58
|
self[0] = get()
|
|
55
59
|
timerByHandleId[getHandleId(self[0])] = self
|
|
56
60
|
end
|
|
57
61
|
function Timer.prototype.start(self, timeout, periodic, callback, ...)
|
|
58
|
-
self[
|
|
62
|
+
self[2] = callback
|
|
59
63
|
local argsLength = select("#", ...)
|
|
60
|
-
self[
|
|
64
|
+
self[3] = argsLength
|
|
61
65
|
for i = 1, argsLength do
|
|
62
|
-
self[
|
|
66
|
+
self[3 + i] = (select(i, ...))
|
|
63
67
|
end
|
|
64
68
|
timerStart(self.handle, timeout, periodic, timerSafeCall)
|
|
65
69
|
end
|
|
70
|
+
function Timer.prototype.onDestroy(self)
|
|
71
|
+
local handle = self[0]
|
|
72
|
+
timerByHandleId[getHandleId(handle)] = nil
|
|
73
|
+
release(handle)
|
|
74
|
+
return AbstractDestroyable.prototype.onDestroy(self)
|
|
75
|
+
end
|
|
66
76
|
function Timer.prototype.pause(self)
|
|
67
77
|
pauseTimer(self[0])
|
|
68
78
|
end
|
|
69
79
|
function Timer.prototype.resume(self)
|
|
70
80
|
resumeTimer(self[0])
|
|
71
81
|
end
|
|
72
|
-
function Timer.prototype.destroy(self)
|
|
73
|
-
if self[1] then
|
|
74
|
-
error(
|
|
75
|
-
__TS__New(IllegalStateException, "Double-destroy run for timer"),
|
|
76
|
-
0
|
|
77
|
-
)
|
|
78
|
-
end
|
|
79
|
-
local handle = self[0]
|
|
80
|
-
timerByHandleId[getHandleId(handle)] = nil
|
|
81
|
-
release(handle)
|
|
82
|
-
self[1] = true
|
|
83
|
-
end
|
|
84
82
|
function Timer.create(self)
|
|
85
83
|
return __TS__New(____exports.Timer)
|
|
86
84
|
end
|
|
87
|
-
function Timer.run(self,
|
|
88
|
-
|
|
85
|
+
function Timer.run(self, objectOrCallback, keyOrFirstArg, ...)
|
|
86
|
+
if ____type(objectOrCallback) == "function" then
|
|
87
|
+
____exports.Timer:simple(0, objectOrCallback, keyOrFirstArg, ...)
|
|
88
|
+
else
|
|
89
|
+
____exports.Timer:simple(0, objectOrCallback[keyOrFirstArg], objectOrCallback, ...)
|
|
90
|
+
end
|
|
89
91
|
end
|
|
90
92
|
function Timer.simple(self, timeout, callback, ...)
|
|
91
93
|
local timer = __TS__New(____exports.Timer)
|
|
92
|
-
timer[
|
|
94
|
+
timer[1] = true
|
|
93
95
|
timer:start(timeout, false, callback, ...)
|
|
94
96
|
return timer
|
|
95
97
|
end
|