warscript 0.0.1-dev.96a6f7e → 0.0.1-dev.987b772
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/core/types/frame.d.ts
CHANGED
|
@@ -108,6 +108,7 @@ export declare class Frame extends Handle<jframehandle> {
|
|
|
108
108
|
enable(): void;
|
|
109
109
|
addText(text: string): void;
|
|
110
110
|
clearAllPoints(): void;
|
|
111
|
+
get children(): Frame[];
|
|
111
112
|
getChild(index: number): Frame;
|
|
112
113
|
getChildrenCount(): number;
|
|
113
114
|
setSize(width: number, height: number): void;
|
package/core/types/frame.lua
CHANGED
|
@@ -720,6 +720,18 @@ __TS__SetDescriptor(
|
|
|
720
720
|
end},
|
|
721
721
|
true
|
|
722
722
|
)
|
|
723
|
+
__TS__SetDescriptor(
|
|
724
|
+
Frame.prototype,
|
|
725
|
+
"children",
|
|
726
|
+
{get = function(self)
|
|
727
|
+
local children = {}
|
|
728
|
+
for i = 0, self:getChildrenCount() - 1 do
|
|
729
|
+
children[i + 1] = self:getChild(i)
|
|
730
|
+
end
|
|
731
|
+
return children
|
|
732
|
+
end},
|
|
733
|
+
true
|
|
734
|
+
)
|
|
723
735
|
__TS__ObjectDefineProperty(
|
|
724
736
|
Frame,
|
|
725
737
|
"onKeyPress",
|
|
@@ -288,7 +288,7 @@ export declare class Unit extends Handle<junit> {
|
|
|
288
288
|
static getInRange(x: number, y: number, range: number, predicate?: (unit: Unit) => boolean): Unit[];
|
|
289
289
|
static getInCollisionRange(x: number, y: number, range: number, predicate?: (unit: Unit) => boolean): Unit[];
|
|
290
290
|
static getInSector(pos: Vec2, range: number, offsetAngle: number, centralAngle: number): Unit[];
|
|
291
|
-
static getSelectionOf(player: Player): Unit[];
|
|
291
|
+
static getSelectionOf(player: Player, target?: Unit[]): Unit[];
|
|
292
292
|
static readonly deathEvent: UnitTriggerEvent<[Unit]>;
|
|
293
293
|
static readonly onDecay: UnitTriggerEvent<[]>;
|
|
294
294
|
static readonly onResurrect: InitializingEvent<[Unit], void>;
|
package/engine/internal/unit.lua
CHANGED
|
@@ -1108,8 +1108,11 @@ function Unit.getInSector(self, pos, range, offsetAngle, centralAngle)
|
|
|
1108
1108
|
)
|
|
1109
1109
|
return targetCollection
|
|
1110
1110
|
end
|
|
1111
|
-
function Unit.getSelectionOf(self, player)
|
|
1112
|
-
|
|
1111
|
+
function Unit.getSelectionOf(self, player, target)
|
|
1112
|
+
if target == nil then
|
|
1113
|
+
target = {}
|
|
1114
|
+
end
|
|
1115
|
+
targetCollection = target
|
|
1113
1116
|
targetCollectionNextIndex = 1
|
|
1114
1117
|
GroupEnumUnitsSelected(dummyGroup, player.handle, collectIntoTarget)
|
|
1115
1118
|
return targetCollection
|
package/engine/local-client.d.ts
CHANGED
|
@@ -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
|
}
|
package/engine/local-client.lua
CHANGED
|
@@ -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,31 @@ compiletime(function()
|
|
|
21
34
|
currentMap:addFileString("_HD.w3mod\\" .. tocPath, fdfPath .. "\r\n")
|
|
22
35
|
end
|
|
23
36
|
end)
|
|
37
|
+
local selectionContainer
|
|
38
|
+
local selectionButtons
|
|
39
|
+
Timer:run(function()
|
|
40
|
+
selectionContainer = Frame:byName("SimpleInfoPanelUnitDetail").parent:getChild(5):getChild(0)
|
|
41
|
+
selectionButtons = __TS__ArrayMap(
|
|
42
|
+
selectionContainer.children,
|
|
43
|
+
function(____, frame) return frame:getChild(0) end
|
|
44
|
+
)
|
|
45
|
+
end)
|
|
46
|
+
local localSelectedUnits = {}
|
|
47
|
+
local indexByLocalSelectedUnit = {}
|
|
48
|
+
local function compareUnitsSelectionPriority(a, b)
|
|
49
|
+
local aHandle = a.handle
|
|
50
|
+
local bHandle = b.handle
|
|
51
|
+
local priorityDelta = getUnitRealField(bHandle, UNIT_RF_PRIORITY) - getUnitRealField(aHandle, UNIT_RF_PRIORITY)
|
|
52
|
+
if priorityDelta ~= 0 then
|
|
53
|
+
return priorityDelta < 0
|
|
54
|
+
end
|
|
55
|
+
local aTypeId = getUnitTypeId(aHandle)
|
|
56
|
+
local bTypeId = getUnitTypeId(bHandle)
|
|
57
|
+
local orderDelta = (isHeroUnitId(aTypeId) and getHandleId(aHandle) or aTypeId) - (isHeroUnitId(bTypeId) and getHandleId(bHandle) or bTypeId)
|
|
58
|
+
return (orderDelta ~= 0 and orderDelta or indexByLocalSelectedUnit[a] - indexByLocalSelectedUnit[b]) < 0
|
|
59
|
+
end
|
|
60
|
+
local mainSelectedUnitChangeEvent
|
|
61
|
+
local previousMainSelectedUnit
|
|
24
62
|
____exports.LocalClient = __TS__Class()
|
|
25
63
|
local LocalClient = ____exports.LocalClient
|
|
26
64
|
LocalClient.name = "LocalClient"
|
|
@@ -69,6 +107,49 @@ __TS__ObjectDefineProperty(
|
|
|
69
107
|
return Unit:of(getMouseFocusUnit())
|
|
70
108
|
end}
|
|
71
109
|
)
|
|
110
|
+
__TS__ObjectDefineProperty(
|
|
111
|
+
LocalClient,
|
|
112
|
+
"mainSelectedUnit",
|
|
113
|
+
{get = function(self)
|
|
114
|
+
Unit:getSelectionOf(Player["local"], localSelectedUnits)
|
|
115
|
+
for i = 1, #localSelectedUnits do
|
|
116
|
+
indexByLocalSelectedUnit[localSelectedUnits[i]] = i
|
|
117
|
+
end
|
|
118
|
+
tableSort(localSelectedUnits, compareUnitsSelectionPriority)
|
|
119
|
+
local mainSelectedUnitIndex
|
|
120
|
+
if selectionContainer and selectionButtons and selectionContainer.visible then
|
|
121
|
+
for i = 0, #selectionButtons - 1 do
|
|
122
|
+
if selectionButtons[i + 1].visible then
|
|
123
|
+
mainSelectedUnitIndex = i
|
|
124
|
+
break
|
|
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
|
+
Event.invoke(mainSelectedUnitChangeEvent, previousMainSelectedUnit, mainSelectedUnit)
|
|
135
|
+
previousMainSelectedUnit = mainSelectedUnit
|
|
136
|
+
end
|
|
137
|
+
return mainSelectedUnit
|
|
138
|
+
end}
|
|
139
|
+
)
|
|
140
|
+
__TS__ObjectDefineProperty(
|
|
141
|
+
LocalClient,
|
|
142
|
+
"mainSelectedUnitChangeEvent",
|
|
143
|
+
{get = function(self)
|
|
144
|
+
if mainSelectedUnitChangeEvent == nil then
|
|
145
|
+
mainSelectedUnitChangeEvent = __TS__New(Event)
|
|
146
|
+
Timer.onPeriod[1 / 64]:addListener(function()
|
|
147
|
+
local _ = ____exports.LocalClient.mainSelectedUnit
|
|
148
|
+
end)
|
|
149
|
+
end
|
|
150
|
+
return mainSelectedUnitChangeEvent
|
|
151
|
+
end}
|
|
152
|
+
)
|
|
72
153
|
LocalClient.onDisconnect = __TS__New(
|
|
73
154
|
TriggerEvent,
|
|
74
155
|
function(trigger)
|
package/package.json
CHANGED