warscript 0.0.1-dev.099f0af → 0.0.1-dev.0b2f1d6

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.
@@ -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,
@@ -108,6 +111,7 @@ export declare class Frame extends Handle<jframehandle> {
108
111
  enable(): void;
109
112
  addText(text: string): void;
110
113
  clearAllPoints(): void;
114
+ get children(): Frame[];
111
115
  getChild(index: number): Frame;
112
116
  getChildrenCount(): number;
113
117
  setSize(width: number, height: number): void;
@@ -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",
@@ -720,6 +779,18 @@ __TS__SetDescriptor(
720
779
  end},
721
780
  true
722
781
  )
782
+ __TS__SetDescriptor(
783
+ Frame.prototype,
784
+ "children",
785
+ {get = function(self)
786
+ local children = {}
787
+ for i = 0, self:getChildrenCount() - 1 do
788
+ children[i + 1] = self:getChild(i)
789
+ end
790
+ return children
791
+ end},
792
+ true
793
+ )
723
794
  __TS__ObjectDefineProperty(
724
795
  Frame,
725
796
  "onKeyPress",
package/core/util.d.ts CHANGED
@@ -54,7 +54,7 @@ declare global {
54
54
  function fourCC(id: string): number;
55
55
  }
56
56
  declare namespace inner {
57
- const orderId: (id: "blink" | "stop" | "load" | "sleep" | "absorb" | "acidbomb" | "acolyteharvest" | "ambush" | "ancestralspirit" | "ancestralspirittarget" | "animatedead" | "antimagicshell" | "attack" | "attackground" | "attackonce" | "attributemodskill" | "auraunholy" | "auravampiric" | "autodispel" | "autodispeloff" | "autodispelon" | "autoentangle" | "autoentangleinstant" | "autoharvestgold" | "autoharvestlumber" | "avatar" | "avengerform" | "awaken" | "banish" | "barkskin" | "barkskinoff" | "barkskinon" | "battleroar" | "battlestations" | "bearform" | "berserk" | "blackarrow" | "blackarrowoff" | "blackarrowon" | "blight" | "blizzard" | "bloodlust" | "bloodlustoff" | "bloodluston" | "board" | "breathoffire" | "breathoffrost" | "build" | "burrow" | "cannibalize" | "carrionscarabs" | "carrionscarabsinstant" | "carrionscarabsoff" | "carrionscarabson" | "carrionswarm" | "chainlightning" | "channel" | "charm" | "chemicalrage" | "cloudoffog" | "clusterrockets" | "coldarrows" | "coldarrowstarg" | "controlmagic" | "corporealform" | "corrosivebreath" | "coupleinstant" | "coupletarget" | "creepanimatedead" | "creepdevour" | "creepheal" | "creephealoff" | "creephealon" | "creepthunderbolt" | "creepthunderclap" | "cripple" | "curse" | "curseoff" | "curseon" | "cyclone" | "darkconversion" | "darkportal" | "darkritual" | "darksummoning" | "deathanddecay" | "deathcoil" | "deathpact" | "decouple" | "defend" | "detectaoe" | "detonate" | "devour" | "devourmagic" | "disassociate" | "disenchant" | "dismount" | "dispel" | "divineshield" | "doom" | "drain" | "dreadlordinferno" | "dropitem" | "drunkenhaze" | "earthquake" | "eattree" | "elementalfury" | "ensnare" | "ensnareoff" | "ensnareon" | "entangle" | "entangleinstant" | "entanglingroots" | "etherealform" | "evileye" | "faeriefire" | "faeriefireoff" | "faeriefireon" | "fanofknives" | "farsight" | "fingerofdeath" | "firebolt" | "flamestrike" | "flamingarrows" | "flamingarrowstarg" | "flamingattack" | "flamingattacktarg" | "flare" | "forceboard" | "forceofnature" | "forkedlightning" | "freezingbreath" | "frenzy" | "frenzyoff" | "frenzyon" | "frostarmor" | "frostarmoroff" | "frostarmoron" | "frostnova" | "getitem" | "gold2lumber" | "grabtree" | "harvest" | "heal" | "healingspray" | "healingward" | "healingwave" | "healoff" | "healon" | "hex" | "holdposition" | "holybolt" | "howlofterror" | "humanbuild" | "immolation" | "impale" | "incineratearrow" | "incineratearrowoff" | "incineratearrowon" | "inferno" | "innerfire" | "innerfireoff" | "innerfireon" | "instant" | "invisibility" | "lavamonster" | "lightningshield" | "loadarcher" | "loadcorpse" | "loadcorpseinstant" | "locustswarm" | "lumber2gold" | "magicdefense" | "magicleash" | "magicundefense" | "manaburn" | "manaflareoff" | "manaflareon" | "manashieldoff" | "manashieldon" | "massteleport" | "mechanicalcritter" | "metamorphosis" | "militia" | "militiaconvert" | "militiaoff" | "militiaunconvert" | "mindrot" | "mirrorimage" | "monsoon" | "mount" | "mounthippogryph" | "move" | "moveAI" | "nagabuild" | "neutraldetectaoe" | "neutralinteract" | "neutralspell" | "nightelfbuild" | "orcbuild" | "parasite" | "parasiteoff" | "parasiteon" | "patrol" | "patrolAI" | "phaseshift" | "phaseshiftinstant" | "phaseshiftoff" | "phaseshifton" | "phoenixfire" | "phoenixmorph" | "poisonarrows" | "poisonarrowstarg" | "polymorph" | "possession" | "preservation" | "purge" | "rainofchaos" | "rainoffire" | "raisedead" | "raisedeadoff" | "raisedeadon" | "ravenform" | "recharge" | "rechargeoff" | "rechargeon" | "rejuvination" | "renew" | "renewoff" | "renewon" | "repair" | "repairoff" | "repairon" | "replenish" | "replenishlife" | "replenishlifeoff" | "replenishlifeon" | "replenishmana" | "replenishmanaoff" | "replenishmanaon" | "replenishoff" | "replenishon" | "request_hero" | "requestsacrifice" | "restoration" | "restorationoff" | "restorationon" | "resumebuild" | "resumeharvesting" | "resurrection" | "returnresources" | "revenge" | "revive" | "roar" | "robogoblin" | "root" | "sacrifice" | "sanctuary" | "scout" | "selfdestruct" | "selfdestructoff" | "selfdestructon" | "sentinel" | "follow" | "smart" | "setrally" | "shadowsight" | "shadowstrike" | "shockwave" | "silence" | "slow" | "slowoff" | "slowon" | "soulburn" | "soulpreservation" | "spellshield" | "spellshieldaoe" | "spellsteal" | "spellstealoff" | "spellstealon" | "spies" | "spiritlink" | "spiritofvengeance" | "spirittroll" | "spiritwolf" | "stampede" | "standdown" | "starfall" | "stasistrap" | "steal" | "stomp" | "stoneform" | "stunned" | "submerge" | "summonfactory" | "summongrizzly" | "summonphoenix" | "summonquillbeast" | "summonwareagle" | "tankdroppilot" | "tankloadpilot" | "tankpilot" | "taunt" | "thunderbolt" | "thunderclap" | "tornado" | "townbelloff" | "townbellon" | "tranquility" | "transmute" | "unavatar" | "unavengerform" | "unbearform" | "unburrow" | "uncoldarrows" | "uncorporealform" | "undeadbuild" | "undefend" | "undivineshield" | "unetherealform" | "unflamingarrows" | "unflamingattack" | "unholyfrenzy" | "unimmolation" | "unload" | "unloadall" | "unloadallcorpses" | "unloadallinstant" | "unpoisonarrows" | "unravenform" | "unrobogoblin" | "unroot" | "unstableconcoction" | "unstoneform" | "unsubmerge" | "unsummon" | "unwindwalk" | "vengeance" | "vengeanceinstant" | "vengeanceoff" | "vengeanceon" | "volcano" | "voodoo" | "ward" | "waterelemental" | "wateryminion" | "web" | "weboff" | "webon" | "whirlwind" | "windwalk" | "wispharvest") => number;
57
+ const orderId: (id: "blink" | "stop" | "load" | "sleep" | "absorb" | "acidbomb" | "acolyteharvest" | "ambush" | "ancestralspirit" | "ancestralspirittarget" | "animatedead" | "antimagicshell" | "attack" | "attackground" | "attackonce" | "attributemodskill" | "auraunholy" | "auravampiric" | "autodispel" | "autodispeloff" | "autodispelon" | "autoentangle" | "autoentangleinstant" | "autoharvestgold" | "autoharvestlumber" | "avatar" | "avengerform" | "awaken" | "banish" | "barkskin" | "barkskinoff" | "barkskinon" | "battleroar" | "battlestations" | "bearform" | "berserk" | "blackarrow" | "blackarrowoff" | "blackarrowon" | "blight" | "blizzard" | "bloodlust" | "bloodlustoff" | "bloodluston" | "board" | "breathoffire" | "breathoffrost" | "build" | "burrow" | "cannibalize" | "carrionscarabs" | "carrionscarabsinstant" | "carrionscarabsoff" | "carrionscarabson" | "carrionswarm" | "chainlightning" | "channel" | "charm" | "chemicalrage" | "cloudoffog" | "clusterrockets" | "coldarrows" | "coldarrowstarg" | "controlmagic" | "corporealform" | "corrosivebreath" | "coupleinstant" | "coupletarget" | "creepanimatedead" | "creepdevour" | "creepheal" | "creephealoff" | "creephealon" | "creepthunderbolt" | "creepthunderclap" | "cripple" | "curse" | "curseoff" | "curseon" | "cyclone" | "darkconversion" | "darkportal" | "darkritual" | "darksummoning" | "deathanddecay" | "deathcoil" | "deathpact" | "decouple" | "defend" | "detectaoe" | "detonate" | "devour" | "devourmagic" | "disassociate" | "disenchant" | "dismount" | "dispel" | "divineshield" | "doom" | "drain" | "dreadlordinferno" | "dropitem" | "moveslot0" | "moveslot1" | "moveslot2" | "moveslot3" | "moveslot4" | "moveslot5" | "drunkenhaze" | "earthquake" | "eattree" | "elementalfury" | "ensnare" | "ensnareoff" | "ensnareon" | "entangle" | "entangleinstant" | "entanglingroots" | "etherealform" | "evileye" | "faeriefire" | "faeriefireoff" | "faeriefireon" | "fanofknives" | "farsight" | "fingerofdeath" | "firebolt" | "flamestrike" | "flamingarrows" | "flamingarrowstarg" | "flamingattack" | "flamingattacktarg" | "flare" | "forceboard" | "forceofnature" | "forkedlightning" | "freezingbreath" | "frenzy" | "frenzyoff" | "frenzyon" | "frostarmor" | "frostarmoroff" | "frostarmoron" | "frostnova" | "getitem" | "gold2lumber" | "grabtree" | "harvest" | "heal" | "healingspray" | "healingward" | "healingwave" | "healoff" | "healon" | "hex" | "holdposition" | "holybolt" | "howlofterror" | "humanbuild" | "immolation" | "impale" | "incineratearrow" | "incineratearrowoff" | "incineratearrowon" | "inferno" | "innerfire" | "innerfireoff" | "innerfireon" | "instant" | "invisibility" | "lavamonster" | "lightningshield" | "loadarcher" | "loadcorpse" | "loadcorpseinstant" | "locustswarm" | "lumber2gold" | "magicdefense" | "magicleash" | "magicundefense" | "manaburn" | "manaflareoff" | "manaflareon" | "manashieldoff" | "manashieldon" | "massteleport" | "mechanicalcritter" | "metamorphosis" | "militia" | "militiaconvert" | "militiaoff" | "militiaunconvert" | "mindrot" | "mirrorimage" | "monsoon" | "mount" | "mounthippogryph" | "move" | "moveAI" | "nagabuild" | "neutraldetectaoe" | "neutralinteract" | "neutralspell" | "nightelfbuild" | "orcbuild" | "parasite" | "parasiteoff" | "parasiteon" | "patrol" | "patrolAI" | "phaseshift" | "phaseshiftinstant" | "phaseshiftoff" | "phaseshifton" | "phoenixfire" | "phoenixmorph" | "poisonarrows" | "poisonarrowstarg" | "polymorph" | "possession" | "preservation" | "purge" | "rainofchaos" | "rainoffire" | "raisedead" | "raisedeadoff" | "raisedeadon" | "ravenform" | "recharge" | "rechargeoff" | "rechargeon" | "rejuvination" | "renew" | "renewoff" | "renewon" | "repair" | "repairoff" | "repairon" | "replenish" | "replenishlife" | "replenishlifeoff" | "replenishlifeon" | "replenishmana" | "replenishmanaoff" | "replenishmanaon" | "replenishoff" | "replenishon" | "request_hero" | "requestsacrifice" | "restoration" | "restorationoff" | "restorationon" | "resumebuild" | "resumeharvesting" | "resurrection" | "returnresources" | "revenge" | "revive" | "roar" | "robogoblin" | "root" | "sacrifice" | "sanctuary" | "scout" | "selfdestruct" | "selfdestructoff" | "selfdestructon" | "sentinel" | "follow" | "smart" | "setrally" | "shadowsight" | "shadowstrike" | "shockwave" | "silence" | "slow" | "slowoff" | "slowon" | "soulburn" | "soulpreservation" | "spellshield" | "spellshieldaoe" | "spellsteal" | "spellstealoff" | "spellstealon" | "spies" | "spiritlink" | "spiritofvengeance" | "spirittroll" | "spiritwolf" | "stampede" | "standdown" | "starfall" | "stasistrap" | "steal" | "stomp" | "stoneform" | "stunned" | "submerge" | "summonfactory" | "summongrizzly" | "summonphoenix" | "summonquillbeast" | "summonwareagle" | "tankdroppilot" | "tankloadpilot" | "tankpilot" | "taunt" | "thunderbolt" | "thunderclap" | "tornado" | "townbelloff" | "townbellon" | "tranquility" | "transmute" | "unavatar" | "unavengerform" | "unbearform" | "unburrow" | "uncoldarrows" | "uncorporealform" | "undeadbuild" | "undefend" | "undivineshield" | "unetherealform" | "unflamingarrows" | "unflamingattack" | "unholyfrenzy" | "unimmolation" | "unload" | "unloadall" | "unloadallcorpses" | "unloadallinstant" | "unpoisonarrows" | "unravenform" | "unrobogoblin" | "unroot" | "unstableconcoction" | "unstoneform" | "unsubmerge" | "unsummon" | "unwindwalk" | "vengeance" | "vengeanceinstant" | "vengeanceoff" | "vengeanceon" | "volcano" | "voodoo" | "ward" | "waterelemental" | "wateryminion" | "web" | "weboff" | "webon" | "whirlwind" | "windwalk" | "wispharvest") => number;
58
58
  }
59
59
  declare global {
60
60
  function orderId(...args: Parameters<typeof inner.orderId>): ReturnType<typeof inner.orderId>;
package/core/util.lua CHANGED
@@ -196,6 +196,12 @@ do
196
196
  drain = 852487,
197
197
  dreadlordinferno = 852224,
198
198
  dropitem = 852001,
199
+ moveslot0 = 852002,
200
+ moveslot1 = 852003,
201
+ moveslot2 = 852004,
202
+ moveslot3 = 852005,
203
+ moveslot4 = 852006,
204
+ moveslot5 = 852007,
199
205
  drunkenhaze = 852585,
200
206
  earthquake = 852121,
201
207
  eattree = 852146,
@@ -17,9 +17,9 @@ export declare abstract class Behavior<T extends AnyNotNil, PeriodicActionParame
17
17
  protected startPeriodicAction(interval: number, ...parameters: PeriodicActionParameters): void;
18
18
  protected stopPeriodicAction(): void;
19
19
  static count<T extends Behavior<AnyNotNil>, ConstructorParameters extends any[]>(this: BehaviorConstructor<T, ConstructorParameters>, object: T extends Behavior<infer Object> ? Object : never, limit?: number): number;
20
- static getFirst<T extends Behavior<AnyNotNil>, ConstructorParameters extends any[], Count extends [number] | []>(this: BehaviorConstructor<T, ConstructorParameters>, object: T extends Behavior<infer Object> ? Object : never, ...[count]: Count): Count extends [number] ? T[] : T | undefined;
20
+ static getFirst<T extends Behavior<AnyNotNil>, ConstructorParameters extends any[], CountOrPredicate extends [number] | [] | [(behavior: T, ...args: PredicateArgs) => boolean, ...PredicateArgs], PredicateArgs extends any[]>(this: BehaviorConstructor<T, ConstructorParameters>, object: T extends Behavior<infer Object> ? Object : never, ...[countOrPredicate]: CountOrPredicate): CountOrPredicate extends [number] ? T[] : T | undefined;
21
21
  static getLast<T extends Behavior<AnyNotNil>, ConstructorParameters extends any[]>(this: BehaviorConstructor<T, ConstructorParameters>, object: T extends Behavior<infer Object> ? Object : never): T | undefined;
22
- static getAll<T extends Behavior<AnyNotNil>, ConstructorParameters extends any[]>(this: BehaviorConstructor<T, ConstructorParameters>, object: T extends Behavior<infer Object> ? Object : never): T[];
22
+ static getAll<T extends Behavior<AnyNotNil>, ConstructorParameters extends any[], PredicateArgs extends any[]>(this: BehaviorConstructor<T, ConstructorParameters>, object: T extends Behavior<infer Object> ? Object : never, predicate?: (this: void, behavior: T, ...args: PredicateArgs) => boolean, ...predicateArgs: PredicateArgs): T[];
23
23
  static forFirst<T extends Behavior<AnyNotNil>, ConstructorParameters extends any[], ConsumerParameters extends any[]>(this: BehaviorConstructor<T, ConstructorParameters>, object: T extends Behavior<infer Object> ? Object : never, count: number, consumer: (this: void, behavior: T, ...parameters: ConsumerParameters) => any, ...parameters: ConsumerParameters): number;
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;
@@ -83,11 +83,11 @@ function Behavior.count(self, object, limit)
83
83
  end
84
84
  return behaviorsCount
85
85
  end
86
- function Behavior.getFirst(self, object, count)
86
+ function Behavior.getFirst(self, object, countOrPredicate, ...)
87
87
  local behavior = firstBehaviorByObject[object]
88
- if count == nil then
88
+ if type(countOrPredicate) ~= "number" then
89
89
  while behavior ~= nil do
90
- if __TS__InstanceOf(behavior, self) then
90
+ if __TS__InstanceOf(behavior, self) and (countOrPredicate == nil or countOrPredicate(behavior, ...)) then
91
91
  return behavior
92
92
  end
93
93
  behavior = behavior[1]
@@ -96,7 +96,7 @@ function Behavior.getFirst(self, object, count)
96
96
  end
97
97
  local behaviors = {}
98
98
  local behaviorsCount = 0
99
- while behavior ~= nil and behaviorsCount < count do
99
+ while behavior ~= nil and behaviorsCount < countOrPredicate do
100
100
  if __TS__InstanceOf(behavior, self) then
101
101
  behaviorsCount = behaviorsCount + 1
102
102
  behaviors[behaviorsCount] = behavior
@@ -115,12 +115,12 @@ function Behavior.getLast(self, object)
115
115
  end
116
116
  return nil
117
117
  end
118
- function Behavior.getAll(self, object)
118
+ function Behavior.getAll(self, object, predicate, ...)
119
119
  local behaviors = {}
120
120
  local behaviorsCount = 0
121
121
  local behavior = firstBehaviorByObject[object]
122
122
  while behavior ~= nil do
123
- if __TS__InstanceOf(behavior, self) then
123
+ if __TS__InstanceOf(behavior, self) and (predicate == nil or predicate(behavior, ...)) then
124
124
  behaviorsCount = behaviorsCount + 1
125
125
  behaviors[behaviorsCount] = behavior
126
126
  end
@@ -4,14 +4,6 @@ import { Event } from "../../event";
4
4
  import type { Item } from "../../core/types/item";
5
5
  import type { Unit } from "./unit";
6
6
  import type { AbilityTypeId } from "../object-data/entry/ability-type";
7
- interface Fields<K, V> {
8
- set(field: K, value: V): boolean;
9
- get(field: K): V;
10
- has(field: K): boolean;
11
- }
12
- interface AbilityLevel {
13
- realFields: Fields<jabilityreallevelfield, number>;
14
- }
15
7
  export type jabilityfield = jabilityintegerfield | jabilityrealfield | jabilitybooleanfield | jabilitystringfield | jabilityintegerlevelfield | jabilityreallevelfield | jabilitybooleanlevelfield | jabilitystringlevelfield;
16
8
  export declare class AbilitySnapshot {
17
9
  }
@@ -40,8 +32,7 @@ export declare abstract class Ability extends Handle<jability> {
40
32
  setField(field: jabilityintegerlevelfield | jabilityreallevelfield, level: number, value: number): boolean;
41
33
  setField(field: jabilitybooleanlevelfield, level: number, value: boolean): boolean;
42
34
  setField(field: jabilitystringlevelfield, level: number, value: string): boolean;
43
- get realFields(): Fields<jabilityrealfield, number>;
44
- get levels(): readonly AbilityLevel[];
35
+ get levelCount(): number;
45
36
  abstract get level(): number;
46
37
  static get onCreate(): Event<[Ability]>;
47
38
  static get destroyEvent(): Event<[Ability]>;
@@ -58,6 +49,8 @@ export declare class UnitAbility extends Ability {
58
49
  readonly owner: Unit;
59
50
  private readonly u;
60
51
  constructor(handle: jability, typeId: number, owner: Unit);
52
+ incrementHideCounter(): void;
53
+ decrementHideCounter(): void;
61
54
  get level(): number;
62
55
  set level(v: number);
63
56
  get cooldownRemaining(): number;
@@ -88,4 +81,3 @@ export declare class ItemAbility extends Ability {
88
81
  static get onCreate(): Event<[ItemAbility]>;
89
82
  static get onDestroy(): Event<[ItemAbility]>;
90
83
  }
91
- export {};
@@ -2,7 +2,6 @@ local ____lualib = require("lualib_bundle")
2
2
  local __TS__ArrayMap = ____lualib.__TS__ArrayMap
3
3
  local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
4
4
  local __TS__Class = ____lualib.__TS__Class
5
- local __TS__New = ____lualib.__TS__New
6
5
  local __TS__ClassExtends = ____lualib.__TS__ClassExtends
7
6
  local __TS__InstanceOf = ____lualib.__TS__InstanceOf
8
7
  local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
@@ -33,7 +32,7 @@ local getAbilityStringLevelField = BlzGetAbilityStringLevelField
33
32
  local getUnitAbilityCooldownRemaining = BlzGetUnitAbilityCooldownRemaining
34
33
  local startUnitAbilityCooldown = BlzStartUnitAbilityCooldown
35
34
  local getHandleId = GetHandleId
36
- local getItemAbility = BlzGetItemAbility
35
+ local unitHideAbility = BlzUnitHideAbility
37
36
  local match = string.match
38
37
  local ____type = _G.type
39
38
  local ____tostring = _G.tostring
@@ -151,55 +150,6 @@ local orders = postcompile(function()
151
150
  end
152
151
  return orders
153
152
  end)
154
- local RealFields = __TS__Class()
155
- RealFields.name = "RealFields"
156
- function RealFields.prototype.____constructor(self, handle)
157
- self.handle = handle
158
- end
159
- function RealFields.prototype.set(self, field, value)
160
- return BlzSetAbilityRealField(self.handle, field, value)
161
- end
162
- function RealFields.prototype.get(self, field)
163
- return BlzGetAbilityRealField(self.handle, field)
164
- end
165
- function RealFields.prototype.has(self, field)
166
- local handle = self.handle
167
- return BlzSetAbilityRealField(
168
- handle,
169
- field,
170
- BlzGetAbilityRealField(handle, field)
171
- )
172
- end
173
- local RealLevelFields = __TS__Class()
174
- RealLevelFields.name = "RealLevelFields"
175
- function RealLevelFields.prototype.____constructor(self, handle, level)
176
- self.handle = handle
177
- self.level = level
178
- end
179
- function RealLevelFields.prototype.set(self, field, value)
180
- return BlzSetAbilityRealLevelField(self.handle, field, self.level, value)
181
- end
182
- function RealLevelFields.prototype.get(self, field)
183
- return BlzGetAbilityRealLevelField(self.handle, field, self.level)
184
- end
185
- function RealLevelFields.prototype.has(self, field)
186
- local handle = self.handle
187
- return BlzSetAbilityRealLevelField(
188
- handle,
189
- field,
190
- 0,
191
- BlzGetAbilityRealLevelField(handle, field, 0)
192
- )
193
- end
194
- local realLevelMetatable = {__index = self}
195
- local levelDescriptors = {realFields = function(self, handle, level)
196
- return __TS__New(RealLevelFields, handle, level)
197
- end}
198
- local levelMetatable = {__index = function(self, key)
199
- local fields = levelDescriptors[key](levelDescriptors, self.handle, self.level)
200
- rawset(self, key, fields)
201
- return fields
202
- end}
203
153
  local fieldGetters = {
204
154
  abilityintegerfield = function(ability, field)
205
155
  return getAbilityIntegerField(ability.handle, field)
@@ -355,34 +305,9 @@ __TS__SetDescriptor(
355
305
  )
356
306
  __TS__SetDescriptor(
357
307
  Ability.prototype,
358
- "realFields",
359
- {get = function(self)
360
- local realFields = __TS__New(RealFields, self.handle)
361
- rawset(self, "realFields", realFields)
362
- return realFields
363
- end},
364
- true
365
- )
366
- __TS__SetDescriptor(
367
- Ability.prototype,
368
- "levels",
308
+ "levelCount",
369
309
  {get = function(self)
370
- local handle = self.handle
371
- local levels = setmetatable(
372
- {},
373
- {
374
- __len = function(self)
375
- return BlzGetAbilityIntegerField(handle, ABILITY_IF_LEVELS)
376
- end,
377
- __index = function(self, i)
378
- local level = setmetatable({handle = handle, level = i - 1}, levelMetatable)
379
- self[i] = level
380
- return level
381
- end
382
- }
383
- )
384
- rawset(self, "levels", levels)
385
- return levels
310
+ return self:getField(ABILITY_IF_LEVELS)
386
311
  end},
387
312
  true
388
313
  )
@@ -433,6 +358,12 @@ function UnitAbility.prototype.____constructor(self, handle, typeId, owner)
433
358
  self.owner = owner
434
359
  self.u = owner.handle
435
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
436
367
  __TS__SetDescriptor(
437
368
  UnitAbility.prototype,
438
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,9 +11,11 @@ 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;
18
+ protected __ipairs(): LuaIterator<LuaMultiReturn<[number, Item | undefined]>, junit>;
17
19
  }
18
20
  declare module "../unit" {
19
21
  interface Unit {
@@ -17,12 +17,29 @@ local unitInventorySize = UnitInventorySize
17
17
  local unitItemInSlot = UnitItemInSlot
18
18
  local unitRemoveItemFromSlot = UnitRemoveItemFromSlot
19
19
  local handleByUnitItems = setmetatable({}, {__mode = "k"})
20
+ local function unitItemsNext(handle, index)
21
+ local slot = index & 7
22
+ if index >> 3 == slot then
23
+ return nil, nil
24
+ end
25
+ return index + 1, Item:of(unitItemInSlot(handle, slot))
26
+ end
20
27
  ____exports.UnitItems = __TS__Class()
21
28
  local UnitItems = ____exports.UnitItems
22
29
  UnitItems.name = "UnitItems"
23
30
  function UnitItems.prototype.____constructor(self, handle)
24
31
  handleByUnitItems[self] = handle
25
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
26
43
  function UnitItems.prototype.__newindex(self, slot, item)
27
44
  local handle = handleByUnitItems[self]
28
45
  if slot < 1 or slot > unitInventorySize(handle) then
@@ -51,6 +68,10 @@ end
51
68
  function UnitItems.prototype.__len(self)
52
69
  return unitInventorySize(handleByUnitItems[self])
53
70
  end
71
+ function UnitItems.prototype.__ipairs(self)
72
+ local handle = handleByUnitItems[self]
73
+ return unitItemsNext, handle, unitInventorySize(handle) << 3
74
+ end
54
75
  __TS__ObjectDefineProperty(
55
76
  Unit.prototype,
56
77
  "items",
@@ -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
@@ -7,14 +7,33 @@ local ____event = require("event")
7
7
  local Event = ____event.Event
8
8
  local ____timer = require("core.types.timer")
9
9
  local Timer = ____timer.Timer
10
+ local ____lua_2Dsets = require("utility.lua-sets")
11
+ local luaSetOf = ____lua_2Dsets.luaSetOf
10
12
  local autoAttackFinishEvent = __TS__New(Event)
11
13
  rawset(Unit, "autoAttackFinishEvent", autoAttackFinishEvent)
12
14
  local eventTimerByUnit = {}
13
- local function reset(source)
14
- local eventTimer = eventTimerByUnit[source]
15
- if eventTimer then
16
- eventTimer:destroy()
17
- eventTimerByUnit[source] = nil
15
+ local instantOrderIds = luaSetOf(
16
+ orderId("avatar"),
17
+ orderId("berserk"),
18
+ orderId("divineshield"),
19
+ orderId("immolation"),
20
+ orderId("moveslot0"),
21
+ orderId("moveslot1"),
22
+ orderId("moveslot2"),
23
+ orderId("moveslot3"),
24
+ orderId("moveslot4"),
25
+ orderId("moveslot5"),
26
+ orderId("unavatar"),
27
+ orderId("undivineshield"),
28
+ orderId("unimmolation")
29
+ )
30
+ local function reset(source, orderId)
31
+ if not (instantOrderIds[orderId] ~= nil) then
32
+ local eventTimer = eventTimerByUnit[source]
33
+ if eventTimer then
34
+ eventTimer:destroy()
35
+ eventTimerByUnit[source] = nil
36
+ end
18
37
  end
19
38
  end
20
39
  Unit.onImmediateOrder:addListener(reset)
@@ -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]?;
@@ -288,7 +293,7 @@ export declare class Unit extends Handle<junit> {
288
293
  static getInRange(x: number, y: number, range: number, predicate?: (unit: Unit) => boolean): Unit[];
289
294
  static getInCollisionRange(x: number, y: number, range: number, predicate?: (unit: Unit) => boolean): Unit[];
290
295
  static getInSector(pos: Vec2, range: number, offsetAngle: number, centralAngle: number): Unit[];
291
- static getSelectionOf(player: Player): Unit[];
296
+ static getSelectionOf(player: Player, target?: Unit[]): Unit[];
292
297
  static readonly deathEvent: UnitTriggerEvent<[Unit]>;
293
298
  static readonly onDecay: UnitTriggerEvent<[]>;
294
299
  static readonly onResurrect: InitializingEvent<[Unit], void>;
@@ -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(
@@ -1108,8 +1103,11 @@ function Unit.getInSector(self, pos, range, offsetAngle, centralAngle)
1108
1103
  )
1109
1104
  return targetCollection
1110
1105
  end
1111
- function Unit.getSelectionOf(self, player)
1112
- targetCollection = {}
1106
+ function Unit.getSelectionOf(self, player, target)
1107
+ if target == nil then
1108
+ target = {}
1109
+ end
1110
+ targetCollection = target
1113
1111
  targetCollectionNextIndex = 1
1114
1112
  GroupEnumUnitsSelected(dummyGroup, player.handle, collectIntoTarget)
1115
1113
  return targetCollection
@@ -1131,6 +1129,9 @@ end
1131
1129
  function Unit.prototype.__tostring(self)
1132
1130
  return (((self.constructor.name .. "$") .. util.id2s(self.typeId)) .. "@") .. tostring(getHandleId(self.handle))
1133
1131
  end
1132
+ function Unit.getBySyncId(self, syncId)
1133
+ return unitBySyncId[syncId]
1134
+ end
1134
1135
  __TS__SetDescriptor(
1135
1136
  Unit.prototype,
1136
1137
  "_deltas",
@@ -1388,17 +1389,17 @@ __TS__SetDescriptor(
1388
1389
  "isTeamGlowVisible",
1389
1390
  {
1390
1391
  get = function(self)
1391
- return not self[105]
1392
+ return not self[106]
1392
1393
  end,
1393
1394
  set = function(self, isTeamGlowVisible)
1394
1395
  showUnitTeamGlow(self.handle, isTeamGlowVisible)
1395
- local ____temp_5
1396
+ local ____temp_6
1396
1397
  if not isTeamGlowVisible then
1397
- ____temp_5 = true
1398
+ ____temp_6 = true
1398
1399
  else
1399
- ____temp_5 = nil
1400
+ ____temp_6 = nil
1400
1401
  end
1401
- self[105] = ____temp_5
1402
+ self[106] = ____temp_6
1402
1403
  end
1403
1404
  },
1404
1405
  true
@@ -1408,7 +1409,7 @@ __TS__SetDescriptor(
1408
1409
  "color",
1409
1410
  {set = function(self, color)
1410
1411
  setUnitColor(self.handle, color.handle)
1411
- if self[105] then
1412
+ if self[106] then
1412
1413
  showUnitTeamGlow(self.handle, false)
1413
1414
  end
1414
1415
  end},
@@ -1432,14 +1433,14 @@ __TS__SetDescriptor(
1432
1433
  "maxHealth",
1433
1434
  {
1434
1435
  get = function(self)
1435
- 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)
1436
1437
  end,
1437
1438
  set = function(self, maxHealth)
1438
- if maxHealth < 1 and self[102] ~= nil then
1439
- 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)
1440
1441
  maxHealth = 1
1441
1442
  end
1442
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[104] or 0))
1443
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1443
1444
  end
1444
1445
  },
1445
1446
  true
@@ -1481,10 +1482,10 @@ __TS__SetDescriptor(
1481
1482
  "health",
1482
1483
  {
1483
1484
  get = function(self)
1484
- return GetWidgetLife(self.handle) - (self[104] or 0)
1485
+ return GetWidgetLife(self.handle) - (self[105] or 0)
1485
1486
  end,
1486
1487
  set = function(self, health)
1487
- SetWidgetLife(self.handle, health + (self[104] or 0))
1488
+ SetWidgetLife(self.handle, health + (self[105] or 0))
1488
1489
  end
1489
1490
  },
1490
1491
  true
@@ -1695,17 +1696,17 @@ __TS__SetDescriptor(
1695
1696
  set = function(self, isPaused)
1696
1697
  local handle = self.handle
1697
1698
  if isPaused and not IsUnitPaused(handle) then
1698
- self[100] = true
1699
- for _ = self[101] or 0, -1 do
1699
+ self[101] = true
1700
+ for _ = self[102] or 0, -1 do
1700
1701
  BlzPauseUnitEx(handle, true)
1701
1702
  end
1702
1703
  PauseUnit(handle, true)
1703
1704
  elseif not isPaused and IsUnitPaused(handle) then
1704
1705
  PauseUnit(handle, false)
1705
- for _ = self[101] or 0, -1 do
1706
+ for _ = self[102] or 0, -1 do
1706
1707
  BlzPauseUnitEx(handle, false)
1707
1708
  end
1708
- self[100] = nil
1709
+ self[101] = nil
1709
1710
  end
1710
1711
  end
1711
1712
  },
@@ -2124,25 +2125,25 @@ Unit.onTargetCast = dispatchId(__TS__New(
2124
2125
  InitializingEvent,
2125
2126
  function(event)
2126
2127
  local function listener(unit, id)
2127
- local ____GetSpellTargetUnit_result_8
2128
+ local ____GetSpellTargetUnit_result_9
2128
2129
  if GetSpellTargetUnit() then
2129
- ____GetSpellTargetUnit_result_8 = ____exports.Unit:of(GetSpellTargetUnit())
2130
+ ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
2130
2131
  else
2131
- local ____GetSpellTargetItem_result_7
2132
+ local ____GetSpellTargetItem_result_8
2132
2133
  if GetSpellTargetItem() then
2133
- ____GetSpellTargetItem_result_7 = Item:of(GetSpellTargetItem())
2134
+ ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
2134
2135
  else
2135
- local ____GetSpellTargetDestructable_result_6
2136
+ local ____GetSpellTargetDestructable_result_7
2136
2137
  if GetSpellTargetDestructable() then
2137
- ____GetSpellTargetDestructable_result_6 = Destructable:of(GetSpellTargetDestructable())
2138
+ ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
2138
2139
  else
2139
- ____GetSpellTargetDestructable_result_6 = nil
2140
+ ____GetSpellTargetDestructable_result_7 = nil
2140
2141
  end
2141
- ____GetSpellTargetItem_result_7 = ____GetSpellTargetDestructable_result_6
2142
+ ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
2142
2143
  end
2143
- ____GetSpellTargetUnit_result_8 = ____GetSpellTargetItem_result_7
2144
+ ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
2144
2145
  end
2145
- local target = ____GetSpellTargetUnit_result_8
2146
+ local target = ____GetSpellTargetUnit_result_9
2146
2147
  if target then
2147
2148
  invoke(event, unit, id, target)
2148
2149
  end
@@ -2469,7 +2470,7 @@ Unit.onDamage = __TS__New(
2469
2470
  invoke(event, source, target, evData)
2470
2471
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2471
2472
  local bonusHealth = math.ceil(evData.amount)
2472
- target[104] = (target[104] or 0) + bonusHealth
2473
+ target[105] = (target[105] or 0) + bonusHealth
2473
2474
  BlzSetUnitMaxHP(
2474
2475
  target.handle,
2475
2476
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2483,7 +2484,7 @@ Unit.onDamage = __TS__New(
2483
2484
  evData[0],
2484
2485
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2485
2486
  )
2486
- target[104] = (target[104] or 0) - bonusHealth
2487
+ target[105] = (target[105] or 0) - bonusHealth
2487
2488
  SetWidgetLife(
2488
2489
  target.handle,
2489
2490
  GetWidgetLife(target.handle) - bonusHealth
@@ -2535,6 +2536,30 @@ Unit.itemStackedEvent = __TS__New(
2535
2536
  EVENT_PLAYER_UNIT_STACK_ITEM,
2536
2537
  function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2537
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
+ )
2538
2563
  __TS__ObjectDefineProperty(
2539
2564
  Unit,
2540
2565
  "onCreate",
@@ -1,7 +1,7 @@
1
1
  /** @noSelfInFile */
2
2
  import { Unit } from "../core/types/unit";
3
3
  import { Async } from "../core/types/async";
4
- import { TriggerEvent } from "../event";
4
+ import { Event, TriggerEvent } from "../event";
5
5
  import { GraphicsMode } from "./index";
6
6
  export declare class LocalClient {
7
7
  private constructor();
@@ -11,6 +11,11 @@ export declare class LocalClient {
11
11
  static get isHD(): boolean;
12
12
  static get graphicsMode(): GraphicsMode;
13
13
  static get isActive(): boolean;
14
- static get mouseFocusUnit(): Async<Unit>;
14
+ static get mouseFocusUnit(): Async<Unit> | undefined;
15
+ static get mainSelectedUnit(): Async<Unit> | undefined;
16
+ static get mainSelectedUnitChangeEvent(): Event<[
17
+ previousMainSelectedUnit: Unit | undefined,
18
+ newMainSelectedUnit: Unit | undefined
19
+ ]>;
15
20
  static readonly onDisconnect: TriggerEvent<[]>;
16
21
  }
@@ -1,4 +1,5 @@
1
1
  local ____lualib = require("lualib_bundle")
2
+ local __TS__ArrayMap = ____lualib.__TS__ArrayMap
2
3
  local __TS__Class = ____lualib.__TS__Class
3
4
  local __TS__ObjectDefineProperty = ____lualib.__TS__ObjectDefineProperty
4
5
  local __TS__New = ____lualib.__TS__New
@@ -6,13 +7,25 @@ local ____exports = {}
6
7
  local ____unit = require("core.types.unit")
7
8
  local Unit = ____unit.Unit
8
9
  local ____event = require("event")
10
+ local Event = ____event.Event
9
11
  local TriggerEvent = ____event.TriggerEvent
12
+ local ____frame = require("core.types.frame")
13
+ local Frame = ____frame.Frame
14
+ local ____player = require("core.types.player")
15
+ local Player = ____player.Player
16
+ local ____timer = require("core.types.timer")
17
+ local Timer = ____timer.Timer
10
18
  local loadTOCFile = BlzLoadTOCFile
11
19
  local getLocalClientWidth = BlzGetLocalClientWidth
12
20
  local getLocalClientHeight = BlzGetLocalClientHeight
13
21
  local isLocalClientActive = BlzIsLocalClientActive
22
+ local isHeroUnitId = IsHeroUnitId
23
+ local getHandleId = GetHandleId
14
24
  local getMouseFocusUnit = BlzGetMouseFocusUnit
25
+ local getUnitRealField = BlzGetUnitRealField
26
+ local getUnitTypeId = GetUnitTypeId
15
27
  local getLocale = BlzGetLocale
28
+ local tableSort = table.sort
16
29
  local tocPath = "_warscript\\IsHD.toc"
17
30
  compiletime(function()
18
31
  if currentMap then
@@ -21,6 +34,29 @@ compiletime(function()
21
34
  currentMap:addFileString("_HD.w3mod\\" .. tocPath, fdfPath .. "\r\n")
22
35
  end
23
36
  end)
37
+ local selectionButtons
38
+ Timer:run(function()
39
+ selectionButtons = __TS__ArrayMap(
40
+ Frame:byName("SimpleInfoPanelUnitDetail").parent:getChild(5):getChild(0).children,
41
+ function(____, frame) return frame:getChild(1) end
42
+ )
43
+ end)
44
+ local localSelectedUnits = {}
45
+ local indexByLocalSelectedUnit = {}
46
+ local function compareUnitsSelectionPriority(a, b)
47
+ local aHandle = a.handle
48
+ local bHandle = b.handle
49
+ local priorityDelta = getUnitRealField(bHandle, UNIT_RF_PRIORITY) - getUnitRealField(aHandle, UNIT_RF_PRIORITY)
50
+ if priorityDelta ~= 0 then
51
+ return priorityDelta < 0
52
+ end
53
+ local aTypeId = getUnitTypeId(aHandle)
54
+ local bTypeId = getUnitTypeId(bHandle)
55
+ local orderDelta = (isHeroUnitId(aTypeId) and getHandleId(aHandle) or aTypeId) - (isHeroUnitId(bTypeId) and getHandleId(bHandle) or bTypeId)
56
+ return (orderDelta ~= 0 and orderDelta or indexByLocalSelectedUnit[a] - indexByLocalSelectedUnit[b]) < 0
57
+ end
58
+ local mainSelectedUnitChangeEvent
59
+ local previousMainSelectedUnit
24
60
  ____exports.LocalClient = __TS__Class()
25
61
  local LocalClient = ____exports.LocalClient
26
62
  LocalClient.name = "LocalClient"
@@ -69,6 +105,52 @@ __TS__ObjectDefineProperty(
69
105
  return Unit:of(getMouseFocusUnit())
70
106
  end}
71
107
  )
108
+ __TS__ObjectDefineProperty(
109
+ LocalClient,
110
+ "mainSelectedUnit",
111
+ {get = function(self)
112
+ Unit:getSelectionOf(Player["local"], localSelectedUnits)
113
+ for i = 1, #localSelectedUnits do
114
+ indexByLocalSelectedUnit[localSelectedUnits[i]] = i
115
+ end
116
+ tableSort(localSelectedUnits, compareUnitsSelectionPriority)
117
+ local mainSelectedUnitIndex
118
+ if selectionButtons and #localSelectedUnits > 1 then
119
+ local maxButtonWidth = 0
120
+ for i = 0, #selectionButtons - 1 do
121
+ local width = selectionButtons[i + 1].width
122
+ if width > maxButtonWidth then
123
+ maxButtonWidth = width
124
+ mainSelectedUnitIndex = i
125
+ end
126
+ end
127
+ end
128
+ local mainSelectedUnit = localSelectedUnits[(mainSelectedUnitIndex or 0) + 1]
129
+ for i = 1, #localSelectedUnits do
130
+ indexByLocalSelectedUnit[localSelectedUnits[i]] = nil
131
+ localSelectedUnits[i] = nil
132
+ end
133
+ if mainSelectedUnitChangeEvent ~= nil and mainSelectedUnit ~= previousMainSelectedUnit then
134
+ local previousPreviousMainSelectedUnit = previousMainSelectedUnit
135
+ previousMainSelectedUnit = mainSelectedUnit
136
+ Event.invoke(mainSelectedUnitChangeEvent, previousPreviousMainSelectedUnit, previousMainSelectedUnit)
137
+ end
138
+ return mainSelectedUnit
139
+ end}
140
+ )
141
+ __TS__ObjectDefineProperty(
142
+ LocalClient,
143
+ "mainSelectedUnitChangeEvent",
144
+ {get = function(self)
145
+ if mainSelectedUnitChangeEvent == nil then
146
+ mainSelectedUnitChangeEvent = __TS__New(Event)
147
+ Timer.onPeriod[1 / 64]:addListener(function()
148
+ local _ = ____exports.LocalClient.mainSelectedUnit
149
+ end)
150
+ end
151
+ return mainSelectedUnitChangeEvent
152
+ end}
153
+ )
72
154
  LocalClient.onDisconnect = __TS__New(
73
155
  TriggerEvent,
74
156
  function(trigger)
@@ -261,7 +261,7 @@ local AbilityLevelField = ____exports.AbilityLevelField
261
261
  AbilityLevelField.name = "AbilityLevelField"
262
262
  __TS__ClassExtends(AbilityLevelField, ObjectLevelField)
263
263
  function AbilityLevelField.prototype.getLevelCount(self, entry)
264
- return __TS__InstanceOf(entry, Ability) and #entry.levels or entry.levelCount
264
+ return entry.levelCount
265
265
  end
266
266
  function AbilityLevelField.prototype.getObjectDataEntryId(self, instance)
267
267
  return instance.typeId
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/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  /** @noSelfInFile */
2
2
  import "./types";
3
+ import "./patch-lua";
3
4
  import "./patch-lualib";
4
5
  import "./patch-natives";
5
6
  import "./global/math";
package/index.lua CHANGED
@@ -1,5 +1,6 @@
1
1
  local ____exports = {}
2
2
  require("types")
3
+ require("patch-lua")
3
4
  require("patch-lualib")
4
5
  require("patch-natives")
5
6
  require("global.math")
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.099f0af",
4
+ "version": "0.0.1-dev.0b2f1d6",
5
5
  "description": "A typescript library for Warcraft III using Warpack.",
6
6
  "keywords": [
7
7
  "warcraft",
package/patch-lua.d.ts ADDED
File without changes
package/patch-lua.lua ADDED
@@ -0,0 +1,10 @@
1
+ local getmetatable = _G.getmetatable
2
+ local ipairs = _G.ipairs
3
+
4
+ _G.ipairs = function(t)
5
+ local metatable = getmetatable(t)
6
+ if metatable and metatable.__ipairs then
7
+ return metatable.__ipairs(t)
8
+ end
9
+ return ipairs(t)
10
+ end
@@ -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>;
@@ -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