warscript 0.0.1-dev.3bc4ba4 → 0.0.1-dev.3dad3ec

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/core/types/frame.lua +25 -12
  2. package/core/types/player.lua +4 -1
  3. package/core/types/playerCamera.d.ts +2 -0
  4. package/core/types/playerCamera.lua +76 -2
  5. package/core/types/timer.d.ts +2 -1
  6. package/core/types/timer.lua +7 -2
  7. package/decl/native.d.ts +4 -2
  8. package/engine/behavior.d.ts +2 -0
  9. package/engine/behavior.lua +53 -27
  10. package/engine/behaviour/ability/apply-buff.lua +1 -1
  11. package/engine/behaviour/ability/emulate-impact.d.ts +1 -1
  12. package/engine/behaviour/ability/emulate-impact.lua +2 -1
  13. package/engine/behaviour/ability/restore-mana.d.ts +1 -1
  14. package/engine/behaviour/ability/restore-mana.lua +6 -6
  15. package/engine/behaviour/ability.lua +7 -16
  16. package/engine/behaviour/unit/stun-immunity.d.ts +5 -3
  17. package/engine/behaviour/unit/stun-immunity.lua +43 -27
  18. package/engine/behaviour/unit.d.ts +12 -1
  19. package/engine/behaviour/unit.lua +56 -7
  20. package/engine/buff.d.ts +2 -1
  21. package/engine/buff.lua +9 -3
  22. package/engine/internal/ability.lua +8 -2
  23. package/engine/internal/item/ability.lua +51 -1
  24. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  25. package/engine/internal/misc/get-terrain-z.lua +11 -0
  26. package/engine/internal/unit/ability.d.ts +30 -0
  27. package/engine/internal/unit/ability.lua +48 -0
  28. package/engine/internal/unit/order.d.ts +20 -0
  29. package/engine/internal/unit/order.lua +136 -0
  30. package/engine/internal/unit-missile-launch.lua +8 -1
  31. package/engine/internal/unit.d.ts +3 -3
  32. package/engine/internal/unit.lua +70 -57
  33. package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
  34. package/engine/object-data/auxiliary/armor-type.lua +46 -0
  35. package/engine/object-data/entry/ability-type.lua +1 -3
  36. package/engine/object-data/entry/unit-type.d.ts +11 -2
  37. package/engine/object-data/entry/unit-type.lua +59 -1
  38. package/engine/object-field/unit.d.ts +11 -0
  39. package/engine/object-field/unit.lua +34 -0
  40. package/engine/standard/fields/unit.d.ts +4 -0
  41. package/engine/standard/fields/unit.lua +7 -0
  42. package/engine/text-tag.d.ts +26 -3
  43. package/engine/text-tag.lua +215 -11
  44. package/engine/unit.d.ts +1 -0
  45. package/engine/unit.lua +1 -0
  46. package/package.json +2 -2
  47. package/utility/functions.d.ts +7 -0
  48. package/utility/functions.lua +12 -0
  49. package/utility/lua-sets.d.ts +1 -0
  50. package/utility/lua-sets.lua +4 -0
  51. package/core/types/order.d.ts +0 -26
  52. package/core/types/order.lua +0 -65
@@ -2,6 +2,7 @@ local ____lualib = require("lualib_bundle")
2
2
  local __TS__Class = ____lualib.__TS__Class
3
3
  local __TS__ClassExtends = ____lualib.__TS__ClassExtends
4
4
  local __TS__New = ____lualib.__TS__New
5
+ local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
5
6
  local __TS__ObjectAssign = ____lualib.__TS__ObjectAssign
6
7
  local ____exports = {}
7
8
  local ____color = require("core.types.color")
@@ -10,6 +11,12 @@ local ____timer = require("core.types.timer")
10
11
  local Timer = ____timer.Timer
11
12
  local ____destroyable = require("destroyable")
12
13
  local AbstractDestroyable = ____destroyable.AbstractDestroyable
14
+ local ____player = require("core.types.player")
15
+ local PLAYER_LOCAL_HANDLE = ____player.PLAYER_LOCAL_HANDLE
16
+ local ____playerCamera = require("core.types.playerCamera")
17
+ local worldCoordinatesToFrame = ____playerCamera.worldCoordinatesToFrame
18
+ local ____get_2Dterrain_2Dz = require("engine.internal.misc.get-terrain-z")
19
+ local getTerrainZ = ____get_2Dterrain_2Dz.getTerrainZ
13
20
  local createTextTag = CreateTextTag
14
21
  local destroyTextTag = DestroyTextTag
15
22
  local setTextTagText = SetTextTagText
@@ -23,6 +30,12 @@ local setTextTagPermanent = SetTextTagPermanent
23
30
  local setTextTagAge = SetTextTagAge
24
31
  local setTextTagLifespan = SetTextTagLifespan
25
32
  local setTextTagFadepoint = SetTextTagFadepoint
33
+ local isUnitHidden = IsUnitHidden
34
+ local isUnitLoaded = IsUnitLoaded
35
+ local isUnitVisible = IsUnitVisible
36
+ local getUnitFlyHeight = GetUnitFlyHeight
37
+ local getUnitX = GetUnitX
38
+ local getUnitY = GetUnitY
26
39
  local DEFAULT_FONT_SIZE = 0.024
27
40
  local function applyConfiguration(textTag, configuration)
28
41
  setTextTagFadepoint(textTag, configuration.fadepoint)
@@ -40,16 +53,47 @@ local function applyConfiguration(textTag, configuration)
40
53
  setTextTagVisibility(textTag, true)
41
54
  end
42
55
  local unitTextTags = setmetatable({}, {__mode = "k"})
56
+ local function ensureHandle(textTag)
57
+ local handle = textTag[101]
58
+ if handle == nil then
59
+ handle = createTextTag()
60
+ applyConfiguration(handle, textTag[102])
61
+ setTextTagPermanent(handle, true)
62
+ setTextTagText(handle, textTag[103] or "", textTag[104] or DEFAULT_FONT_SIZE)
63
+ local color = textTag[105]
64
+ if color ~= nil then
65
+ setTextTagColor(
66
+ handle,
67
+ color.r,
68
+ color.g,
69
+ color.b,
70
+ color.a
71
+ )
72
+ end
73
+ local unit = textTag[100]
74
+ if unit ~= nil then
75
+ setTextTagPosUnit(handle, unit.handle, textTag[102].offsetZ)
76
+ else
77
+ setTextTagPos(handle, textTag[106] or 0, textTag[107] or 0, 0)
78
+ end
79
+ textTag[101] = handle
80
+ end
81
+ return handle
82
+ end
43
83
  ____exports.TextTag = __TS__Class()
44
84
  local TextTag = ____exports.TextTag
45
85
  TextTag.name = "TextTag"
46
86
  __TS__ClassExtends(TextTag, AbstractDestroyable)
47
87
  function TextTag.prototype.____constructor(self, handle)
48
88
  AbstractDestroyable.prototype.____constructor(self)
49
- self.handle = handle
89
+ self[101] = handle
50
90
  end
51
91
  function TextTag.prototype.onDestroy(self)
52
- destroyTextTag(self.handle)
92
+ local handle = self[101]
93
+ if handle ~= nil then
94
+ destroyTextTag(handle)
95
+ self[101] = nil
96
+ end
53
97
  unitTextTags[self] = nil
54
98
  return AbstractDestroyable.prototype.onDestroy(self)
55
99
  end
@@ -60,17 +104,160 @@ function TextTag.flash(self, configuration, text, x, y, z)
60
104
  applyConfiguration(textTag, configuration)
61
105
  end
62
106
  function TextTag.create(self, configuration, text, unit)
63
- local handle = createTextTag()
64
- setTextTagText(handle, text, DEFAULT_FONT_SIZE)
65
- setTextTagPosUnit(handle, unit.handle, configuration.offsetZ)
66
- applyConfiguration(handle, configuration)
67
- setTextTagPermanent(handle, true)
68
- local textTag = __TS__New(____exports.TextTag, handle)
69
- textTag[100] = unit.handle
70
- textTag[101] = configuration
107
+ local textTag = __TS__New(____exports.TextTag)
108
+ textTag[100] = unit
109
+ textTag[102] = configuration
110
+ ensureHandle(textTag)
71
111
  unitTextTags[textTag] = true
72
112
  return textTag
73
113
  end
114
+ __TS__SetDescriptor(
115
+ TextTag.prototype,
116
+ "text",
117
+ {
118
+ get = function(self)
119
+ return self[103] or ""
120
+ end,
121
+ set = function(self, text)
122
+ setTextTagText(
123
+ ensureHandle(self),
124
+ text,
125
+ self[104] or DEFAULT_FONT_SIZE
126
+ )
127
+ self[103] = text
128
+ end
129
+ },
130
+ true
131
+ )
132
+ __TS__SetDescriptor(
133
+ TextTag.prototype,
134
+ "fontSize",
135
+ {
136
+ get = function(self)
137
+ return self[104] or DEFAULT_FONT_SIZE
138
+ end,
139
+ set = function(self, fontSize)
140
+ setTextTagText(
141
+ ensureHandle(self),
142
+ self[103] or "",
143
+ DEFAULT_FONT_SIZE
144
+ )
145
+ self[104] = fontSize
146
+ end
147
+ },
148
+ true
149
+ )
150
+ __TS__SetDescriptor(
151
+ TextTag.prototype,
152
+ "color",
153
+ {
154
+ get = function(self)
155
+ return self[105] or Color.white
156
+ end,
157
+ set = function(self, color)
158
+ setTextTagColor(
159
+ ensureHandle(self),
160
+ color.r,
161
+ color.g,
162
+ color.b,
163
+ color.a
164
+ )
165
+ self[105] = color
166
+ end
167
+ },
168
+ true
169
+ )
170
+ __TS__SetDescriptor(
171
+ TextTag.prototype,
172
+ "unit",
173
+ {
174
+ get = function(self)
175
+ return self[100]
176
+ end,
177
+ set = function(self, unit)
178
+ if unit ~= nil then
179
+ setTextTagPosUnit(
180
+ ensureHandle(self),
181
+ unit.handle,
182
+ 0
183
+ )
184
+ self[106] = nil
185
+ self[107] = nil
186
+ unitTextTags[self] = true
187
+ elseif self[100] ~= nil then
188
+ local unit = self[100]
189
+ local x = unit.x
190
+ local y = unit.y
191
+ setTextTagPos(
192
+ ensureHandle(self),
193
+ x,
194
+ y,
195
+ 0
196
+ )
197
+ self[106] = x
198
+ self[107] = y
199
+ unitTextTags[self] = nil
200
+ end
201
+ self[100] = unit
202
+ end
203
+ },
204
+ true
205
+ )
206
+ __TS__SetDescriptor(
207
+ TextTag.prototype,
208
+ "x",
209
+ {
210
+ get = function(self)
211
+ local ____self__106_2 = self[106]
212
+ if ____self__106_2 == nil then
213
+ local ____opt_0 = self[100]
214
+ ____self__106_2 = ____opt_0 and ____opt_0.x
215
+ end
216
+ return ____self__106_2 or 0
217
+ end,
218
+ set = function(self, x)
219
+ local ____ensureHandle_result_6 = ensureHandle(self)
220
+ local ____x_7 = x
221
+ local ____self__107_5 = self[107]
222
+ if ____self__107_5 == nil then
223
+ local ____opt_3 = self[100]
224
+ ____self__107_5 = ____opt_3 and ____opt_3.y
225
+ end
226
+ setTextTagPos(____ensureHandle_result_6, ____x_7, ____self__107_5 or 0, 0)
227
+ self[106] = x
228
+ self[100] = nil
229
+ unitTextTags[self] = nil
230
+ end
231
+ },
232
+ true
233
+ )
234
+ __TS__SetDescriptor(
235
+ TextTag.prototype,
236
+ "y",
237
+ {
238
+ get = function(self)
239
+ local ____self__107_10 = self[107]
240
+ if ____self__107_10 == nil then
241
+ local ____opt_8 = self[100]
242
+ ____self__107_10 = ____opt_8 and ____opt_8.y
243
+ end
244
+ return ____self__107_10 or 0
245
+ end,
246
+ set = function(self, y)
247
+ local ____ensureHandle_result_14 = ensureHandle(self)
248
+ local ____self__106_13 = self[106]
249
+ if ____self__106_13 == nil then
250
+ local ____opt_11 = self[100]
251
+ ____self__106_13 = ____opt_11 and ____opt_11.x
252
+ end
253
+ setTextTagPos(____ensureHandle_result_14, ____self__106_13 or 0, y, 0)
254
+ self[107] = y
255
+ self[100] = nil
256
+ unitTextTags[self] = nil
257
+ end
258
+ },
259
+ true
260
+ )
74
261
  TextTag.BASE = {
75
262
  fadepoint = 2,
76
263
  lifespan = 3,
@@ -137,7 +324,24 @@ TextTag.SHADOW_STRIKE = __TS__ObjectAssign(
137
324
  )
138
325
  Timer.onPeriod[1 / 64]:addListener(function()
139
326
  for textTag in pairs(unitTextTags) do
140
- setTextTagPosUnit(textTag.handle, textTag[100], textTag[101].offsetZ)
327
+ local unit = textTag[100].handle
328
+ local x = getUnitX(unit)
329
+ local y = getUnitY(unit)
330
+ local ____, ____, isInView = worldCoordinatesToFrame(
331
+ x,
332
+ y,
333
+ getUnitFlyHeight(unit) + getTerrainZ(x, y)
334
+ )
335
+ if isInView and not isUnitHidden(unit) and not isUnitLoaded(unit) and isUnitVisible(unit, PLAYER_LOCAL_HANDLE) then
336
+ setTextTagPosUnit(
337
+ ensureHandle(textTag),
338
+ unit,
339
+ textTag[102].offsetZ
340
+ )
341
+ elseif textTag[101] ~= nil then
342
+ destroyTextTag(textTag[101])
343
+ textTag[101] = nil
344
+ end
141
345
  end
142
346
  end)
143
347
  return ____exports
package/engine/unit.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  /** @noSelfInFile */
2
2
  import "./internal/unit";
3
+ import "./internal/unit/order";
3
4
  import "./internal/unit/ability";
4
5
  import "./internal/unit/allowed-targets";
5
6
  import "./internal/unit/buff";
package/engine/unit.lua CHANGED
@@ -1,5 +1,6 @@
1
1
  local ____exports = {}
2
2
  require("engine.internal.unit")
3
+ require("engine.internal.unit.order")
3
4
  require("engine.internal.unit.ability")
4
5
  require("engine.internal.unit.allowed-targets")
5
6
  require("engine.internal.unit.buff")
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.3bc4ba4",
4
+ "version": "0.0.1-dev.3dad3ec",
5
5
  "description": "A typescript library for Warcraft III using Warpack.",
6
6
  "keywords": [
7
7
  "warcraft",
@@ -24,7 +24,7 @@
24
24
  "@warscript/language-extensions": "^0.0.1",
25
25
  "@warscript/tstl-plugin": "^0.0.4",
26
26
  "lua-types": "^2.13.1",
27
- "warpack": "0.0.1-dev.fa5e065"
27
+ "warpack": "0.0.1-dev.78d2c64"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@typescript-eslint/eslint-plugin": "^8.13.0",
@@ -4,3 +4,10 @@ export declare const apply: {
4
4
  <T, ConsumerParameters extends any[], K extends KeysOfType<T, (...parameters: ConsumerParameters) => void>>(object: T, key: K, ...parameters: ConsumerParameters): T;
5
5
  };
6
6
  export declare const identity: <T>(value: T) => T;
7
+ export declare const firstArgument: <T>(value: T) => T;
8
+ export declare const secondArgument: <T>(_: unknown, value: T) => T;
9
+ export declare const thirdArgument: <T>(_first: unknown, _second: unknown, value: T) => T;
10
+ export declare const increment: (value: number) => number;
11
+ export declare const or: (lhs: boolean, rhs: boolean) => boolean;
12
+ export type Transform<T, R> = (<T, R>(value: T) => R) | KeysOfType<T, R>;
13
+ export declare const transform: <T, R>(object: T, transform: Transform<T, R>) => R;
@@ -88,4 +88,16 @@ ____exports.apply = function(object, transform, ...)
88
88
  return object
89
89
  end
90
90
  ____exports.identity = function(value) return value end
91
+ ____exports.firstArgument = ____exports.identity
92
+ ____exports.secondArgument = function(_, value) return value end
93
+ ____exports.thirdArgument = function(_first, _second, value) return value end
94
+ ____exports.increment = function(value) return value + 1 end
95
+ ____exports["or"] = function(lhs, rhs) return lhs or rhs end
96
+ ____exports.transform = function(object, transform)
97
+ if type(transform) == "function" then
98
+ return transform(object)
99
+ else
100
+ return object[transform]
101
+ end
102
+ end
91
103
  return ____exports
@@ -1,4 +1,5 @@
1
1
  /** @noSelfInFile */
2
+ export declare const emptyLuaSet: <T extends AnyNotNil>() => ReadonlyLuaSet<T>;
2
3
  export declare const mutableLuaSet: <T extends AnyNotNil>() => LuaSet<T>;
3
4
  export declare const luaSetOf: <T extends AnyNotNil>(...elements: readonly T[]) => LuaSet<T>;
4
5
  export declare const luaSetOfNotNull: <T extends AnyNotNil>(...elements: readonly (T | undefined | null)[]) => LuaSet<T>;
@@ -1,5 +1,9 @@
1
1
  local ____exports = {}
2
2
  local select = _G.select
3
+ local EMPTY_LUA_SET = {}
4
+ ____exports.emptyLuaSet = function()
5
+ return EMPTY_LUA_SET
6
+ end
3
7
  ____exports.mutableLuaSet = function()
4
8
  return {}
5
9
  end
@@ -1,26 +0,0 @@
1
- /** @noSelfInFile */
2
- import { Unit } from "./unit";
3
- import { Item } from "./item";
4
- import { Destructable } from "./destructable";
5
- export type Order = {
6
- id: number;
7
- startX: number;
8
- startY: number;
9
- issueTime: number;
10
- } & ({
11
- type: "immediate";
12
- } | {
13
- type: "point";
14
- targetX: number;
15
- targetY: number;
16
- } | {
17
- type: "target";
18
- target: Unit | Item | Destructable;
19
- });
20
- declare module "../../engine/internal/unit" {
21
- interface Unit {
22
- readonly currentOrder: Order;
23
- readonly lastOrder: Order;
24
- issueOrder(order: Order): void;
25
- }
26
- }
@@ -1,65 +0,0 @@
1
- local ____lualib = require("lualib_bundle")
2
- local __TS__ObjectDefineProperty = ____lualib.__TS__ObjectDefineProperty
3
- local ____exports = {}
4
- local ____unit = require("core.types.unit")
5
- local Unit = ____unit.Unit
6
- local ____game = require("core.game")
7
- local elapsedTime = ____game.elapsedTime
8
- local getUnitCurrentOrder = GetUnitCurrentOrder
9
- local orders = setmetatable({}, {__mode = "k"})
10
- Unit.onImmediateOrder:addListener(function(unit, orderId)
11
- orders[unit] = {
12
- id = orderId,
13
- startX = unit.x,
14
- startY = unit.y,
15
- issueTime = elapsedTime(),
16
- type = "immediate"
17
- }
18
- end)
19
- Unit.onPointOrder:addListener(function(unit, orderId, x, y)
20
- orders[unit] = {
21
- id = orderId,
22
- startX = unit.x,
23
- startY = unit.y,
24
- issueTime = elapsedTime(),
25
- type = "point",
26
- targetX = x,
27
- targetY = y
28
- }
29
- end)
30
- Unit.onTargetOrder:addListener(function(unit, orderId, target)
31
- orders[unit] = {
32
- id = orderId,
33
- startX = unit.x,
34
- startY = unit.y,
35
- issueTime = elapsedTime(),
36
- type = "target",
37
- target = target
38
- }
39
- end)
40
- __TS__ObjectDefineProperty(
41
- Unit.prototype,
42
- "currentOrder",
43
- {get = function(self)
44
- local currentOrderId = getUnitCurrentOrder(self.handle)
45
- local lastOrder = orders[self]
46
- return lastOrder and (lastOrder.id == currentOrderId or currentOrderId == orderId("patrolAI") and lastOrder.id == orderId("patrol")) and lastOrder or ({id = 0, type = "immediate"})
47
- end}
48
- )
49
- __TS__ObjectDefineProperty(
50
- Unit.prototype,
51
- "lastOrder",
52
- {get = function(self)
53
- return orders[self] or ({id = 0, type = "immediate"})
54
- end}
55
- )
56
- Unit.prototype.issueOrder = function(self, order)
57
- if order.type == "immediate" then
58
- IssueImmediateOrderById(self.handle, order.id)
59
- elseif order.type == "point" then
60
- IssuePointOrderById(self.handle, order.id, order.targetX, order.targetY)
61
- else
62
- IssueTargetOrderById(self.handle, order.id, order.target.handle)
63
- end
64
- end
65
- return ____exports