warscript 0.0.1-dev.311b554 → 0.0.1-dev.3370e98

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 (37) hide show
  1. package/core/types/frame.lua +10 -12
  2. package/core/types/player.lua +3 -1
  3. package/core/types/playerCamera.d.ts +2 -0
  4. package/core/types/playerCamera.lua +79 -5
  5. package/core/types/timer.d.ts +1 -0
  6. package/core/types/timer.lua +7 -2
  7. package/decl/native.d.ts +4 -2
  8. package/engine/behavior.d.ts +2 -0
  9. package/engine/behavior.lua +53 -27
  10. package/engine/behaviour/ability/emulate-impact.d.ts +1 -1
  11. package/engine/behaviour/ability/emulate-impact.lua +2 -1
  12. package/engine/behaviour/ability/restore-mana.d.ts +1 -1
  13. package/engine/behaviour/ability/restore-mana.lua +6 -6
  14. package/engine/internal/ability.lua +1 -1
  15. package/engine/internal/item+owner.lua +12 -6
  16. package/engine/internal/misc/frame-coordinates.d.ts +2 -0
  17. package/engine/internal/misc/frame-coordinates.lua +21 -0
  18. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  19. package/engine/internal/misc/get-terrain-z.lua +11 -0
  20. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  21. package/engine/internal/misc/player-local-handle.lua +5 -0
  22. package/engine/internal/unit+ability.lua +1 -1
  23. package/engine/internal/unit-missile-launch.lua +8 -1
  24. package/engine/internal/unit.d.ts +2 -3
  25. package/engine/internal/unit.lua +9 -5
  26. package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
  27. package/engine/object-data/auxiliary/armor-type.lua +46 -0
  28. package/engine/object-data/entry/ability-type.lua +1 -3
  29. package/engine/object-data/entry/unit-type.d.ts +11 -2
  30. package/engine/object-data/entry/unit-type.lua +59 -1
  31. package/engine/text-tag.d.ts +1 -1
  32. package/engine/text-tag.lua +91 -17
  33. package/package.json +2 -2
  34. package/utility/functions.d.ts +4 -0
  35. package/utility/functions.lua +9 -0
  36. package/utility/lua-sets.d.ts +1 -0
  37. package/utility/lua-sets.lua +4 -0
@@ -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 w = BlzGetLocalClientWidth()
348
- local h = BlzGetLocalClientHeight()
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 w = BlzGetLocalClientWidth()
359
- local h = BlzGetLocalClientHeight()
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 = 0
367
- Frame.maxY = 0.6
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,
@@ -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(GetLocalPlayer())
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 localPlayer = GetLocalPlayer()
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
- if memoized[id] then
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 == localPlayer
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
@@ -22,6 +22,7 @@ export declare class Timer extends AbstractDestroyable {
22
22
  pause(): void;
23
23
  resume(): void;
24
24
  static create(): Timer;
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;
25
26
  static run<Args extends any[]>(callback: (this: void, ...args: Args) => void, ...args: Args): void;
26
27
  static simple<Args extends any[]>(timeout: number, callback: (...args: Args) => void, ...args: Args): Timer;
27
28
  static periodic<Args extends any[]>(period: number, callback: (this: void, timer: Timer, ...args: Args) => void, ...args: Args): Timer;
@@ -24,6 +24,7 @@ local getHandleId = GetHandleId
24
24
  local ____pcall = _G.pcall
25
25
  local ____print = _G.print
26
26
  local select = _G.select
27
+ local ____type = _G.type
27
28
  local safeCall = warpack.safeCall
28
29
  local corunning = coroutine.running
29
30
  local coresume = coroutine.resume
@@ -81,8 +82,12 @@ end
81
82
  function Timer.create(self)
82
83
  return __TS__New(____exports.Timer)
83
84
  end
84
- function Timer.run(self, callback, ...)
85
- ____exports.Timer:simple(0, callback, ...)
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
86
91
  end
87
92
  function Timer.simple(self, timeout, callback, ...)
88
93
  local timer = __TS__New(____exports.Timer)
package/decl/native.d.ts CHANGED
@@ -388,13 +388,15 @@ declare interface jmovetype extends jhandle {
388
388
  declare interface jtargetflag extends jhandle {
389
389
  __jtargetflag: never
390
390
  }
391
- declare interface jarmortype extends jhandle {
391
+ declare type jarmortype = symbol &
392
+ jhandle & {
392
393
  __jarmortype: never
393
394
  }
394
395
  declare interface jheroattribute extends jhandle {
395
396
  __jheroattribute: never
396
397
  }
397
- declare interface jdefensetype extends jhandle {
398
+ declare type jdefensetype = symbol &
399
+ jhandle & {
398
400
  __jdefensetype: never
399
401
  }
400
402
  declare interface jregentype extends jhandle {
@@ -24,5 +24,7 @@ export declare abstract class Behavior<T extends AnyNotNil, PeriodicActionParame
24
24
  static forFirst<T extends Behavior<AnyNotNil>, ConstructorParameters extends any[], K extends KeysOfType<T, (this: T, ...args: any) => any>>(this: BehaviorConstructor<T, ConstructorParameters>, object: T extends Behavior<infer Object> ? Object : never, count: number, key: K, ...parameters: T[K] extends (this: T, ...args: any) => any ? Parameters<T[K]> : never): number;
25
25
  static forAll<T extends Behavior<AnyNotNil>, ConstructorParameters extends any[], ConsumerParameters extends any[]>(this: BehaviorConstructor<T, ConstructorParameters>, object: T extends Behavior<infer Object> ? Object : never, consumer: (this: void, behavior: T, ...parameters: ConsumerParameters) => unknown, ...parameters: ConsumerParameters): number;
26
26
  static forAll<T extends Behavior<AnyNotNil>, ConstructorParameters extends any[], K extends KeysOfType<T, (this: T, ...args: any) => any>>(this: BehaviorConstructor<T, ConstructorParameters>, object: T extends Behavior<infer Object> ? Object : never, key: K, ...parameters: T[K] extends (this: T, ...args: any) => any ? Parameters<T[K]> : never): number;
27
+ static reduce<T extends Behavior<AnyNotNil>, ConstructorParameters extends any[], ConsumerParameters extends any[], Accumulator, R>(this: BehaviorConstructor<T, ConstructorParameters>, object: T extends Behavior<infer Object> ? Object : never, operation: (this: void, accumulator: Accumulator, value: R) => Accumulator, initial: Accumulator, consumer: (this: void, behavior: T, ...parameters: ConsumerParameters) => R, ...parameters: ConsumerParameters): Accumulator;
28
+ static reduce<T extends Behavior<AnyNotNil>, ConstructorParameters extends any[], Accumulator, R, K extends KeysOfType<T, (this: T, ...args: any) => R>>(this: BehaviorConstructor<T, ConstructorParameters>, object: T extends Behavior<infer Object> ? Object : never, operation: (this: void, accumulator: Accumulator, value: R) => Accumulator, initial: Accumulator, key: K, ...parameters: T[K] extends (this: T, ...args: any) => R ? Parameters<T[K]> : never): Accumulator;
27
29
  }
28
30
  export {};
@@ -1,18 +1,52 @@
1
1
  local ____lualib = require("lualib_bundle")
2
+ local __TS__InstanceOf = ____lualib.__TS__InstanceOf
2
3
  local __TS__Class = ____lualib.__TS__Class
3
4
  local __TS__ClassExtends = ____lualib.__TS__ClassExtends
4
- local __TS__InstanceOf = ____lualib.__TS__InstanceOf
5
5
  local ____exports = {}
6
6
  local ____destroyable = require("destroyable")
7
7
  local AbstractDestroyable = ____destroyable.AbstractDestroyable
8
8
  local ____timer = require("core.types.timer")
9
9
  local Timer = ____timer.Timer
10
+ local ____functions = require("utility.functions")
11
+ local increment = ____functions.increment
10
12
  local safeCall = warpack.safeCall
11
13
  local firstBehaviorByObject = {}
12
14
  local lastBehaviorByObject = {}
13
15
  local function invokeBehaviorOnPeriod(behavior, ...)
14
16
  behavior.onPeriod(behavior, ...)
15
17
  end
18
+ local function reduceBehaviors(behaviorConstructor, object, operation, initial, consumerOrKey, ...)
19
+ local accumulator = initial
20
+ local behavior = firstBehaviorByObject[object]
21
+ if behavior ~= nil then
22
+ if type(consumerOrKey) == "function" then
23
+ repeat
24
+ do
25
+ if __TS__InstanceOf(behavior, behaviorConstructor) then
26
+ local isSuccessful, result = safeCall(consumerOrKey, behavior, ...)
27
+ if isSuccessful then
28
+ accumulator = operation(accumulator, result)
29
+ end
30
+ end
31
+ behavior = behavior[1]
32
+ end
33
+ until not (behavior ~= nil)
34
+ else
35
+ repeat
36
+ do
37
+ if __TS__InstanceOf(behavior, behaviorConstructor) then
38
+ local isSuccessful, result = safeCall(behavior[consumerOrKey], behavior, ...)
39
+ if isSuccessful then
40
+ accumulator = operation(accumulator, result)
41
+ end
42
+ end
43
+ behavior = behavior[1]
44
+ end
45
+ until not (behavior ~= nil)
46
+ end
47
+ end
48
+ return accumulator
49
+ end
16
50
  ____exports.Behavior = __TS__Class()
17
51
  local Behavior = ____exports.Behavior
18
52
  Behavior.name = "Behavior"
@@ -151,31 +185,23 @@ function Behavior.forFirst(self, object, count, consumerOrKey, ...)
151
185
  return behaviorsCount
152
186
  end
153
187
  function Behavior.forAll(self, object, consumerOrKey, ...)
154
- local behaviorsCount = 0
155
- local behavior = firstBehaviorByObject[object]
156
- if behavior ~= nil then
157
- if type(consumerOrKey) == "function" then
158
- repeat
159
- do
160
- if __TS__InstanceOf(behavior, self) then
161
- safeCall(consumerOrKey, behavior, ...)
162
- behaviorsCount = behaviorsCount + 1
163
- end
164
- behavior = behavior[1]
165
- end
166
- until not (behavior ~= nil)
167
- else
168
- repeat
169
- do
170
- if __TS__InstanceOf(behavior, self) then
171
- safeCall(behavior[consumerOrKey], behavior, ...)
172
- behaviorsCount = behaviorsCount + 1
173
- end
174
- behavior = behavior[1]
175
- end
176
- until not (behavior ~= nil)
177
- end
178
- end
179
- return behaviorsCount
188
+ return reduceBehaviors(
189
+ self,
190
+ object,
191
+ increment,
192
+ 0,
193
+ consumerOrKey,
194
+ ...
195
+ )
196
+ end
197
+ function Behavior.reduce(self, object, operation, initial, consumerOrKey, ...)
198
+ return reduceBehaviors(
199
+ self,
200
+ object,
201
+ operation,
202
+ initial,
203
+ consumerOrKey,
204
+ ...
205
+ )
180
206
  end
181
207
  return ____exports
@@ -2,5 +2,5 @@
2
2
  import { AbilityBehavior } from "../ability";
3
3
  import { Unit } from "../../internal/unit";
4
4
  export declare abstract class EmulateImpactAbilityBehavior extends AbilityBehavior {
5
- protected emulateImpact(caster: Unit): void;
5
+ protected emulateImpact(caster: Unit): boolean;
6
6
  }
@@ -28,7 +28,7 @@ function EmulateImpactAbilityBehavior.prototype.emulateImpact(self, caster)
28
28
  local manaCost = self:resolveCurrentAbilityDependentValue(MANA_COST_ABILITY_INTEGER_LEVEL_FIELD)
29
29
  local cooldown = self:resolveCurrentAbilityDependentValue(COOLDOWN_ABILITY_FLOAT_LEVEL_FIELD)
30
30
  if self.ability.cooldownRemaining ~= 0 or caster.mana < manaCost or __TS__InstanceOf(self.ability, UnitAbility) and self.ability.isDisabled then
31
- return
31
+ return false
32
32
  end
33
33
  caster.mana = caster.mana - manaCost
34
34
  self.ability.cooldownRemaining = max(cooldown, MINIMUM_POSITIVE_NORMALIZED_FLOAT)
@@ -38,5 +38,6 @@ function EmulateImpactAbilityBehavior.prototype.emulateImpact(self, caster)
38
38
  Sound3D:playFromLabel(soundPresetId, SoundSettings.Ability, caster)
39
39
  end
40
40
  Event.invoke(Unit.abilityImpactEvent, caster, self.ability)
41
+ return true
41
42
  end
42
43
  return ____exports
@@ -8,7 +8,7 @@ export declare class RestoreManaSelfAbilityBehavior extends AbilityBehavior {
8
8
  constructor(ability: Ability, mana: AbilityDependentValue<number>);
9
9
  onImpact(caster: Unit): void;
10
10
  }
11
- export declare class RestoreManaAbilityBehavior extends AbilityBehavior {
11
+ export declare class RestoreManaTargetAbilityBehavior extends AbilityBehavior {
12
12
  private readonly mana;
13
13
  constructor(ability: Ability, mana: AbilityDependentValue<number>);
14
14
  onUnitTargetImpact(caster: Unit, target: Unit): void;
@@ -15,15 +15,15 @@ end
15
15
  function RestoreManaSelfAbilityBehavior.prototype.onImpact(self, caster)
16
16
  caster.mana = caster.mana + self:resolveCurrentAbilityDependentValue(self.mana)
17
17
  end
18
- ____exports.RestoreManaAbilityBehavior = __TS__Class()
19
- local RestoreManaAbilityBehavior = ____exports.RestoreManaAbilityBehavior
20
- RestoreManaAbilityBehavior.name = "RestoreManaAbilityBehavior"
21
- __TS__ClassExtends(RestoreManaAbilityBehavior, AbilityBehavior)
22
- function RestoreManaAbilityBehavior.prototype.____constructor(self, ability, mana)
18
+ ____exports.RestoreManaTargetAbilityBehavior = __TS__Class()
19
+ local RestoreManaTargetAbilityBehavior = ____exports.RestoreManaTargetAbilityBehavior
20
+ RestoreManaTargetAbilityBehavior.name = "RestoreManaTargetAbilityBehavior"
21
+ __TS__ClassExtends(RestoreManaTargetAbilityBehavior, AbilityBehavior)
22
+ function RestoreManaTargetAbilityBehavior.prototype.____constructor(self, ability, mana)
23
23
  AbilityBehavior.prototype.____constructor(self, ability)
24
24
  self.mana = mana
25
25
  end
26
- function RestoreManaAbilityBehavior.prototype.onUnitTargetImpact(self, caster, target)
26
+ function RestoreManaTargetAbilityBehavior.prototype.onUnitTargetImpact(self, caster, target)
27
27
  target.mana = target.mana + self:resolveCurrentAbilityDependentValue(self.mana)
28
28
  end
29
29
  return ____exports
@@ -406,8 +406,8 @@ end
406
406
  function UnitAbility.prototype.incrementDisableCounter(self)
407
407
  local unit = self.u
408
408
  local typeId = self.typeId
409
- unitDisableAbility(unit, typeId, true, false)
410
409
  unitHideAbility(unit, typeId, true)
410
+ unitDisableAbility(unit, typeId, true, false)
411
411
  self.d = (self.d or 0) + 1
412
412
  end
413
413
  function UnitAbility.prototype.decrementDisableCounter(self)
@@ -6,12 +6,18 @@ local Item = ____item.Item
6
6
  local ____unit = require("engine.internal.unit")
7
7
  local Unit = ____unit.Unit
8
8
  local ownerByItem = setmetatable({}, {__mode = "kv"})
9
- Unit.itemPickedUpEvent:addListener(function(unit, item)
10
- ownerByItem[item] = unit
11
- end)
12
- Unit.itemDroppedEvent:addListener(function(unit, item)
13
- ownerByItem[item] = nil
14
- end)
9
+ Unit.itemPickedUpEvent:addListener(
10
+ 4,
11
+ function(unit, item)
12
+ ownerByItem[item] = unit
13
+ end
14
+ )
15
+ Unit.itemDroppedEvent:addListener(
16
+ 4,
17
+ function(unit, item)
18
+ ownerByItem[item] = nil
19
+ end
20
+ )
15
21
  __TS__ObjectDefineProperty(
16
22
  Item.prototype,
17
23
  "owner",
@@ -0,0 +1,2 @@
1
+ /** @noSelfInFile */
2
+ export {};
@@ -0,0 +1,21 @@
1
+ local ____exports = {}
2
+ local getLocalClientWidth = BlzGetLocalClientWidth
3
+ local getLocalClientHeight = BlzGetLocalClientHeight
4
+ ---
5
+ -- @internal For use by internal systems only.
6
+ ____exports.getFrameMinXMaxX = function()
7
+ local w = getLocalClientWidth()
8
+ local h = getLocalClientHeight()
9
+ local width4by3 = (w - h / 600 * 800) / 2
10
+ local pxtodpi = 0.6 / h
11
+ local minX = -width4by3 * pxtodpi
12
+ local maxX = minX + w * pxtodpi
13
+ return minX, maxX
14
+ end
15
+ ---
16
+ -- @internal For use by internal systems only.
17
+ ____exports.FRAME_MIN_Y = 0
18
+ ---
19
+ -- @internal For use by internal systems only.
20
+ ____exports.FRAME_MAX_Y = 0.6
21
+ return ____exports
@@ -0,0 +1,2 @@
1
+ /** @noSelfInFile */
2
+ export {};
@@ -0,0 +1,11 @@
1
+ local ____exports = {}
2
+ local getLocationZ = GetLocationZ
3
+ local moveLocation = MoveLocation
4
+ local location = Location(0, 0)
5
+ ---
6
+ -- @internal For use by internal systems only.
7
+ ____exports.getTerrainZ = function(x, y)
8
+ moveLocation(location, x, y)
9
+ return getLocationZ(location)
10
+ end
11
+ return ____exports
@@ -0,0 +1,2 @@
1
+ /** @noSelfInFile */
2
+ export {};
@@ -0,0 +1,5 @@
1
+ local ____exports = {}
2
+ ---
3
+ -- @internal For use by internal systems only.
4
+ ____exports.PLAYER_LOCAL_HANDLE = GetLocalPlayer()
5
+ return ____exports
@@ -7,8 +7,8 @@ local UnitAbility = ____ability.UnitAbility
7
7
  local ____unit = require("engine.internal.unit")
8
8
  local Unit = ____unit.Unit
9
9
  local ____event = require("event")
10
- local Event = ____event.Event
11
10
  local createDispatchingEvent = ____event.createDispatchingEvent
11
+ local Event = ____event.Event
12
12
  local abilityGainedEvent = createDispatchingEvent(
13
13
  __TS__New(Event),
14
14
  function(unit, ability) return ability.typeId end
@@ -9,6 +9,8 @@ local ____timer = require("core.types.timer")
9
9
  local Timer = ____timer.Timer
10
10
  local ____lua_2Dsets = require("utility.lua-sets")
11
11
  local luaSetOf = ____lua_2Dsets.luaSetOf
12
+ local ____math = require("math")
13
+ local min = ____math.min
12
14
  local autoAttackFinishEvent = __TS__New(Event)
13
15
  rawset(Unit, "autoAttackFinishEvent", autoAttackFinishEvent)
14
16
  local eventTimerByUnit = {}
@@ -45,7 +47,12 @@ local function timerCallback(source, target)
45
47
  end
46
48
  Unit.autoAttackStartEvent:addListener(function(source, target)
47
49
  local attackPoint = (source:chooseWeapon(target) or source.firstWeapon).impactDelay
48
- local timer = Timer:simple(attackPoint, timerCallback, source, target)
50
+ local timer = Timer:simple(
51
+ attackPoint + min(0.001, attackPoint / 2),
52
+ timerCallback,
53
+ source,
54
+ target
55
+ )
49
56
  eventTimerByUnit[source] = timer
50
57
  end)
51
58
  return ____exports
@@ -160,8 +160,7 @@ export declare class Unit extends Handle<junit> {
160
160
  isInRangeOf(unit: Unit, range: number): boolean;
161
161
  isAllyOf(unit: Unit): boolean;
162
162
  isEnemyOf(unit: Unit): boolean;
163
- playAnimation(animation: string, rarity?: jraritycontrol): void;
164
- playAnimation(animation: number): void;
163
+ playAnimation(...parameters: [animation: number] | [animation: string, rarity?: jraritycontrol]): void;
165
164
  resetAnimation(): void;
166
165
  queueAnimation(animation: string): void;
167
166
  get weapons(): [UnitWeapon, UnitWeapon];
@@ -354,7 +353,7 @@ export declare class Unit extends Handle<junit> {
354
353
  static itemDroppedEvent: UnitTriggerEvent<[Item]>;
355
354
  static itemPickedUpEvent: UnitTriggerEvent<[Item]>;
356
355
  static itemUsedEvent: UnitTriggerEvent<[Item]>;
357
- static itemStackedEvent: UnitTriggerEvent<[Item]>;
356
+ static itemStackedEvent: UnitTriggerEvent<[source: Item, target: Item]>;
358
357
  static get itemChargesChangedEvent(): Event<[unit: Unit, item: Item]>;
359
358
  static get itemUseOrderEvent(): Event<[unit: Unit, item: Item]>;
360
359
  static get itemMoveOrderEvent(): Event<[
@@ -2670,10 +2670,14 @@ Unit.itemPickedUpEvent = __TS__New(
2670
2670
  ____exports.UnitTriggerEvent,
2671
2671
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2672
2672
  function()
2673
- local unit = getTriggerUnit()
2674
- local item = getManipulatedItem()
2675
- if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2676
- return ____exports.Unit:of(unit), Item:of(item)
2673
+ local unitHandle = getTriggerUnit()
2674
+ local itemHandle = getManipulatedItem()
2675
+ if getUnitTypeId(unitHandle) ~= dummyUnitId and not (ignoreEventsItems[itemHandle] ~= nil) then
2676
+ local unit = ____exports.Unit:of(unitHandle)
2677
+ local item = Item:of(itemHandle)
2678
+ if item.owner ~= unit then
2679
+ return unit, item
2680
+ end
2677
2681
  end
2678
2682
  return IgnoreEvent
2679
2683
  end
@@ -2693,7 +2697,7 @@ Unit.itemUsedEvent = __TS__New(
2693
2697
  Unit.itemStackedEvent = __TS__New(
2694
2698
  ____exports.UnitTriggerEvent,
2695
2699
  EVENT_PLAYER_UNIT_STACK_ITEM,
2696
- function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2700
+ function() return ____exports.Unit:of(getTriggerUnit()), Item:of(BlzGetStackingItemSource()), Item:of(BlzGetStackingItemTarget()) end
2697
2701
  )
2698
2702
  __TS__ObjectDefineProperty(
2699
2703
  Unit,
@@ -0,0 +1,11 @@
1
+ /** @noSelfInFile */
2
+ export declare const enum ArmorType {
3
+ LIGHT = 0,
4
+ MEDIUM = 1,
5
+ HEAVY = 2,
6
+ FORTIFIED = 3,
7
+ NORMAL = 4,
8
+ HERO = 5,
9
+ DIVINE = 6,
10
+ UNARMORED = 7
11
+ }
@@ -0,0 +1,46 @@
1
+ local ____exports = {}
2
+ local ____records = require("utility.records")
3
+ local invertRecord = ____records.invertRecord
4
+ local stringByArmorType = {
5
+ [0] = "small",
6
+ [1] = "medium",
7
+ [2] = "large",
8
+ [3] = "fort",
9
+ [4] = "normal",
10
+ [5] = "hero",
11
+ [6] = "divine",
12
+ [7] = "none"
13
+ }
14
+ local armorTypeByString = invertRecord(stringByArmorType)
15
+ local nativeByArmorType = {
16
+ [0] = DEFENSE_TYPE_LIGHT,
17
+ [1] = DEFENSE_TYPE_MEDIUM,
18
+ [2] = DEFENSE_TYPE_LARGE,
19
+ [3] = DEFENSE_TYPE_FORT,
20
+ [4] = DEFENSE_TYPE_NORMAL,
21
+ [5] = DEFENSE_TYPE_HERO,
22
+ [6] = DEFENSE_TYPE_DIVINE,
23
+ [7] = DEFENSE_TYPE_NONE
24
+ }
25
+ local armorTypeByNative = invertRecord(nativeByArmorType)
26
+ ---
27
+ -- @internal For use by internal systems only.
28
+ ____exports.armorTypeToString = function(armorType)
29
+ return stringByArmorType[armorType]
30
+ end
31
+ ---
32
+ -- @internal For use by internal systems only.
33
+ ____exports.stringToArmorType = function(____string)
34
+ return armorTypeByString[____string] or 7
35
+ end
36
+ ---
37
+ -- @internal For use by internal systems only.
38
+ ____exports.armorTypeToNative = function(armorType)
39
+ return nativeByArmorType[armorType]
40
+ end
41
+ ---
42
+ -- @internal For use by internal systems only.
43
+ ____exports.nativeToArmorType = function(armorType)
44
+ return armorTypeByNative[armorType]
45
+ end
46
+ return ____exports
@@ -979,9 +979,7 @@ for abilityTypeId, animationFQN in pairs(postcompile(function() return castAnima
979
979
  4,
980
980
  function(caster, ability)
981
981
  if ability:getField(ABILITY_RLF_CASTING_TIME) ~= 0 then
982
- Timer:run(function()
983
- caster:playAnimation(animationFQN)
984
- end)
982
+ Timer:run(caster, "playAnimation", animationFQN)
985
983
  end
986
984
  end
987
985
  )
@@ -13,6 +13,7 @@ import type { AbilityTypeId } from "./ability-type";
13
13
  import type { UpgradeId } from "./upgrade";
14
14
  import { AnimationQualifier } from "../auxiliary/animation-qualifier";
15
15
  import { AttackType } from "../auxiliary/attack-type";
16
+ import { ArmorType } from "../auxiliary/armor-type";
16
17
  export type UnitTypeId = ObjectDataEntryId & number & {
17
18
  readonly __unitTypeId: unique symbol;
18
19
  };
@@ -144,6 +145,8 @@ export declare abstract class UnitType<Id extends UnitTypeId = UnitTypeId> exten
144
145
  set runSpeedSD(runSpeedSD: number);
145
146
  get runSpeedHD(): number;
146
147
  set runSpeedHD(runSpeedHD: number);
148
+ get selectionCircleHeight(): number;
149
+ set selectionCircleHeight(height: number);
147
150
  get selectionCircleScale(): number;
148
151
  set selectionCircleScale(selectionCircleScale: number);
149
152
  get selectionCircleScaleSD(): number;
@@ -182,16 +185,20 @@ export declare abstract class UnitType<Id extends UnitTypeId = UnitTypeId> exten
182
185
  set walkSpeedSD(walkSpeedSD: number);
183
186
  get walkSpeedHD(): number;
184
187
  set walkSpeedHD(walkSpeedHD: number);
188
+ get armor(): number;
189
+ set armor(armor: number);
185
190
  get armorSoundType(): ArmorSoundType;
186
191
  set armorSoundType(armorSoundType: ArmorSoundType);
187
192
  get armorSoundTypeSD(): ArmorSoundType;
188
193
  set armorSoundTypeSD(armorSoundTypeSD: ArmorSoundType);
189
194
  get armorSoundTypeHD(): ArmorSoundType;
190
195
  set armorSoundTypeHD(armorSoundTypeHD: ArmorSoundType);
196
+ get armorType(): ArmorType;
197
+ set armorType(armorType: ArmorType);
191
198
  get combatClassifications(): CombatClassifications;
192
199
  set combatClassifications(combatClassifications: CombatClassifications);
193
- get unitClassifications(): UnitClassifications;
194
- set unitClassifications(unitClassifications: UnitClassifications);
200
+ get classifications(): UnitClassifications;
201
+ set classifications(unitClassifications: UnitClassifications);
195
202
  get weapons(): TupleOf<UnitTypeWeapon, 2>;
196
203
  get firstWeapon(): UnitTypeWeapon;
197
204
  get secondWeapon(): UnitTypeWeapon;
@@ -225,6 +232,8 @@ export declare abstract class UnitType<Id extends UnitTypeId = UnitTypeId> exten
225
232
  set goldCost(goldCost: number);
226
233
  get healthRegenerationRate(): number;
227
234
  set healthRegenerationRate(healthRegenerationRate: number);
235
+ get level(): number;
236
+ set level(level: number);
228
237
  get manaRegenerationRate(): number;
229
238
  set manaRegenerationRate(manaRegenerationRate: number);
230
239
  get maximumHealth(): number;
@@ -27,6 +27,9 @@ local attackTypeToString = ____attack_2Dtype.attackTypeToString
27
27
  local stringToAttackType = ____attack_2Dtype.stringToAttackType
28
28
  local ____config = require("config")
29
29
  local WarscriptConfig = ____config.WarscriptConfig
30
+ local ____armor_2Dtype = require("engine.object-data.auxiliary.armor-type")
31
+ local armorTypeToString = ____armor_2Dtype.armorTypeToString
32
+ local stringToArmorType = ____armor_2Dtype.stringToArmorType
30
33
  local getOrCreateUnitTypeWeapons
31
34
  ____exports.UnitTypeWeapon = __TS__Class()
32
35
  local UnitTypeWeapon = ____exports.UnitTypeWeapon
@@ -936,6 +939,19 @@ __TS__SetDescriptor(
936
939
  },
937
940
  true
938
941
  )
942
+ __TS__SetDescriptor(
943
+ UnitType.prototype,
944
+ "selectionCircleHeight",
945
+ {
946
+ get = function(self)
947
+ return self:getNumberField("uslz")
948
+ end,
949
+ set = function(self, height)
950
+ self:setNumberField("uslz", height)
951
+ end
952
+ },
953
+ true
954
+ )
939
955
  __TS__SetDescriptor(
940
956
  UnitType.prototype,
941
957
  "selectionCircleScale",
@@ -1183,6 +1199,19 @@ __TS__SetDescriptor(
1183
1199
  },
1184
1200
  true
1185
1201
  )
1202
+ __TS__SetDescriptor(
1203
+ UnitType.prototype,
1204
+ "armor",
1205
+ {
1206
+ get = function(self)
1207
+ return self:getNumberField("udef")
1208
+ end,
1209
+ set = function(self, armor)
1210
+ self:setNumberField("udef", armor)
1211
+ end
1212
+ },
1213
+ true
1214
+ )
1186
1215
  __TS__SetDescriptor(
1187
1216
  UnitType.prototype,
1188
1217
  "armorSoundType",
@@ -1222,6 +1251,22 @@ __TS__SetDescriptor(
1222
1251
  },
1223
1252
  true
1224
1253
  )
1254
+ __TS__SetDescriptor(
1255
+ UnitType.prototype,
1256
+ "armorType",
1257
+ {
1258
+ get = function(self)
1259
+ return stringToArmorType(self:getStringField("udty"))
1260
+ end,
1261
+ set = function(self, armorType)
1262
+ self:setStringField(
1263
+ "udty",
1264
+ armorTypeToString(armorType)
1265
+ )
1266
+ end
1267
+ },
1268
+ true
1269
+ )
1225
1270
  __TS__SetDescriptor(
1226
1271
  UnitType.prototype,
1227
1272
  "combatClassifications",
@@ -1240,7 +1285,7 @@ __TS__SetDescriptor(
1240
1285
  )
1241
1286
  __TS__SetDescriptor(
1242
1287
  UnitType.prototype,
1243
- "unitClassifications",
1288
+ "classifications",
1244
1289
  {
1245
1290
  get = function(self)
1246
1291
  return stringArrayToUnitClassifications(self:getStringsField("utyp"))
@@ -1476,6 +1521,19 @@ __TS__SetDescriptor(
1476
1521
  },
1477
1522
  true
1478
1523
  )
1524
+ __TS__SetDescriptor(
1525
+ UnitType.prototype,
1526
+ "level",
1527
+ {
1528
+ get = function(self)
1529
+ return self:getNumberField("ulev")
1530
+ end,
1531
+ set = function(self, level)
1532
+ self:setNumberField("ulev", level)
1533
+ end
1534
+ },
1535
+ true
1536
+ )
1479
1537
  __TS__SetDescriptor(
1480
1538
  UnitType.prototype,
1481
1539
  "manaRegenerationRate",
@@ -23,7 +23,7 @@ declare const enum TextTagPropertyKey {
23
23
  Y = 107
24
24
  }
25
25
  export declare class TextTag extends AbstractDestroyable {
26
- private readonly [TextTagPropertyKey.HANDLE];
26
+ private [TextTagPropertyKey.HANDLE]?;
27
27
  private [TextTagPropertyKey.CONFIGURATION]?;
28
28
  private [TextTagPropertyKey.TEXT]?;
29
29
  private [TextTagPropertyKey.FONT_SIZE]?;
@@ -11,6 +11,12 @@ local ____timer = require("core.types.timer")
11
11
  local Timer = ____timer.Timer
12
12
  local ____destroyable = require("destroyable")
13
13
  local AbstractDestroyable = ____destroyable.AbstractDestroyable
14
+ local ____playerCamera = require("core.types.playerCamera")
15
+ local worldCoordinatesToFrame = ____playerCamera.worldCoordinatesToFrame
16
+ local ____get_2Dterrain_2Dz = require("engine.internal.misc.get-terrain-z")
17
+ local getTerrainZ = ____get_2Dterrain_2Dz.getTerrainZ
18
+ local ____player_2Dlocal_2Dhandle = require("engine.internal.misc.player-local-handle")
19
+ local PLAYER_LOCAL_HANDLE = ____player_2Dlocal_2Dhandle.PLAYER_LOCAL_HANDLE
14
20
  local createTextTag = CreateTextTag
15
21
  local destroyTextTag = DestroyTextTag
16
22
  local setTextTagText = SetTextTagText
@@ -24,6 +30,12 @@ local setTextTagPermanent = SetTextTagPermanent
24
30
  local setTextTagAge = SetTextTagAge
25
31
  local setTextTagLifespan = SetTextTagLifespan
26
32
  local setTextTagFadepoint = SetTextTagFadepoint
33
+ local isUnitHidden = IsUnitHidden
34
+ local isUnitLoaded = IsUnitLoaded
35
+ local isUnitVisible = IsUnitVisible
36
+ local getUnitFlyHeight = GetUnitFlyHeight
37
+ local getUnitX = GetUnitX
38
+ local getUnitY = GetUnitY
27
39
  local DEFAULT_FONT_SIZE = 0.024
28
40
  local function applyConfiguration(textTag, configuration)
29
41
  setTextTagFadepoint(textTag, configuration.fadepoint)
@@ -41,6 +53,33 @@ local function applyConfiguration(textTag, configuration)
41
53
  setTextTagVisibility(textTag, true)
42
54
  end
43
55
  local unitTextTags = setmetatable({}, {__mode = "k"})
56
+ local function ensureHandle(textTag)
57
+ local handle = textTag[101]
58
+ if handle == nil then
59
+ handle = createTextTag()
60
+ applyConfiguration(handle, textTag[102])
61
+ setTextTagPermanent(handle, true)
62
+ setTextTagText(handle, textTag[103] or "", textTag[104] or DEFAULT_FONT_SIZE)
63
+ local color = textTag[105]
64
+ if color ~= nil then
65
+ setTextTagColor(
66
+ handle,
67
+ color.r,
68
+ color.g,
69
+ color.b,
70
+ color.a
71
+ )
72
+ end
73
+ local unit = textTag[100]
74
+ if unit ~= nil then
75
+ setTextTagPosUnit(handle, unit.handle, textTag[102].offsetZ)
76
+ else
77
+ setTextTagPos(handle, textTag[106] or 0, textTag[107] or 0, 0)
78
+ end
79
+ textTag[101] = handle
80
+ end
81
+ return handle
82
+ end
44
83
  ____exports.TextTag = __TS__Class()
45
84
  local TextTag = ____exports.TextTag
46
85
  TextTag.name = "TextTag"
@@ -50,7 +89,11 @@ function TextTag.prototype.____constructor(self, handle)
50
89
  self[101] = handle
51
90
  end
52
91
  function TextTag.prototype.onDestroy(self)
53
- destroyTextTag(self[101])
92
+ local handle = self[101]
93
+ if handle ~= nil then
94
+ destroyTextTag(handle)
95
+ self[101] = nil
96
+ end
54
97
  unitTextTags[self] = nil
55
98
  return AbstractDestroyable.prototype.onDestroy(self)
56
99
  end
@@ -61,14 +104,11 @@ function TextTag.flash(self, configuration, text, x, y, z)
61
104
  applyConfiguration(textTag, configuration)
62
105
  end
63
106
  function TextTag.create(self, configuration, text, unit)
64
- local handle = createTextTag()
65
- setTextTagText(handle, text, DEFAULT_FONT_SIZE)
66
- setTextTagPosUnit(handle, unit.handle, configuration.offsetZ)
67
- applyConfiguration(handle, configuration)
68
- setTextTagPermanent(handle, true)
69
- local textTag = __TS__New(____exports.TextTag, handle)
107
+ local textTag = __TS__New(____exports.TextTag)
108
+ textTag[103] = text
70
109
  textTag[100] = unit
71
110
  textTag[102] = configuration
111
+ ensureHandle(textTag)
72
112
  unitTextTags[textTag] = true
73
113
  return textTag
74
114
  end
@@ -80,7 +120,11 @@ __TS__SetDescriptor(
80
120
  return self[103] or ""
81
121
  end,
82
122
  set = function(self, text)
83
- setTextTagText(self[101], text, self[104] or DEFAULT_FONT_SIZE)
123
+ setTextTagText(
124
+ ensureHandle(self),
125
+ text,
126
+ self[104] or DEFAULT_FONT_SIZE
127
+ )
84
128
  self[103] = text
85
129
  end
86
130
  },
@@ -94,7 +138,11 @@ __TS__SetDescriptor(
94
138
  return self[104] or DEFAULT_FONT_SIZE
95
139
  end,
96
140
  set = function(self, fontSize)
97
- setTextTagText(self[101], self[103] or "", DEFAULT_FONT_SIZE)
141
+ setTextTagText(
142
+ ensureHandle(self),
143
+ self[103] or "",
144
+ DEFAULT_FONT_SIZE
145
+ )
98
146
  self[104] = fontSize
99
147
  end
100
148
  },
@@ -109,7 +157,7 @@ __TS__SetDescriptor(
109
157
  end,
110
158
  set = function(self, color)
111
159
  setTextTagColor(
112
- self[101],
160
+ ensureHandle(self),
113
161
  color.r,
114
162
  color.g,
115
163
  color.b,
@@ -129,7 +177,11 @@ __TS__SetDescriptor(
129
177
  end,
130
178
  set = function(self, unit)
131
179
  if unit ~= nil then
132
- setTextTagPosUnit(self[101], unit.handle, 0)
180
+ setTextTagPosUnit(
181
+ ensureHandle(self),
182
+ unit.handle,
183
+ 0
184
+ )
133
185
  self[106] = nil
134
186
  self[107] = nil
135
187
  unitTextTags[self] = true
@@ -137,7 +189,12 @@ __TS__SetDescriptor(
137
189
  local unit = self[100]
138
190
  local x = unit.x
139
191
  local y = unit.y
140
- setTextTagPos(self[101], x, y, 0)
192
+ setTextTagPos(
193
+ ensureHandle(self),
194
+ x,
195
+ y,
196
+ 0
197
+ )
141
198
  self[106] = x
142
199
  self[107] = y
143
200
  unitTextTags[self] = nil
@@ -160,14 +217,14 @@ __TS__SetDescriptor(
160
217
  return ____self__106_2 or 0
161
218
  end,
162
219
  set = function(self, x)
163
- local ____self__101_6 = self[101]
220
+ local ____ensureHandle_result_6 = ensureHandle(self)
164
221
  local ____x_7 = x
165
222
  local ____self__107_5 = self[107]
166
223
  if ____self__107_5 == nil then
167
224
  local ____opt_3 = self[100]
168
225
  ____self__107_5 = ____opt_3 and ____opt_3.y
169
226
  end
170
- setTextTagPos(____self__101_6, ____x_7, ____self__107_5 or 0, 0)
227
+ setTextTagPos(____ensureHandle_result_6, ____x_7, ____self__107_5 or 0, 0)
171
228
  self[106] = x
172
229
  self[100] = nil
173
230
  unitTextTags[self] = nil
@@ -188,13 +245,13 @@ __TS__SetDescriptor(
188
245
  return ____self__107_10 or 0
189
246
  end,
190
247
  set = function(self, y)
191
- local ____self__101_14 = self[101]
248
+ local ____ensureHandle_result_14 = ensureHandle(self)
192
249
  local ____self__106_13 = self[106]
193
250
  if ____self__106_13 == nil then
194
251
  local ____opt_11 = self[100]
195
252
  ____self__106_13 = ____opt_11 and ____opt_11.x
196
253
  end
197
- setTextTagPos(____self__101_14, ____self__106_13 or 0, y, 0)
254
+ setTextTagPos(____ensureHandle_result_14, ____self__106_13 or 0, y, 0)
198
255
  self[107] = y
199
256
  self[100] = nil
200
257
  unitTextTags[self] = nil
@@ -268,7 +325,24 @@ TextTag.SHADOW_STRIKE = __TS__ObjectAssign(
268
325
  )
269
326
  Timer.onPeriod[1 / 64]:addListener(function()
270
327
  for textTag in pairs(unitTextTags) do
271
- setTextTagPosUnit(textTag[101], textTag[100].handle, textTag[102].offsetZ)
328
+ local unit = textTag[100].handle
329
+ local x = getUnitX(unit)
330
+ local y = getUnitY(unit)
331
+ local ____, ____, isInView = worldCoordinatesToFrame(
332
+ x,
333
+ y,
334
+ getUnitFlyHeight(unit) + getTerrainZ(x, y)
335
+ )
336
+ if isInView and not isUnitHidden(unit) and not isUnitLoaded(unit) and isUnitVisible(unit, PLAYER_LOCAL_HANDLE) then
337
+ setTextTagPosUnit(
338
+ ensureHandle(textTag),
339
+ unit,
340
+ textTag[102].offsetZ
341
+ )
342
+ elseif textTag[101] ~= nil then
343
+ destroyTextTag(textTag[101])
344
+ textTag[101] = nil
345
+ end
272
346
  end
273
347
  end)
274
348
  return ____exports
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "warscript",
4
- "version": "0.0.1-dev.311b554",
4
+ "version": "0.0.1-dev.3370e98",
5
5
  "description": "A typescript library for Warcraft III using Warpack.",
6
6
  "keywords": [
7
7
  "warcraft",
@@ -24,7 +24,7 @@
24
24
  "@warscript/language-extensions": "^0.0.1",
25
25
  "@warscript/tstl-plugin": "^0.0.4",
26
26
  "lua-types": "^2.13.1",
27
- "warpack": "0.0.1-dev.fa5e065"
27
+ "warpack": "0.0.1-dev.78d2c64"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@typescript-eslint/eslint-plugin": "^8.13.0",
@@ -7,3 +7,7 @@ export declare const identity: <T>(value: T) => T;
7
7
  export declare const firstArgument: <T>(value: T) => T;
8
8
  export declare const secondArgument: <T>(_: unknown, value: T) => T;
9
9
  export declare const thirdArgument: <T>(_first: unknown, _second: unknown, value: T) => T;
10
+ export declare const increment: (value: number) => number;
11
+ export declare const or: (lhs: boolean, rhs: boolean) => boolean;
12
+ export type Transform<T, R> = (<T, R>(value: T) => R) | KeysOfType<T, R>;
13
+ export declare const transform: <T, R>(object: T, transform: Transform<T, R>) => R;
@@ -91,4 +91,13 @@ ____exports.identity = function(value) return value end
91
91
  ____exports.firstArgument = ____exports.identity
92
92
  ____exports.secondArgument = function(_, value) return value end
93
93
  ____exports.thirdArgument = function(_first, _second, value) return value end
94
+ ____exports.increment = function(value) return value + 1 end
95
+ ____exports["or"] = function(lhs, rhs) return lhs or rhs end
96
+ ____exports.transform = function(object, transform)
97
+ if type(transform) == "function" then
98
+ return transform(object)
99
+ else
100
+ return object[transform]
101
+ end
102
+ end
94
103
  return ____exports
@@ -1,4 +1,5 @@
1
1
  /** @noSelfInFile */
2
+ export declare const emptyLuaSet: <T extends AnyNotNil>() => ReadonlyLuaSet<T>;
2
3
  export declare const mutableLuaSet: <T extends AnyNotNil>() => LuaSet<T>;
3
4
  export declare const luaSetOf: <T extends AnyNotNil>(...elements: readonly T[]) => LuaSet<T>;
4
5
  export declare const luaSetOfNotNull: <T extends AnyNotNil>(...elements: readonly (T | undefined | null)[]) => LuaSet<T>;
@@ -1,5 +1,9 @@
1
1
  local ____exports = {}
2
2
  local select = _G.select
3
+ local EMPTY_LUA_SET = {}
4
+ ____exports.emptyLuaSet = function()
5
+ return EMPTY_LUA_SET
6
+ end
3
7
  ____exports.mutableLuaSet = function()
4
8
  return {}
5
9
  end