warscript 0.0.1-dev.1a5c0c0 → 0.0.1-dev.1b0add9

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.
@@ -4,15 +4,22 @@ import { Widget } from "./widget";
4
4
  import { PlayerColor } from "./playerColor";
5
5
  declare const enum EffectPropertyKey {
6
6
  COLOR = 100,
7
- PITCH = 101
7
+ PITCH = 101,
8
+ ROLL = 102
8
9
  }
9
10
  export type EffectParameters = {
10
11
  readonly scale?: number;
11
12
  readonly color?: PlayerColor;
13
+ readonly pitch?: number;
14
+ readonly roll?: number;
15
+ readonly detached?: boolean;
16
+ readonly zOffset?: number;
17
+ readonly scaleZOffset?: boolean;
12
18
  };
13
19
  export declare class Effect extends Handle<jeffect> {
14
20
  private [EffectPropertyKey.COLOR]?;
15
21
  private [EffectPropertyKey.PITCH]?;
22
+ private [EffectPropertyKey.ROLL]?;
16
23
  protected onDestroy(): HandleDestructor;
17
24
  get color(): PlayerColor;
18
25
  set color(color: PlayerColor);
@@ -20,11 +27,13 @@ export declare class Effect extends Handle<jeffect> {
20
27
  set scale(scale: number);
21
28
  get pitch(): number;
22
29
  set pitch(pitch: number);
30
+ get roll(): number;
31
+ set roll(roll: number);
23
32
  static create<T extends Effect>(this: typeof Effect & (new (handle: jeffect) => T), model: string, pos: Vec2): T;
24
33
  static createTarget<T extends Effect>(this: typeof Effect & (new (handle: jeffect) => T), model: string, target: Widget, attachPoint: string): T;
25
34
  static flash(modelPath: string, ...args: [
26
- ...pointOrWidget: [x: number, y: number] | [widget: Widget, attachmentPoint: string],
27
- ...parametersOrDuration: [parameters?: EffectParameters] | [duration?: number, parameters?: EffectParameters]
35
+ ...pointOrWidget: [x: number, y: number] | [widget: Widget, attachmentPoint?: string],
36
+ ...parametersOrDuration: [parametersOrDuration?: EffectParameters | number] | [duration?: number, parameters?: EffectParameters]
28
37
  ]): void;
29
38
  static flashTarget(model: string, target: Widget, attachPoint: string, duration?: number): void;
30
39
  }
@@ -1,6 +1,7 @@
1
1
  local ____lualib = require("lualib_bundle")
2
2
  local __TS__Class = ____lualib.__TS__Class
3
3
  local __TS__ClassExtends = ____lualib.__TS__ClassExtends
4
+ local __TS__InstanceOf = ____lualib.__TS__InstanceOf
4
5
  local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
5
6
  local ____exports = {}
6
7
  local dummyPlayer
@@ -12,6 +13,8 @@ local ____player = require("core.types.player")
12
13
  local Player = ____player.Player
13
14
  local ____timer = require("core.types.timer")
14
15
  local Timer = ____timer.Timer
16
+ local ____unit = require("engine.internal.unit")
17
+ local Unit = ____unit.Unit
15
18
  local ____pairs = _G.pairs
16
19
  local select = _G.select
17
20
  local mathRad = math.rad
@@ -22,10 +25,28 @@ local getSpecialEffectScale = BlzGetSpecialEffectScale
22
25
  local playSpecialEffect = BlzPlaySpecialEffect
23
26
  local setSpecialEffectScale = BlzSetSpecialEffectScale
24
27
  local setSpecialEffectPitch = BlzSetSpecialEffectPitch
28
+ local setSpecialEffectRoll = BlzSetSpecialEffectRoll
25
29
  local setSpecialEffectColorByPlayer = BlzSetSpecialEffectColorByPlayer
26
30
  local specialEffectAddSubAnimation = BlzSpecialEffectAddSubAnimation
27
31
  local specialEffectClearSubAnimations = BlzSpecialEffectClearSubAnimations
28
32
  local specialEffectRemoveSubAnimation = BlzSpecialEffectRemoveSubAnimation
33
+ local setSpecialEffectZ = BlzSetSpecialEffectZ
34
+ local getLocationZ = GetLocationZ
35
+ local getUnitZ = BlzGetUnitZ
36
+ local moveLocation = MoveLocation
37
+ local location = Location(0, 0)
38
+ local function setSpecialEffectPitchDegrees(effect, pitch)
39
+ setSpecialEffectPitch(
40
+ effect,
41
+ -mathRad(pitch)
42
+ )
43
+ end
44
+ local function setSpecialEffectRollDegrees(effect, pitch)
45
+ setSpecialEffectRoll(
46
+ effect,
47
+ -mathRad(pitch)
48
+ )
49
+ end
29
50
  local animTypeByAnimationName = {
30
51
  attack = ANIM_TYPE_ATTACK,
31
52
  birth = ANIM_TYPE_BIRTH,
@@ -97,7 +118,7 @@ local function setSpecialEffectColor(effect, color)
97
118
  setSpecialEffectColorByPlayer(effect, dummyPlayer.handle)
98
119
  dummyPlayer.color = dummyColor
99
120
  end
100
- local setters = {scale = setSpecialEffectScale, color = setSpecialEffectColor}
121
+ local setters = {scale = setSpecialEffectScale, color = setSpecialEffectColor, pitch = setSpecialEffectPitchDegrees, roll = setSpecialEffectRollDegrees}
101
122
  dummyPlayer = Player.neutralExtra
102
123
  local temporaryEffects = {}
103
124
  local temporaryEffectsDurations = {}
@@ -136,10 +157,27 @@ function Effect.flash(self, modelPath, xOrWidget, yOrOrAttachmentPoint, paramete
136
157
  parameters = parametersOrDuration
137
158
  parametersOrDuration = nil
138
159
  end
139
- local effect = type(xOrWidget) == "number" and addSpecialEffect(modelPath, xOrWidget, yOrOrAttachmentPoint) or addSpecialEffectTarget(modelPath, xOrWidget.handle, yOrOrAttachmentPoint)
160
+ local coordinatesProvided = type(xOrWidget) == "number"
161
+ local isPositional = coordinatesProvided or (parameters and parameters.detached) == true
162
+ local x = not isPositional and 0 or (coordinatesProvided and xOrWidget or xOrWidget.x)
163
+ local y = not isPositional and 0 or (coordinatesProvided and yOrOrAttachmentPoint or xOrWidget.y)
164
+ local effect = isPositional and addSpecialEffect(modelPath, x, y) or addSpecialEffectTarget(modelPath, xOrWidget.handle, yOrOrAttachmentPoint or "origin")
165
+ if isPositional and not coordinatesProvided and (parameters and parameters.scale) == nil and __TS__InstanceOf(xOrWidget, Unit) then
166
+ setSpecialEffectScale(effect, xOrWidget.scale)
167
+ end
140
168
  if parameters ~= nil then
141
169
  for key, value in ____pairs(parameters) do
142
- setters[key](effect, value)
170
+ if key ~= "zOffset" and key ~= "detached" and key ~= "scaleZOffset" then
171
+ setters[key](effect, value)
172
+ end
173
+ end
174
+ if isPositional and parameters.zOffset ~= nil then
175
+ moveLocation(location, x, y)
176
+ local z = __TS__InstanceOf(xOrWidget, Unit) and getLocationZ(location) + xOrWidget.flyHeight or getLocationZ(location)
177
+ BlzSetSpecialEffectZ(
178
+ effect,
179
+ z + parameters.zOffset * (parameters.scaleZOffset and getSpecialEffectScale(effect) or 1)
180
+ )
143
181
  end
144
182
  end
145
183
  if parametersOrDuration ~= nil and parametersOrDuration > 0 then
@@ -197,13 +235,24 @@ __TS__SetDescriptor(
197
235
  return self[101] or 0
198
236
  end,
199
237
  set = function(self, pitch)
200
- setSpecialEffectPitch(
201
- self.handle,
202
- -mathRad(pitch)
203
- )
238
+ setSpecialEffectPitchDegrees(self.handle, pitch)
204
239
  self[101] = pitch
205
240
  end
206
241
  },
207
242
  true
208
243
  )
244
+ __TS__SetDescriptor(
245
+ Effect.prototype,
246
+ "roll",
247
+ {
248
+ get = function(self)
249
+ return self[102] or 0
250
+ end,
251
+ set = function(self, roll)
252
+ setSpecialEffectRollDegrees(self.handle, roll)
253
+ self[102] = roll
254
+ end
255
+ },
256
+ true
257
+ )
209
258
  return ____exports
@@ -31,6 +31,7 @@ export declare class Frame extends Handle<jframehandle> {
31
31
  static readonly WORLD: Frame;
32
32
  static readonly CHAT: Frame;
33
33
  static readonly TIME_OF_DAY_CLOCK: Frame;
34
+ private static readonly SIMPLE_FRAME_TEST_CHILD;
34
35
  static get uiScale(): number;
35
36
  static get leftBorder(): Frame;
36
37
  static get rightBorder(): Frame;
@@ -79,6 +80,8 @@ export declare class Frame extends Handle<jframehandle> {
79
80
  get onMouseLeave(): FrameEvent;
80
81
  get onMouseUp(): FrameEvent;
81
82
  get onMouseWheel(): FrameEvent<[number]>;
83
+ get mouseEnterLocalEvent(): Event;
84
+ get mouseLeaveLocalEvent(): Event;
82
85
  get popupMenuItemChangeEvent(): FrameEvent<[
83
86
  popupMenu: Frame,
84
87
  previousValue: number,
@@ -122,6 +122,7 @@ do
122
122
  FramePoint.BOTTOM = FRAMEPOINT_BOTTOM
123
123
  FramePoint.BOTTOM_RIGHT = FRAMEPOINT_BOTTOMRIGHT
124
124
  end
125
+ local tooltipByFrame = setmetatable({}, {__mode = "k"})
125
126
  ____exports.Frame = __TS__Class()
126
127
  local Frame = ____exports.Frame
127
128
  Frame.name = "Frame"
@@ -242,6 +243,7 @@ function Frame.prototype.setTextColor(self, color)
242
243
  end
243
244
  function Frame.prototype.setTooltip(self, tooltip)
244
245
  BlzFrameSetTooltip(self.handle, tooltip.handle)
246
+ tooltipByFrame[self] = tooltip
245
247
  end
246
248
  function Frame.prototype.setMinMaxValue(self, minValue, maxValue)
247
249
  BlzFrameSetMinMaxValue(self.handle, minValue, maxValue)
@@ -310,6 +312,7 @@ Frame.CONSOLE_BOTTOM_BAR = ____exports.Frame:byName("ConsoleBottomBar")
310
312
  Frame.WORLD = ____exports.Frame:byOrigin(ORIGIN_FRAME_WORLD_FRAME)
311
313
  Frame.CHAT = ____exports.Frame:byOrigin(ORIGIN_FRAME_CHAT_MSG)
312
314
  Frame.TIME_OF_DAY_CLOCK = ____exports.Frame.GAME_UI:getChild(5):getChild(0)
315
+ Frame.SIMPLE_FRAME_TEST_CHILD = ____exports.Frame:createByType("SIMPLEFRAME", "SimpleFrameTestParent", ____exports.Frame.CONSOLE_UI)
313
316
  __TS__ObjectDefineProperty(
314
317
  Frame,
315
318
  "uiScale",
@@ -618,6 +621,62 @@ __TS__SetDescriptor(
618
621
  end},
619
622
  true
620
623
  )
624
+ __TS__SetDescriptor(
625
+ Frame.prototype,
626
+ "mouseEnterLocalEvent",
627
+ {get = function(self)
628
+ local event = __TS__New(Event)
629
+ if not (tooltipByFrame[self] ~= nil) then
630
+ ____exports.Frame.SIMPLE_FRAME_TEST_CHILD.parent = self
631
+ local tooltip = ____exports.Frame.SIMPLE_FRAME_TEST_CHILD.parent == self and ____exports.Frame:createByType("SIMPLEFRAME", "", ____exports.Frame.CONSOLE_UI) or ____exports.Frame:createByType("FRAME", "", ____exports.Frame.GAME_UI)
632
+ ____exports.Frame.SIMPLE_FRAME_TEST_CHILD.parent = ____exports.Frame.CONSOLE_UI
633
+ self:setTooltip(tooltip)
634
+ end
635
+ local isMouseInside = false
636
+ Timer.onPeriod[1 / 64]:addListener(function()
637
+ local tooltip = tooltipByFrame[self]
638
+ if tooltip and tooltip.visible then
639
+ if not isMouseInside then
640
+ isMouseInside = true
641
+ Event.invoke(event)
642
+ end
643
+ else
644
+ isMouseInside = false
645
+ end
646
+ end)
647
+ rawset(self, "mouseEnterLocalEvent", event)
648
+ return event
649
+ end},
650
+ true
651
+ )
652
+ __TS__SetDescriptor(
653
+ Frame.prototype,
654
+ "mouseLeaveLocalEvent",
655
+ {get = function(self)
656
+ local event = __TS__New(Event)
657
+ if not (tooltipByFrame[self] ~= nil) then
658
+ ____exports.Frame.SIMPLE_FRAME_TEST_CHILD.parent = self
659
+ local tooltip = ____exports.Frame.SIMPLE_FRAME_TEST_CHILD.parent == self and ____exports.Frame:createByType("SIMPLEFRAME", "", ____exports.Frame.CONSOLE_UI) or ____exports.Frame:createByType("FRAME", "", ____exports.Frame.GAME_UI)
660
+ ____exports.Frame.SIMPLE_FRAME_TEST_CHILD.parent = ____exports.Frame.CONSOLE_UI
661
+ self:setTooltip(tooltip)
662
+ end
663
+ local isMouseInside = false
664
+ Timer.onPeriod[1 / 64]:addListener(function()
665
+ local tooltip = tooltipByFrame[self]
666
+ if tooltip and tooltip.visible then
667
+ isMouseInside = true
668
+ else
669
+ if isMouseInside then
670
+ isMouseInside = false
671
+ Event.invoke(event)
672
+ end
673
+ end
674
+ end)
675
+ rawset(self, "mouseLeaveLocalEvent", event)
676
+ return event
677
+ end},
678
+ true
679
+ )
621
680
  __TS__SetDescriptor(
622
681
  Frame.prototype,
623
682
  "popupMenuItemChangeEvent",
package/engine/buff.d.ts CHANGED
@@ -8,6 +8,7 @@ import { BuffResistanceType } from "./object-data/auxiliary/buff-resistance-type
8
8
  import { AbilityBooleanField, AbilityBooleanLevelField, AbilityCombatClassificationsLevelField, AbilityDependentValue, AbilityEnumLevelField, AbilityIntegerField, AbilityIntegerLevelField, AbilityNumberField, AbilityNumberLevelField } from "./object-field/ability";
9
9
  import { CombatClassifications } from "./object-data/auxiliary/combat-classification";
10
10
  import { IsExactlyAny, Prohibit, ReadonlyNonEmptyArray } from "../utility/types";
11
+ import { EffectParameters } from "../core/types/effect";
11
12
  import { UnitBehavior } from "./behaviour/unit";
12
13
  import type { Widget } from "../core/types/widget";
13
14
  import { Destructor } from "../destroyable";
@@ -250,8 +251,12 @@ export declare class Buff<AdditionalParameters extends Prohibit<Record<string, a
250
251
  get duration(): number;
251
252
  get remainingDuration(): number;
252
253
  set remainingDuration(remainingDuration: number);
253
- flashEffect(...parameters: [...widget: [] | [Widget], ...duration: [] | [number]]): void;
254
+ flashEffect(...parameters: [
255
+ ...widgetOrXY: [] | [Widget] | [x: number, x: number],
256
+ ...parametersOrDuration: [] | [EffectParameters] | [number]
257
+ ]): void;
254
258
  flashSpecialEffect(...parameters: [...widget: [] | [Widget], ...duration: [] | [number]]): void;
259
+ protected onCreate(): void;
255
260
  protected onDestroy(): Destructor;
256
261
  static apply<T extends Buff<any>, Args extends any[]>(this: BuffConstructor<T, Args>, ...args: Args): T | undefined;
257
262
  static getByTypeId<T extends Buff<any>, Args extends any[]>(this: BuffConstructor<T, Args>, unit: Unit, typeId: ApplicableBuffTypeId): T | undefined;
package/engine/buff.lua CHANGED
@@ -46,6 +46,10 @@ local ____arrays = require("utility.arrays")
46
46
  local forEach = ____arrays.forEach
47
47
  local ____ability_2Dduration = require("engine.internal.mechanics.ability-duration")
48
48
  local getAbilityDuration = ____ability_2Dduration.getAbilityDuration
49
+ local ____item = require("engine.internal.item")
50
+ local Item = ____item.Item
51
+ local ____destructable = require("core.types.destructable")
52
+ local Destructable = ____destructable.Destructable
49
53
  local getUnitAbility = BlzGetUnitAbility
50
54
  local stringValueByBuffTypeIdByFieldId = postcompile(function()
51
55
  local stringValueByBuffTypeIdByFieldId = {}
@@ -482,6 +486,7 @@ function Buff.prototype.____constructor(self, _unit, typeIdOrTypeIds, polarityOr
482
486
  timer:start(duration, false, expireBuff, self)
483
487
  self._timer = timer
484
488
  end
489
+ self:onCreate()
485
490
  end
486
491
  function Buff.prototype.getUnitBonus(self, bonusType)
487
492
  local ____opt_36 = self._bonusIdByBonusType
@@ -496,26 +501,30 @@ function Buff.prototype.addOrUpdateOrRemoveUnitBonus(self, bonusType, value)
496
501
  end
497
502
  bonusIdByBonusType[bonusType] = addOrUpdateOrRemoveUnitBonus(self._unit, bonusType, bonusIdByBonusType[bonusType], value)
498
503
  end
499
- function Buff.prototype.flashEffect(self, widgetOrDuration, duration)
500
- local isWidgetProvided = type(widgetOrDuration) == "table"
501
- local ____Effect_40 = Effect
502
- local ____Effect_flash_41 = Effect.flash
503
- local ____array_39 = __TS__SparseArrayNew(
504
- self[104],
505
- isWidgetProvided and widgetOrDuration or self._unit,
506
- stringValueByBuffTypeIdByFieldId[fourCC("feft")][self.typeId] or "origin"
507
- )
508
- local ____isWidgetProvided_38
509
- if isWidgetProvided then
510
- ____isWidgetProvided_38 = duration
504
+ function Buff.prototype.flashEffect(self, widgetOrXOrParametersOrDuration, yOrParametersOrDuration, parametersOrDuration)
505
+ if type(widgetOrXOrParametersOrDuration) == "number" and type(yOrParametersOrDuration) == "number" then
506
+ Effect:flash(self[104], widgetOrXOrParametersOrDuration, yOrParametersOrDuration, parametersOrDuration)
511
507
  else
512
- ____isWidgetProvided_38 = widgetOrDuration
508
+ local isWidgetProvided = __TS__InstanceOf(widgetOrXOrParametersOrDuration, Unit) or __TS__InstanceOf(widgetOrXOrParametersOrDuration, Item) or __TS__InstanceOf(widgetOrXOrParametersOrDuration, Destructable)
509
+ local ____Effect_40 = Effect
510
+ local ____Effect_flash_41 = Effect.flash
511
+ local ____array_39 = __TS__SparseArrayNew(
512
+ self[104],
513
+ isWidgetProvided and widgetOrXOrParametersOrDuration or self._unit,
514
+ stringValueByBuffTypeIdByFieldId[fourCC("feft")][self.typeId] or "origin"
515
+ )
516
+ local ____isWidgetProvided_38
517
+ if isWidgetProvided then
518
+ ____isWidgetProvided_38 = yOrParametersOrDuration
519
+ else
520
+ ____isWidgetProvided_38 = widgetOrXOrParametersOrDuration
521
+ end
522
+ __TS__SparseArrayPush(____array_39, ____isWidgetProvided_38)
523
+ ____Effect_flash_41(
524
+ ____Effect_40,
525
+ __TS__SparseArraySpread(____array_39)
526
+ )
513
527
  end
514
- __TS__SparseArrayPush(____array_39, ____isWidgetProvided_38)
515
- ____Effect_flash_41(
516
- ____Effect_40,
517
- __TS__SparseArraySpread(____array_39)
518
- )
519
528
  end
520
529
  function Buff.prototype.flashSpecialEffect(self, widgetOrDuration, duration)
521
530
  local isWidgetProvided = type(widgetOrDuration) == "table"
@@ -538,6 +547,8 @@ function Buff.prototype.flashSpecialEffect(self, widgetOrDuration, duration)
538
547
  __TS__SparseArraySpread(____array_43)
539
548
  )
540
549
  end
550
+ function Buff.prototype.onCreate(self)
551
+ end
541
552
  function Buff.prototype.onDestroy(self)
542
553
  local unit = self._unit
543
554
  if getUnitAbility(unit.handle, self.typeId) == self.handle then
@@ -49,6 +49,8 @@ export declare class UnitAbility extends Ability {
49
49
  readonly owner: Unit;
50
50
  private readonly u;
51
51
  constructor(handle: jability, typeId: number, owner: Unit);
52
+ incrementHideCounter(): void;
53
+ decrementHideCounter(): void;
52
54
  get level(): number;
53
55
  set level(v: number);
54
56
  get cooldownRemaining(): number;
@@ -32,6 +32,7 @@ local getAbilityStringLevelField = BlzGetAbilityStringLevelField
32
32
  local getUnitAbilityCooldownRemaining = BlzGetUnitAbilityCooldownRemaining
33
33
  local startUnitAbilityCooldown = BlzStartUnitAbilityCooldown
34
34
  local getHandleId = GetHandleId
35
+ local unitHideAbility = BlzUnitHideAbility
35
36
  local match = string.match
36
37
  local ____type = _G.type
37
38
  local ____tostring = _G.tostring
@@ -357,6 +358,12 @@ function UnitAbility.prototype.____constructor(self, handle, typeId, owner)
357
358
  self.owner = owner
358
359
  self.u = owner.handle
359
360
  end
361
+ function UnitAbility.prototype.incrementHideCounter(self)
362
+ unitHideAbility(self.u, self.typeId, true)
363
+ end
364
+ function UnitAbility.prototype.decrementHideCounter(self)
365
+ unitHideAbility(self.u, self.typeId, false)
366
+ end
360
367
  __TS__SetDescriptor(
361
368
  UnitAbility.prototype,
362
369
  "level",
@@ -26,11 +26,8 @@ local getSpellTargetUnit = GetSpellTargetUnit
26
26
  local getSpellTargetX = GetSpellTargetX
27
27
  local getSpellTargetY = GetSpellTargetY
28
28
  local getTriggerUnit = GetTriggerUnit
29
- local getUnitAbility = BlzGetUnitAbility
30
- local unitAddAbility = UnitAddAbility
31
29
  local unitInventorySize = UnitInventorySize
32
30
  local unitItemInSlot = UnitItemInSlot
33
- local unitRemoveAbility = UnitRemoveAbility
34
31
  local function retrieveAbility(unit, ability, abilityId)
35
32
  if ability == nil then
36
33
  return __TS__New(
@@ -39,17 +36,6 @@ local function retrieveAbility(unit, ability, abilityId)
39
36
  Unit:of(unit)
40
37
  )
41
38
  end
42
- if not unitAddAbility(unit, abilityId) then
43
- if getUnitAbility(unit, abilityId) == ability then
44
- return UnitAbility:of(
45
- ability,
46
- abilityId,
47
- Unit:of(unit)
48
- )
49
- end
50
- else
51
- unitRemoveAbility(unit, abilityId)
52
- end
53
39
  for i = 0, unitInventorySize(unit) - 1 do
54
40
  local item = unitItemInSlot(unit, i)
55
41
  if getItemAbility(item, abilityId) == ability then
@@ -11,6 +11,7 @@ export interface UnitItems extends ReadonlyArray<Item | undefined> {
11
11
  }
12
12
  export declare class UnitItems {
13
13
  constructor(handle: junit);
14
+ findSlot(item: Item): 0 | 1 | 2 | 3 | 4 | 5 | undefined;
14
15
  protected __newindex(slot: number, item: Item | undefined): void;
15
16
  protected __index(key: string | number): unknown;
16
17
  protected __len(): number;
@@ -30,6 +30,16 @@ UnitItems.name = "UnitItems"
30
30
  function UnitItems.prototype.____constructor(self, handle)
31
31
  handleByUnitItems[self] = handle
32
32
  end
33
+ function UnitItems.prototype.findSlot(self, item)
34
+ local handle = handleByUnitItems[self]
35
+ local itemHandle = item.handle
36
+ for slot = 0, unitInventorySize(handle) - 1 do
37
+ if itemHandle == unitItemInSlot(handle, slot) then
38
+ return slot
39
+ end
40
+ end
41
+ return nil
42
+ end
33
43
  function UnitItems.prototype.__newindex(self, slot, item)
34
44
  local handle = handleByUnitItems[self]
35
45
  if slot < 1 or slot > unitInventorySize(handle) then
@@ -0,0 +1,13 @@
1
+ /** @noSelfInFile */
2
+ import { Player } from "../../../core/types/player";
3
+ import { Event } from "../../../event";
4
+ declare module "../unit" {
5
+ namespace Unit {
6
+ const mainSelectedUnitChangeEvent: Event<[Player]>;
7
+ }
8
+ }
9
+ declare module "../unit" {
10
+ namespace Unit {
11
+ const getMainSelectedOf: (player: Player) => Unit | undefined;
12
+ }
13
+ }
@@ -0,0 +1,51 @@
1
+ local ____lualib = require("lualib_bundle")
2
+ local __TS__New = ____lualib.__TS__New
3
+ local ____exports = {}
4
+ local ____player = require("core.types.player")
5
+ local Player = ____player.Player
6
+ local ____math = require("math")
7
+ local MAXIMUM_INTEGER = ____math.MAXIMUM_INTEGER
8
+ local MINIMUM_INTEGER = ____math.MINIMUM_INTEGER
9
+ local ____local_2Dclient = require("engine.local-client")
10
+ local LocalClient = ____local_2Dclient.LocalClient
11
+ local ____unit = require("engine.internal.unit")
12
+ local Unit = ____unit.Unit
13
+ local ____event = require("event")
14
+ local Event = ____event.Event
15
+ local mainSelectedUnitChangeEvent = __TS__New(Event)
16
+ rawset(Unit, "mainSelectedUnitChangeEvent", mainSelectedUnitChangeEvent)
17
+ local mainSelectedUnitByPlayer = {}
18
+ local syncSlider = BlzCreateFrameByType(
19
+ "SLIDER",
20
+ "UnitSyncId",
21
+ BlzGetOriginFrame(ORIGIN_FRAME_WORLD_FRAME, 0),
22
+ "",
23
+ 0
24
+ )
25
+ BlzFrameSetMinMaxValue(syncSlider, MINIMUM_INTEGER, MAXIMUM_INTEGER)
26
+ LocalClient.mainSelectedUnitChangeEvent:addListener(function()
27
+ local ____opt_0 = LocalClient.mainSelectedUnit
28
+ local syncId = ____opt_0 and ____opt_0.syncId
29
+ BlzFrameSetValue(syncSlider, syncId or 0)
30
+ end)
31
+ local trg = CreateTrigger()
32
+ BlzTriggerRegisterFrameEvent(trg, syncSlider, FRAMEEVENT_SLIDER_VALUE_CHANGED)
33
+ TriggerAddAction(
34
+ trg,
35
+ function()
36
+ local player = Player:of(GetTriggerPlayer())
37
+ local mainSelectedUnit = Unit:getBySyncId(BlzGetTriggerFrameValue())
38
+ if mainSelectedUnit ~= mainSelectedUnitByPlayer[player] then
39
+ mainSelectedUnitByPlayer[player] = mainSelectedUnit
40
+ Event.invoke(mainSelectedUnitChangeEvent, player)
41
+ end
42
+ end
43
+ )
44
+ rawset(
45
+ Unit,
46
+ "getMainSelectedOf",
47
+ function(player)
48
+ return mainSelectedUnitByPlayer[player]
49
+ end
50
+ )
51
+ return ____exports
@@ -94,14 +94,19 @@ export declare class UnitWeapon {
94
94
  set missileSpeed(missileSpeed: number);
95
95
  }
96
96
  declare const enum UnitPropertyKey {
97
- IS_PAUSED = 100,
98
- STUN_COUNTER = 101,
99
- DELAY_HEALTH_CHECKS_COUNTER = 102,
100
- DELAY_HEALTH_CHECKS_HEALTH_BONUS = 103,
101
- PREVENT_DEATH_HEALTH_BONUS = 104,
102
- IS_TEAM_GLOW_HIDDEN = 105
97
+ SYNC_ID = 100,
98
+ IS_PAUSED = 101,
99
+ STUN_COUNTER = 102,
100
+ DELAY_HEALTH_CHECKS_COUNTER = 103,
101
+ DELAY_HEALTH_CHECKS_HEALTH_BONUS = 104,
102
+ PREVENT_DEATH_HEALTH_BONUS = 105,
103
+ IS_TEAM_GLOW_HIDDEN = 106
103
104
  }
105
+ export type UnitSyncId = number & {
106
+ readonly __unitSyncId: unique symbol;
107
+ };
104
108
  export declare class Unit extends Handle<junit> {
109
+ readonly syncId: UnitSyncId;
105
110
  private [UnitPropertyKey.IS_PAUSED]?;
106
111
  private [UnitPropertyKey.STUN_COUNTER]?;
107
112
  private [UnitPropertyKey.DELAY_HEALTH_CHECKS_COUNTER]?;
@@ -327,6 +332,12 @@ export declare class Unit extends Handle<junit> {
327
332
  static itemPickedUpEvent: UnitTriggerEvent<[Item]>;
328
333
  static itemUsedEvent: UnitTriggerEvent<[Item]>;
329
334
  static itemStackedEvent: UnitTriggerEvent<[Item]>;
335
+ static get itemMovedEvent(): Event<[
336
+ unit: Unit,
337
+ item: Item,
338
+ slotFrom: 0 | 1 | 2 | 3 | 4 | 5,
339
+ slotTo: 0 | 1 | 2 | 3 | 4 | 5
340
+ ]>;
330
341
  static get onCreate(): EventDispatcher<[Unit], [Unit]>;
331
342
  static get destroyEvent(): EventDispatcher<[Unit], [Unit]>;
332
343
  getField(field: junitintegerfield | junitrealfield): number;
@@ -337,5 +348,6 @@ export declare class Unit extends Handle<junit> {
337
348
  setField(field: junitbooleanfield, value: boolean): boolean;
338
349
  setField(field: junitstringfield, value: string): boolean;
339
350
  toString(): string;
351
+ static getBySyncId(syncId: UnitSyncId): Unit | undefined;
340
352
  }
341
353
  export {};
@@ -562,17 +562,6 @@ local function retrieveAbility(unit, ability, abilityId)
562
562
  ____exports.Unit:of(unit)
563
563
  )
564
564
  end
565
- if not unitAddAbility(unit, abilityId) then
566
- if getUnitAbility(unit, abilityId) == ability then
567
- return UnitAbility:of(
568
- ability,
569
- abilityId,
570
- ____exports.Unit:of(unit)
571
- )
572
- end
573
- else
574
- unitRemoveAbility(unit, abilityId)
575
- end
576
565
  for i = 0, unitInventorySize(unit) - 1 do
577
566
  local item = unitItemInSlot(unit, i)
578
567
  if getItemAbility(item, abilityId) == ability then
@@ -630,15 +619,15 @@ for ____, player in ipairs(Player.all) do
630
619
  dummies[player] = dummy
631
620
  end
632
621
  local function delayHealthChecksCallback(unit)
633
- local counter = (unit[102] or 0) - 1
622
+ local counter = (unit[103] or 0) - 1
634
623
  if counter ~= 0 then
635
- unit[102] = counter
624
+ unit[103] = counter
636
625
  return
637
626
  end
638
- unit[102] = nil
639
- local healthBonus = unit[103]
627
+ unit[103] = nil
628
+ local healthBonus = unit[104]
640
629
  if healthBonus ~= nil then
641
- unit[103] = nil
630
+ unit[104] = nil
642
631
  local handle = unit.handle
643
632
  BlzSetUnitMaxHP(
644
633
  handle,
@@ -646,12 +635,17 @@ local function delayHealthChecksCallback(unit)
646
635
  )
647
636
  end
648
637
  end
638
+ local nextSyncId = 1
639
+ local unitBySyncId = setmetatable({}, {__mode = "k"})
649
640
  ____exports.Unit = __TS__Class()
650
641
  local Unit = ____exports.Unit
651
642
  Unit.name = "Unit"
652
643
  __TS__ClassExtends(Unit, Handle)
653
644
  function Unit.prototype.____constructor(self, handle)
654
645
  Handle.prototype.____constructor(self, handle)
646
+ local ____nextSyncId_0 = nextSyncId
647
+ nextSyncId = ____nextSyncId_0 + 1
648
+ self.syncId = ____nextSyncId_0
655
649
  self._owner = Player:of(getOwningPlayer(handle))
656
650
  assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
657
651
  assert(unitAddAbility(handle, morphDetectAbilityId))
@@ -664,6 +658,7 @@ function Unit.prototype.____constructor(self, handle)
664
658
  fourCC("Amrf")
665
659
  ))
666
660
  end
661
+ unitBySyncId[self.syncId] = self
667
662
  local ____ = self.abilities
668
663
  end
669
664
  function Unit.prototype.getEvent(self, event, collector)
@@ -749,8 +744,8 @@ function Unit.prototype.addModifier(self, property, modifier)
749
744
  end}
750
745
  end
751
746
  function Unit.prototype.hasCombatClassification(self, combatClassification)
752
- local ____combatClassification_0 = combatClassification
753
- return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_0 == ____combatClassification_0
747
+ local ____combatClassification_1 = combatClassification
748
+ return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_1 == ____combatClassification_1
754
749
  end
755
750
  function Unit.prototype.addClassification(self, classification)
756
751
  return unitAddType(self.handle, classification)
@@ -768,13 +763,13 @@ function Unit.prototype.isInvisibleTo(self, player)
768
763
  return isUnitInvisible(self.handle, player.handle)
769
764
  end
770
765
  function Unit.prototype.isInRangeOf(self, x, y, range)
771
- local ____temp_1
766
+ local ____temp_2
772
767
  if type(x) == "number" then
773
- ____temp_1 = isUnitInRangeXY(self.handle, x, y, range)
768
+ ____temp_2 = isUnitInRangeXY(self.handle, x, y, range)
774
769
  else
775
- ____temp_1 = isUnitInRange(self.handle, x.handle, y)
770
+ ____temp_2 = isUnitInRange(self.handle, x.handle, y)
776
771
  end
777
- return ____temp_1
772
+ return ____temp_2
778
773
  end
779
774
  function Unit.prototype.isAllyOf(self, unit)
780
775
  return isUnitAlly(
@@ -801,7 +796,7 @@ function Unit.prototype.queueAnimation(self, animation)
801
796
  queueUnitAnimation(self.handle, animation)
802
797
  end
803
798
  function Unit.prototype.delayHealthChecks(self)
804
- self[102] = (self[102] or 0) + 1
799
+ self[103] = (self[103] or 0) + 1
805
800
  Timer:run(delayHealthChecksCallback, self)
806
801
  end
807
802
  function Unit.prototype.setPosition(self, x, y)
@@ -818,14 +813,14 @@ function Unit.prototype.kill(self)
818
813
  killUnit(self.handle)
819
814
  end
820
815
  function Unit.prototype.revive(self, x, y, doEffect)
821
- local ____ReviveHero_4 = ReviveHero
822
- local ____array_3 = __TS__SparseArrayNew(self.handle, x, y)
823
- local ____doEffect_2 = doEffect
824
- if ____doEffect_2 == nil then
825
- ____doEffect_2 = false
816
+ local ____ReviveHero_5 = ReviveHero
817
+ local ____array_4 = __TS__SparseArrayNew(self.handle, x, y)
818
+ local ____doEffect_3 = doEffect
819
+ if ____doEffect_3 == nil then
820
+ ____doEffect_3 = false
826
821
  end
827
- __TS__SparseArrayPush(____array_3, ____doEffect_2)
828
- ____ReviveHero_4(__TS__SparseArraySpread(____array_3))
822
+ __TS__SparseArrayPush(____array_4, ____doEffect_3)
823
+ ____ReviveHero_5(__TS__SparseArraySpread(____array_4))
829
824
  end
830
825
  function Unit.prototype.healTarget(self, target, amount)
831
826
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -995,18 +990,18 @@ function Unit.prototype.unpauseEx(self)
995
990
  self:decrementStunCounter()
996
991
  end
997
992
  function Unit.prototype.incrementStunCounter(self)
998
- local stunCounter = self[101] or 0
999
- if not self[100] or stunCounter >= 0 then
993
+ local stunCounter = self[102] or 0
994
+ if not self[101] or stunCounter >= 0 then
1000
995
  BlzPauseUnitEx(self.handle, true)
1001
996
  end
1002
- self[101] = stunCounter + 1
997
+ self[102] = stunCounter + 1
1003
998
  end
1004
999
  function Unit.prototype.decrementStunCounter(self)
1005
- local stunCounter = self[101] or 0
1006
- if not self[100] or stunCounter >= 1 then
1000
+ local stunCounter = self[102] or 0
1001
+ if not self[101] or stunCounter >= 1 then
1007
1002
  BlzPauseUnitEx(self.handle, false)
1008
1003
  end
1009
- self[101] = stunCounter - 1
1004
+ self[102] = stunCounter - 1
1010
1005
  end
1011
1006
  function Unit.create(self, owner, id, x, y, facing, skinId)
1012
1007
  local handle = skinId and BlzCreateUnitWithSkin(
@@ -1134,6 +1129,9 @@ end
1134
1129
  function Unit.prototype.__tostring(self)
1135
1130
  return (((self.constructor.name .. "$") .. util.id2s(self.typeId)) .. "@") .. tostring(getHandleId(self.handle))
1136
1131
  end
1132
+ function Unit.getBySyncId(self, syncId)
1133
+ return unitBySyncId[syncId]
1134
+ end
1137
1135
  __TS__SetDescriptor(
1138
1136
  Unit.prototype,
1139
1137
  "_deltas",
@@ -1391,17 +1389,17 @@ __TS__SetDescriptor(
1391
1389
  "isTeamGlowVisible",
1392
1390
  {
1393
1391
  get = function(self)
1394
- return not self[105]
1392
+ return not self[106]
1395
1393
  end,
1396
1394
  set = function(self, isTeamGlowVisible)
1397
1395
  showUnitTeamGlow(self.handle, isTeamGlowVisible)
1398
- local ____temp_5
1396
+ local ____temp_6
1399
1397
  if not isTeamGlowVisible then
1400
- ____temp_5 = true
1398
+ ____temp_6 = true
1401
1399
  else
1402
- ____temp_5 = nil
1400
+ ____temp_6 = nil
1403
1401
  end
1404
- self[105] = ____temp_5
1402
+ self[106] = ____temp_6
1405
1403
  end
1406
1404
  },
1407
1405
  true
@@ -1411,7 +1409,7 @@ __TS__SetDescriptor(
1411
1409
  "color",
1412
1410
  {set = function(self, color)
1413
1411
  setUnitColor(self.handle, color.handle)
1414
- if self[105] then
1412
+ if self[106] then
1415
1413
  showUnitTeamGlow(self.handle, false)
1416
1414
  end
1417
1415
  end},
@@ -1435,14 +1433,14 @@ __TS__SetDescriptor(
1435
1433
  "maxHealth",
1436
1434
  {
1437
1435
  get = function(self)
1438
- return BlzGetUnitMaxHP(self.handle) - (self[103] or 0) - (self[104] or 0)
1436
+ return BlzGetUnitMaxHP(self.handle) - (self[104] or 0) - (self[105] or 0)
1439
1437
  end,
1440
1438
  set = function(self, maxHealth)
1441
- if maxHealth < 1 and self[102] ~= nil then
1442
- self[103] = (self[103] or 0) + (1 - maxHealth)
1439
+ if maxHealth < 1 and self[103] ~= nil then
1440
+ self[104] = (self[104] or 0) + (1 - maxHealth)
1443
1441
  maxHealth = 1
1444
1442
  end
1445
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[104] or 0))
1443
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1446
1444
  end
1447
1445
  },
1448
1446
  true
@@ -1484,10 +1482,10 @@ __TS__SetDescriptor(
1484
1482
  "health",
1485
1483
  {
1486
1484
  get = function(self)
1487
- return GetWidgetLife(self.handle) - (self[104] or 0)
1485
+ return GetWidgetLife(self.handle) - (self[105] or 0)
1488
1486
  end,
1489
1487
  set = function(self, health)
1490
- SetWidgetLife(self.handle, health + (self[104] or 0))
1488
+ SetWidgetLife(self.handle, health + (self[105] or 0))
1491
1489
  end
1492
1490
  },
1493
1491
  true
@@ -1698,17 +1696,17 @@ __TS__SetDescriptor(
1698
1696
  set = function(self, isPaused)
1699
1697
  local handle = self.handle
1700
1698
  if isPaused and not IsUnitPaused(handle) then
1701
- self[100] = true
1702
- for _ = self[101] or 0, -1 do
1699
+ self[101] = true
1700
+ for _ = self[102] or 0, -1 do
1703
1701
  BlzPauseUnitEx(handle, true)
1704
1702
  end
1705
1703
  PauseUnit(handle, true)
1706
1704
  elseif not isPaused and IsUnitPaused(handle) then
1707
1705
  PauseUnit(handle, false)
1708
- for _ = self[101] or 0, -1 do
1706
+ for _ = self[102] or 0, -1 do
1709
1707
  BlzPauseUnitEx(handle, false)
1710
1708
  end
1711
- self[100] = nil
1709
+ self[101] = nil
1712
1710
  end
1713
1711
  end
1714
1712
  },
@@ -2127,25 +2125,25 @@ Unit.onTargetCast = dispatchId(__TS__New(
2127
2125
  InitializingEvent,
2128
2126
  function(event)
2129
2127
  local function listener(unit, id)
2130
- local ____GetSpellTargetUnit_result_8
2128
+ local ____GetSpellTargetUnit_result_9
2131
2129
  if GetSpellTargetUnit() then
2132
- ____GetSpellTargetUnit_result_8 = ____exports.Unit:of(GetSpellTargetUnit())
2130
+ ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
2133
2131
  else
2134
- local ____GetSpellTargetItem_result_7
2132
+ local ____GetSpellTargetItem_result_8
2135
2133
  if GetSpellTargetItem() then
2136
- ____GetSpellTargetItem_result_7 = Item:of(GetSpellTargetItem())
2134
+ ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
2137
2135
  else
2138
- local ____GetSpellTargetDestructable_result_6
2136
+ local ____GetSpellTargetDestructable_result_7
2139
2137
  if GetSpellTargetDestructable() then
2140
- ____GetSpellTargetDestructable_result_6 = Destructable:of(GetSpellTargetDestructable())
2138
+ ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
2141
2139
  else
2142
- ____GetSpellTargetDestructable_result_6 = nil
2140
+ ____GetSpellTargetDestructable_result_7 = nil
2143
2141
  end
2144
- ____GetSpellTargetItem_result_7 = ____GetSpellTargetDestructable_result_6
2142
+ ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
2145
2143
  end
2146
- ____GetSpellTargetUnit_result_8 = ____GetSpellTargetItem_result_7
2144
+ ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
2147
2145
  end
2148
- local target = ____GetSpellTargetUnit_result_8
2146
+ local target = ____GetSpellTargetUnit_result_9
2149
2147
  if target then
2150
2148
  invoke(event, unit, id, target)
2151
2149
  end
@@ -2472,7 +2470,7 @@ Unit.onDamage = __TS__New(
2472
2470
  invoke(event, source, target, evData)
2473
2471
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2474
2472
  local bonusHealth = math.ceil(evData.amount)
2475
- target[104] = (target[104] or 0) + bonusHealth
2473
+ target[105] = (target[105] or 0) + bonusHealth
2476
2474
  BlzSetUnitMaxHP(
2477
2475
  target.handle,
2478
2476
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2486,7 +2484,7 @@ Unit.onDamage = __TS__New(
2486
2484
  evData[0],
2487
2485
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2488
2486
  )
2489
- target[104] = (target[104] or 0) - bonusHealth
2487
+ target[105] = (target[105] or 0) - bonusHealth
2490
2488
  SetWidgetLife(
2491
2489
  target.handle,
2492
2490
  GetWidgetLife(target.handle) - bonusHealth
@@ -2538,6 +2536,30 @@ Unit.itemStackedEvent = __TS__New(
2538
2536
  EVENT_PLAYER_UNIT_STACK_ITEM,
2539
2537
  function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2540
2538
  )
2539
+ __TS__ObjectDefineProperty(
2540
+ Unit,
2541
+ "itemMovedEvent",
2542
+ {get = function(self)
2543
+ local event = __TS__New(Event)
2544
+ for order = orderId("moveslot0"), orderId("moveslot5") do
2545
+ local slotTo = order - orderId("moveslot0")
2546
+ self.onTargetOrder[order]:addListener(function(unit, item)
2547
+ local slotFrom = unit.items:findSlot(item)
2548
+ if slotFrom ~= nil then
2549
+ invoke(
2550
+ event,
2551
+ unit,
2552
+ item,
2553
+ slotFrom,
2554
+ slotTo
2555
+ )
2556
+ end
2557
+ end)
2558
+ end
2559
+ rawset(self, "itemMovedEvent", event)
2560
+ return event
2561
+ end}
2562
+ )
2541
2563
  __TS__ObjectDefineProperty(
2542
2564
  Unit,
2543
2565
  "onCreate",
@@ -115,7 +115,7 @@ __TS__ObjectDefineProperty(
115
115
  end
116
116
  tableSort(localSelectedUnits, compareUnitsSelectionPriority)
117
117
  local mainSelectedUnitIndex
118
- if selectionButtons then
118
+ if selectionButtons and #localSelectedUnits > 1 then
119
119
  local maxButtonWidth = 0
120
120
  for i = 0, #selectionButtons - 1 do
121
121
  local width = selectionButtons[i + 1].width
@@ -131,8 +131,9 @@ __TS__ObjectDefineProperty(
131
131
  localSelectedUnits[i] = nil
132
132
  end
133
133
  if mainSelectedUnitChangeEvent ~= nil and mainSelectedUnit ~= previousMainSelectedUnit then
134
- Event.invoke(mainSelectedUnitChangeEvent, previousMainSelectedUnit, mainSelectedUnit)
134
+ local previousPreviousMainSelectedUnit = previousMainSelectedUnit
135
135
  previousMainSelectedUnit = mainSelectedUnit
136
+ Event.invoke(mainSelectedUnitChangeEvent, previousPreviousMainSelectedUnit, previousMainSelectedUnit)
136
137
  end
137
138
  return mainSelectedUnit
138
139
  end}
@@ -4,5 +4,9 @@ export declare const enum SoundPresetName {
4
4
  ABOMINATION_PISSED = "AbominationPissed",
5
5
  ABOMINATION_READY = "AbominationReady",
6
6
  ABOMINATION_WAR_CRY = "AbominationWarcry",
7
- AXE_MEDIUM_CHOP_WOOD = "AxeMediumChopWood"
7
+ AXE_MEDIUM_CHOP_WOOD = "AxeMediumChopWood",
8
+ IMPALE = "Impale",
9
+ IMPALE_HIT = "ImpaleHit",
10
+ IMPALE_LAND = "ImpaleLand",
11
+ IMPALE_CAST = "ImpaleCast"
8
12
  }
package/engine/unit.d.ts CHANGED
@@ -16,6 +16,7 @@ import "./internal/unit-missile-launch";
16
16
  import "./internal/unit/ghost-counter";
17
17
  import "./internal/unit/invulnerability-counter";
18
18
  import "./internal/unit/detach-missiles";
19
+ import "./internal/unit/main-selected";
19
20
  import "./internal/unit/band-aids/ancestral-spirit-cannibalize";
20
21
  export { Unit, DamagingEvent, DamageEvent } from "./internal/unit";
21
22
  export * from "./internal/unit+damage";
package/engine/unit.lua CHANGED
@@ -16,6 +16,7 @@ require("engine.internal.unit-missile-launch")
16
16
  require("engine.internal.unit.ghost-counter")
17
17
  require("engine.internal.unit.invulnerability-counter")
18
18
  require("engine.internal.unit.detach-missiles")
19
+ require("engine.internal.unit.main-selected")
19
20
  require("engine.internal.unit.band-aids.ancestral-spirit-cannibalize")
20
21
  do
21
22
  local ____unit = require("engine.internal.unit")
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.1a5c0c0",
4
+ "version": "0.0.1-dev.1b0add9",
5
5
  "description": "A typescript library for Warcraft III using Warpack.",
6
6
  "keywords": [
7
7
  "warcraft",
@@ -32,7 +32,10 @@ export declare const flatMapToLuaSet: {
32
32
  };
33
33
  export declare const mapIndexed: <T, R>(array: readonly T[], transform: (index: number, value: T) => R) => R[];
34
34
  export declare const associate: <T, K extends AnyNotNil, V>(array: readonly T[], keySelector: (value: T) => K, valueSelector: (value: T) => V) => LuaMap<K, V>;
35
- export declare const associateBy: <K extends AnyNotNil, V>(array: readonly V[], keySelector: (value: V) => K) => LuaMap<K, V>;
35
+ export declare const associateBy: {
36
+ <K extends AnyNotNil, V>(array: readonly V[], keySelector: (value: V) => K): LuaMap<K, V>;
37
+ <K extends KeysOfType<V, AnyNotNil>, V>(array: readonly V[], keySelector: K): LuaMap<V[K] extends AnyNotNil ? V[K] : never, V>;
38
+ };
36
39
  export declare const associateByIndexed: <K extends AnyNotNil, V>(array: readonly V[], keySelector: (index: number, value: V) => K) => LuaMap<K, V>;
37
40
  export declare const associateWith: <K extends AnyNotNil, V>(array: readonly K[], valueSelector: (value: K) => V) => LuaMap<K, V>;
38
41
  export declare const associateWithIndexed: <K extends AnyNotNil, V>(array: readonly K[], valueSelector: (index: number, value: K) => V) => LuaMap<K, V>;
@@ -41,6 +44,10 @@ export declare const average: (array: readonly number[]) => number;
41
44
  export declare const sum: (array: readonly number[]) => number;
42
45
  export declare const product: (array: readonly number[]) => number;
43
46
  export declare const max: (array: readonly number[]) => number;
47
+ export declare const maxBy: {
48
+ <T, Args extends any[]>(array: readonly T[], selector: (value: T, ...args: Args) => number, ...args: Args): T | undefined;
49
+ <T, K extends KeysOfType<T, number>>(array: readonly T[], key: K): T | undefined;
50
+ };
44
51
  export declare const intersperse: <T>(array: readonly T[], delimiter: T) => T[];
45
52
  export declare const zip: <T, R, V>(array: readonly T[], otherArray: readonly R[], transform: (value: T, otherValue: R) => V) => V[];
46
53
  export declare const chunked: <T>(array: readonly T[], size: number) => T[][];
@@ -178,9 +178,16 @@ ____exports.associate = function(array, keySelector, valueSelector)
178
178
  end
179
179
  ____exports.associateBy = function(array, keySelector)
180
180
  local result = {}
181
- for i = 1, #array do
182
- local value = array[i]
183
- result[keySelector(value)] = value
181
+ if type(keySelector) == "function" then
182
+ for i = 1, #array do
183
+ local value = array[i]
184
+ result[keySelector(value)] = value
185
+ end
186
+ else
187
+ for i = 1, #array do
188
+ local value = array[i]
189
+ result[value[keySelector]] = value
190
+ end
184
191
  end
185
192
  return result
186
193
  end
@@ -251,6 +258,30 @@ ____exports.max = function(array)
251
258
  end
252
259
  return mathMax(table.unpack(array))
253
260
  end
261
+ ____exports.maxBy = function(array, selector, ...)
262
+ local result = nil
263
+ local maxValue = -math.huge
264
+ if type(selector) == "function" then
265
+ for i = 1, #array do
266
+ local element = array[i]
267
+ local value = selector(element, ...)
268
+ if value > maxValue then
269
+ result = element
270
+ maxValue = value
271
+ end
272
+ end
273
+ else
274
+ for i = 1, #array do
275
+ local element = array[i]
276
+ local value = element[selector]
277
+ if value > maxValue then
278
+ result = element
279
+ maxValue = value
280
+ end
281
+ end
282
+ end
283
+ return result
284
+ end
254
285
  ____exports.intersperse = function(array, delimiter)
255
286
  local result = {}
256
287
  local length = #array