warscript 0.0.1-dev.ccc2b77 → 0.0.1-dev.d1328b7

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.
@@ -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",
@@ -0,0 +1,7 @@
1
+ /** @noSelfInFile */
2
+ import { Player } from "../../../core/types/player";
3
+ declare module "../unit" {
4
+ namespace Unit {
5
+ const getMainSelectedOf: (player: Player) => Unit | undefined;
6
+ }
7
+ }
@@ -0,0 +1,40 @@
1
+ local ____exports = {}
2
+ local ____player = require("core.types.player")
3
+ local Player = ____player.Player
4
+ local ____math = require("math")
5
+ local MAXIMUM_INTEGER = ____math.MAXIMUM_INTEGER
6
+ local MINIMUM_INTEGER = ____math.MINIMUM_INTEGER
7
+ local ____local_2Dclient = require("engine.local-client")
8
+ local LocalClient = ____local_2Dclient.LocalClient
9
+ local ____unit = require("engine.internal.unit")
10
+ local Unit = ____unit.Unit
11
+ local mainSelectedUnitByPlayer = {}
12
+ local syncSlider = BlzCreateFrameByType(
13
+ "SLIDER",
14
+ "UnitSyncId",
15
+ BlzGetOriginFrame(ORIGIN_FRAME_WORLD_FRAME, 0),
16
+ "",
17
+ 0
18
+ )
19
+ BlzFrameSetMinMaxValue(syncSlider, MINIMUM_INTEGER, MAXIMUM_INTEGER)
20
+ LocalClient.mainSelectedUnitChangeEvent:addListener(function()
21
+ local ____opt_0 = LocalClient.mainSelectedUnit
22
+ local syncId = ____opt_0 and ____opt_0.syncId
23
+ BlzFrameSetValue(syncSlider, syncId or 0)
24
+ end)
25
+ local trg = CreateTrigger()
26
+ BlzTriggerRegisterFrameEvent(trg, syncSlider, FRAMEEVENT_SLIDER_VALUE_CHANGED)
27
+ TriggerAddAction(
28
+ trg,
29
+ function()
30
+ mainSelectedUnitByPlayer[Player:of(GetTriggerPlayer())] = Unit:getBySyncId(BlzGetTriggerFrameValue())
31
+ end
32
+ )
33
+ rawset(
34
+ Unit,
35
+ "getMainSelectedOf",
36
+ function(player)
37
+ return mainSelectedUnitByPlayer[player]
38
+ end
39
+ )
40
+ 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]?;
@@ -337,5 +342,6 @@ export declare class Unit extends Handle<junit> {
337
342
  setField(field: junitbooleanfield, value: boolean): boolean;
338
343
  setField(field: junitstringfield, value: string): boolean;
339
344
  toString(): string;
345
+ static getBySyncId(syncId: UnitSyncId): Unit | undefined;
340
346
  }
341
347
  export {};
@@ -630,15 +630,15 @@ for ____, player in ipairs(Player.all) do
630
630
  dummies[player] = dummy
631
631
  end
632
632
  local function delayHealthChecksCallback(unit)
633
- local counter = (unit[102] or 0) - 1
633
+ local counter = (unit[103] or 0) - 1
634
634
  if counter ~= 0 then
635
- unit[102] = counter
635
+ unit[103] = counter
636
636
  return
637
637
  end
638
- unit[102] = nil
639
- local healthBonus = unit[103]
638
+ unit[103] = nil
639
+ local healthBonus = unit[104]
640
640
  if healthBonus ~= nil then
641
- unit[103] = nil
641
+ unit[104] = nil
642
642
  local handle = unit.handle
643
643
  BlzSetUnitMaxHP(
644
644
  handle,
@@ -646,12 +646,17 @@ local function delayHealthChecksCallback(unit)
646
646
  )
647
647
  end
648
648
  end
649
+ local nextSyncId = 1
650
+ local unitBySyncId = setmetatable({}, {__mode = "k"})
649
651
  ____exports.Unit = __TS__Class()
650
652
  local Unit = ____exports.Unit
651
653
  Unit.name = "Unit"
652
654
  __TS__ClassExtends(Unit, Handle)
653
655
  function Unit.prototype.____constructor(self, handle)
654
656
  Handle.prototype.____constructor(self, handle)
657
+ local ____nextSyncId_0 = nextSyncId
658
+ nextSyncId = ____nextSyncId_0 + 1
659
+ self.syncId = ____nextSyncId_0
655
660
  self._owner = Player:of(getOwningPlayer(handle))
656
661
  assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
657
662
  assert(unitAddAbility(handle, morphDetectAbilityId))
@@ -664,6 +669,7 @@ function Unit.prototype.____constructor(self, handle)
664
669
  fourCC("Amrf")
665
670
  ))
666
671
  end
672
+ unitBySyncId[self.syncId] = self
667
673
  local ____ = self.abilities
668
674
  end
669
675
  function Unit.prototype.getEvent(self, event, collector)
@@ -749,8 +755,8 @@ function Unit.prototype.addModifier(self, property, modifier)
749
755
  end}
750
756
  end
751
757
  function Unit.prototype.hasCombatClassification(self, combatClassification)
752
- local ____combatClassification_0 = combatClassification
753
- return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_0 == ____combatClassification_0
758
+ local ____combatClassification_1 = combatClassification
759
+ return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_1 == ____combatClassification_1
754
760
  end
755
761
  function Unit.prototype.addClassification(self, classification)
756
762
  return unitAddType(self.handle, classification)
@@ -768,13 +774,13 @@ function Unit.prototype.isInvisibleTo(self, player)
768
774
  return isUnitInvisible(self.handle, player.handle)
769
775
  end
770
776
  function Unit.prototype.isInRangeOf(self, x, y, range)
771
- local ____temp_1
777
+ local ____temp_2
772
778
  if type(x) == "number" then
773
- ____temp_1 = isUnitInRangeXY(self.handle, x, y, range)
779
+ ____temp_2 = isUnitInRangeXY(self.handle, x, y, range)
774
780
  else
775
- ____temp_1 = isUnitInRange(self.handle, x.handle, y)
781
+ ____temp_2 = isUnitInRange(self.handle, x.handle, y)
776
782
  end
777
- return ____temp_1
783
+ return ____temp_2
778
784
  end
779
785
  function Unit.prototype.isAllyOf(self, unit)
780
786
  return isUnitAlly(
@@ -801,7 +807,7 @@ function Unit.prototype.queueAnimation(self, animation)
801
807
  queueUnitAnimation(self.handle, animation)
802
808
  end
803
809
  function Unit.prototype.delayHealthChecks(self)
804
- self[102] = (self[102] or 0) + 1
810
+ self[103] = (self[103] or 0) + 1
805
811
  Timer:run(delayHealthChecksCallback, self)
806
812
  end
807
813
  function Unit.prototype.setPosition(self, x, y)
@@ -818,14 +824,14 @@ function Unit.prototype.kill(self)
818
824
  killUnit(self.handle)
819
825
  end
820
826
  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
827
+ local ____ReviveHero_5 = ReviveHero
828
+ local ____array_4 = __TS__SparseArrayNew(self.handle, x, y)
829
+ local ____doEffect_3 = doEffect
830
+ if ____doEffect_3 == nil then
831
+ ____doEffect_3 = false
826
832
  end
827
- __TS__SparseArrayPush(____array_3, ____doEffect_2)
828
- ____ReviveHero_4(__TS__SparseArraySpread(____array_3))
833
+ __TS__SparseArrayPush(____array_4, ____doEffect_3)
834
+ ____ReviveHero_5(__TS__SparseArraySpread(____array_4))
829
835
  end
830
836
  function Unit.prototype.healTarget(self, target, amount)
831
837
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -995,18 +1001,18 @@ function Unit.prototype.unpauseEx(self)
995
1001
  self:decrementStunCounter()
996
1002
  end
997
1003
  function Unit.prototype.incrementStunCounter(self)
998
- local stunCounter = self[101] or 0
999
- if not self[100] or stunCounter >= 0 then
1004
+ local stunCounter = self[102] or 0
1005
+ if not self[101] or stunCounter >= 0 then
1000
1006
  BlzPauseUnitEx(self.handle, true)
1001
1007
  end
1002
- self[101] = stunCounter + 1
1008
+ self[102] = stunCounter + 1
1003
1009
  end
1004
1010
  function Unit.prototype.decrementStunCounter(self)
1005
- local stunCounter = self[101] or 0
1006
- if not self[100] or stunCounter >= 1 then
1011
+ local stunCounter = self[102] or 0
1012
+ if not self[101] or stunCounter >= 1 then
1007
1013
  BlzPauseUnitEx(self.handle, false)
1008
1014
  end
1009
- self[101] = stunCounter - 1
1015
+ self[102] = stunCounter - 1
1010
1016
  end
1011
1017
  function Unit.create(self, owner, id, x, y, facing, skinId)
1012
1018
  local handle = skinId and BlzCreateUnitWithSkin(
@@ -1134,6 +1140,9 @@ end
1134
1140
  function Unit.prototype.__tostring(self)
1135
1141
  return (((self.constructor.name .. "$") .. util.id2s(self.typeId)) .. "@") .. tostring(getHandleId(self.handle))
1136
1142
  end
1143
+ function Unit.getBySyncId(self, syncId)
1144
+ return unitBySyncId[syncId]
1145
+ end
1137
1146
  __TS__SetDescriptor(
1138
1147
  Unit.prototype,
1139
1148
  "_deltas",
@@ -1391,17 +1400,17 @@ __TS__SetDescriptor(
1391
1400
  "isTeamGlowVisible",
1392
1401
  {
1393
1402
  get = function(self)
1394
- return not self[105]
1403
+ return not self[106]
1395
1404
  end,
1396
1405
  set = function(self, isTeamGlowVisible)
1397
1406
  showUnitTeamGlow(self.handle, isTeamGlowVisible)
1398
- local ____temp_5
1407
+ local ____temp_6
1399
1408
  if not isTeamGlowVisible then
1400
- ____temp_5 = true
1409
+ ____temp_6 = true
1401
1410
  else
1402
- ____temp_5 = nil
1411
+ ____temp_6 = nil
1403
1412
  end
1404
- self[105] = ____temp_5
1413
+ self[106] = ____temp_6
1405
1414
  end
1406
1415
  },
1407
1416
  true
@@ -1411,7 +1420,7 @@ __TS__SetDescriptor(
1411
1420
  "color",
1412
1421
  {set = function(self, color)
1413
1422
  setUnitColor(self.handle, color.handle)
1414
- if self[105] then
1423
+ if self[106] then
1415
1424
  showUnitTeamGlow(self.handle, false)
1416
1425
  end
1417
1426
  end},
@@ -1435,14 +1444,14 @@ __TS__SetDescriptor(
1435
1444
  "maxHealth",
1436
1445
  {
1437
1446
  get = function(self)
1438
- return BlzGetUnitMaxHP(self.handle) - (self[103] or 0) - (self[104] or 0)
1447
+ return BlzGetUnitMaxHP(self.handle) - (self[104] or 0) - (self[105] or 0)
1439
1448
  end,
1440
1449
  set = function(self, maxHealth)
1441
- if maxHealth < 1 and self[102] ~= nil then
1442
- self[103] = (self[103] or 0) + (1 - maxHealth)
1450
+ if maxHealth < 1 and self[103] ~= nil then
1451
+ self[104] = (self[104] or 0) + (1 - maxHealth)
1443
1452
  maxHealth = 1
1444
1453
  end
1445
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[104] or 0))
1454
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1446
1455
  end
1447
1456
  },
1448
1457
  true
@@ -1484,10 +1493,10 @@ __TS__SetDescriptor(
1484
1493
  "health",
1485
1494
  {
1486
1495
  get = function(self)
1487
- return GetWidgetLife(self.handle) - (self[104] or 0)
1496
+ return GetWidgetLife(self.handle) - (self[105] or 0)
1488
1497
  end,
1489
1498
  set = function(self, health)
1490
- SetWidgetLife(self.handle, health + (self[104] or 0))
1499
+ SetWidgetLife(self.handle, health + (self[105] or 0))
1491
1500
  end
1492
1501
  },
1493
1502
  true
@@ -1698,17 +1707,17 @@ __TS__SetDescriptor(
1698
1707
  set = function(self, isPaused)
1699
1708
  local handle = self.handle
1700
1709
  if isPaused and not IsUnitPaused(handle) then
1701
- self[100] = true
1702
- for _ = self[101] or 0, -1 do
1710
+ self[101] = true
1711
+ for _ = self[102] or 0, -1 do
1703
1712
  BlzPauseUnitEx(handle, true)
1704
1713
  end
1705
1714
  PauseUnit(handle, true)
1706
1715
  elseif not isPaused and IsUnitPaused(handle) then
1707
1716
  PauseUnit(handle, false)
1708
- for _ = self[101] or 0, -1 do
1717
+ for _ = self[102] or 0, -1 do
1709
1718
  BlzPauseUnitEx(handle, false)
1710
1719
  end
1711
- self[100] = nil
1720
+ self[101] = nil
1712
1721
  end
1713
1722
  end
1714
1723
  },
@@ -2127,25 +2136,25 @@ Unit.onTargetCast = dispatchId(__TS__New(
2127
2136
  InitializingEvent,
2128
2137
  function(event)
2129
2138
  local function listener(unit, id)
2130
- local ____GetSpellTargetUnit_result_8
2139
+ local ____GetSpellTargetUnit_result_9
2131
2140
  if GetSpellTargetUnit() then
2132
- ____GetSpellTargetUnit_result_8 = ____exports.Unit:of(GetSpellTargetUnit())
2141
+ ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
2133
2142
  else
2134
- local ____GetSpellTargetItem_result_7
2143
+ local ____GetSpellTargetItem_result_8
2135
2144
  if GetSpellTargetItem() then
2136
- ____GetSpellTargetItem_result_7 = Item:of(GetSpellTargetItem())
2145
+ ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
2137
2146
  else
2138
- local ____GetSpellTargetDestructable_result_6
2147
+ local ____GetSpellTargetDestructable_result_7
2139
2148
  if GetSpellTargetDestructable() then
2140
- ____GetSpellTargetDestructable_result_6 = Destructable:of(GetSpellTargetDestructable())
2149
+ ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
2141
2150
  else
2142
- ____GetSpellTargetDestructable_result_6 = nil
2151
+ ____GetSpellTargetDestructable_result_7 = nil
2143
2152
  end
2144
- ____GetSpellTargetItem_result_7 = ____GetSpellTargetDestructable_result_6
2153
+ ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
2145
2154
  end
2146
- ____GetSpellTargetUnit_result_8 = ____GetSpellTargetItem_result_7
2155
+ ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
2147
2156
  end
2148
- local target = ____GetSpellTargetUnit_result_8
2157
+ local target = ____GetSpellTargetUnit_result_9
2149
2158
  if target then
2150
2159
  invoke(event, unit, id, target)
2151
2160
  end
@@ -2472,7 +2481,7 @@ Unit.onDamage = __TS__New(
2472
2481
  invoke(event, source, target, evData)
2473
2482
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2474
2483
  local bonusHealth = math.ceil(evData.amount)
2475
- target[104] = (target[104] or 0) + bonusHealth
2484
+ target[105] = (target[105] or 0) + bonusHealth
2476
2485
  BlzSetUnitMaxHP(
2477
2486
  target.handle,
2478
2487
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2486,7 +2495,7 @@ Unit.onDamage = __TS__New(
2486
2495
  evData[0],
2487
2496
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2488
2497
  )
2489
- target[104] = (target[104] or 0) - bonusHealth
2498
+ target[105] = (target[105] or 0) - bonusHealth
2490
2499
  SetWidgetLife(
2491
2500
  target.handle,
2492
2501
  GetWidgetLife(target.handle) - bonusHealth
@@ -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}
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.ccc2b77",
4
+ "version": "0.0.1-dev.d1328b7",
5
5
  "description": "A typescript library for Warcraft III using Warpack.",
6
6
  "keywords": [
7
7
  "warcraft",