warscript 0.0.1-dev.e72b4b0 → 0.0.1-dev.ea102a7

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 (70) hide show
  1. package/core/types/frame.lua +24 -21
  2. package/core/types/player.lua +3 -1
  3. package/core/types/playerCamera.d.ts +2 -0
  4. package/core/types/playerCamera.lua +123 -5
  5. package/core/types/tileCell.d.ts +9 -0
  6. package/core/types/tileCell.lua +92 -0
  7. package/core/types/timer.d.ts +2 -1
  8. package/core/types/timer.lua +21 -2
  9. package/decl/native.d.ts +6 -4
  10. package/engine/behavior.d.ts +5 -0
  11. package/engine/behavior.lua +106 -27
  12. package/engine/behaviour/ability/apply-buff.lua +1 -1
  13. package/engine/behaviour/ability/emulate-impact.d.ts +1 -1
  14. package/engine/behaviour/ability/emulate-impact.lua +2 -1
  15. package/engine/behaviour/ability/restore-mana.d.ts +1 -1
  16. package/engine/behaviour/ability/restore-mana.lua +6 -6
  17. package/engine/behaviour/ability.lua +7 -16
  18. package/engine/behaviour/unit/stun-immunity.d.ts +7 -3
  19. package/engine/behaviour/unit/stun-immunity.lua +52 -27
  20. package/engine/behaviour/unit.d.ts +12 -2
  21. package/engine/behaviour/unit.lua +47 -7
  22. package/engine/buff.d.ts +2 -4
  23. package/engine/buff.lua +68 -83
  24. package/engine/internal/ability.d.ts +3 -1
  25. package/engine/internal/ability.lua +34 -11
  26. package/engine/internal/item/ability.lua +51 -1
  27. package/engine/internal/item+owner.lua +12 -6
  28. package/engine/internal/item.d.ts +13 -15
  29. package/engine/internal/item.lua +63 -49
  30. package/engine/internal/misc/frame-coordinates.d.ts +2 -0
  31. package/engine/internal/misc/frame-coordinates.lua +21 -0
  32. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  33. package/engine/internal/misc/get-terrain-z.lua +11 -0
  34. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  35. package/engine/internal/misc/player-local-handle.lua +5 -0
  36. package/engine/internal/unit/ability.lua +13 -5
  37. package/engine/internal/unit+ability.lua +10 -1
  38. package/engine/internal/unit-missile-launch.lua +18 -5
  39. package/engine/internal/unit.d.ts +5 -6
  40. package/engine/internal/unit.lua +73 -73
  41. package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
  42. package/engine/object-data/auxiliary/armor-type.lua +46 -0
  43. package/engine/object-data/entry/ability-type.lua +5 -4
  44. package/engine/object-data/entry/unit-type.d.ts +11 -2
  45. package/engine/object-data/entry/unit-type.lua +59 -1
  46. package/engine/object-field/ability.d.ts +3 -3
  47. package/engine/object-field/ability.lua +7 -6
  48. package/engine/object-field/unit.d.ts +7 -0
  49. package/engine/object-field/unit.lua +21 -0
  50. package/engine/object-field.d.ts +2 -2
  51. package/engine/object-field.lua +8 -6
  52. package/engine/random.d.ts +9 -0
  53. package/engine/random.lua +13 -0
  54. package/engine/standard/fields/unit.d.ts +2 -1
  55. package/engine/standard/fields/unit.lua +2 -0
  56. package/engine/text-tag.d.ts +1 -1
  57. package/engine/text-tag.lua +91 -17
  58. package/objutil/buff.lua +1 -1
  59. package/package.json +2 -2
  60. package/patch-lualib.lua +1 -1
  61. package/utility/arrays.d.ts +1 -0
  62. package/utility/arrays.lua +8 -0
  63. package/utility/callback-array.d.ts +13 -0
  64. package/utility/callback-array.lua +46 -0
  65. package/utility/functions.d.ts +7 -0
  66. package/utility/functions.lua +12 -0
  67. package/utility/lua-maps.d.ts +11 -2
  68. package/utility/lua-maps.lua +33 -2
  69. package/utility/lua-sets.d.ts +1 -0
  70. package/utility/lua-sets.lua +4 -0
@@ -58,9 +58,9 @@ end
58
58
  function ObjectFieldBase.prototype.supports(self, instance)
59
59
  return __TS__InstanceOf(instance, self.instanceClass)
60
60
  end
61
- function ObjectFieldBase.prototype.hasValue(self, instance)
61
+ function ObjectFieldBase.prototype.hasValue(self, objectDataEntryId)
62
62
  local defaultValueByObjectDataEntryId = defaultValueByObjectDataEntryIdByObjectFieldId[self.id]
63
- return self.isGlobal or defaultValueByObjectDataEntryId ~= nil and defaultValueByObjectDataEntryId[self:getObjectDataEntryId(instance)] ~= nil or self:hasNativeFieldValue(instance)
63
+ return self.isGlobal or defaultValueByObjectDataEntryId ~= nil and defaultValueByObjectDataEntryId[objectDataEntryId] ~= nil or self:hasNativeFieldValue(objectDataEntryId)
64
64
  end
65
65
  function ObjectFieldBase.create(self, id, isGlobal)
66
66
  return __TS__New(
@@ -215,8 +215,9 @@ function ObjectField.prototype.getActualValue(self, instance)
215
215
  end
216
216
  function ObjectField.prototype.setActualValue(self, instance, value)
217
217
  local defaultValueByObjectDataEntryId = defaultValueByObjectDataEntryIdByObjectFieldId[self.id]
218
+ local objectDataEntryId = self:getObjectDataEntryId(instance)
218
219
  if defaultValueByObjectDataEntryId ~= nil or self.isGlobal then
219
- local defaultValue = (defaultValueByObjectDataEntryId or emptyLuaMap())[self:getObjectDataEntryId(instance)]
220
+ local defaultValue = (defaultValueByObjectDataEntryId or emptyLuaMap())[objectDataEntryId]
220
221
  if defaultValue ~= nil or self.isGlobal then
221
222
  local ____self_valueByInstance_instance_3 = self.valueByInstance[instance]
222
223
  if ____self_valueByInstance_instance_3 == nil then
@@ -234,7 +235,7 @@ function ObjectField.prototype.setActualValue(self, instance, value)
234
235
  return true
235
236
  end
236
237
  end
237
- if not self:hasNativeFieldValue(instance) then
238
+ if not self:hasNativeFieldValue(objectDataEntryId) then
238
239
  return false
239
240
  end
240
241
  local previousValue = self:getNativeFieldValue(instance)
@@ -460,8 +461,9 @@ function ObjectLevelField.prototype.setValue(self, entry, levelOrValue, value)
460
461
  return true
461
462
  end
462
463
  local defaultValueByObjectDataEntryId = defaultValueByObjectDataEntryIdByObjectFieldId[self.id]
464
+ local objectDataEntryId = self:getObjectDataEntryId(entry)
463
465
  if defaultValueByObjectDataEntryId ~= nil or self.isGlobal then
464
- local defaultValueByLevel = (defaultValueByObjectDataEntryId or emptyLuaMap())[self:getObjectDataEntryId(entry)]
466
+ local defaultValueByLevel = (defaultValueByObjectDataEntryId or emptyLuaMap())[objectDataEntryId]
465
467
  if defaultValueByLevel ~= nil or self.isGlobal then
466
468
  local valueByLevel = self.valueByInstance[entry]
467
469
  if valueByLevel == nil then
@@ -490,7 +492,7 @@ function ObjectLevelField.prototype.setValue(self, entry, levelOrValue, value)
490
492
  return true
491
493
  end
492
494
  end
493
- if not self:hasNativeFieldValue(entry) then
495
+ if not self:hasNativeFieldValue(objectDataEntryId) then
494
496
  return false
495
497
  end
496
498
  local previousValue = self:getNativeFieldValue(entry, level)
@@ -1,4 +1,5 @@
1
1
  /** @noSelfInFile */
2
+ import { ReadonlyNonEmptyArray } from "../utility/types";
2
3
  export declare const randomAngle: () => number;
3
4
  export declare const randomInteger: {
4
5
  (upperBound?: number): number;
@@ -9,3 +10,11 @@ export declare const randomFloat: {
9
10
  (lowerBound: number, upperBound: number): number;
10
11
  };
11
12
  export declare const randomXY: (centerX: number, centerY: number, range: number) => LuaMultiReturn<[x: number, y: number]>;
13
+ export declare const randomElement: {
14
+ <T>(array: ReadonlyNonEmptyArray<T>): T;
15
+ <T>(array: ReadonlyArray<T>): T | undefined;
16
+ };
17
+ export declare const random: {
18
+ <T>(element: T, ...elements: T[]): T;
19
+ <T>(...elements: T[]): T | undefined;
20
+ };
package/engine/random.lua CHANGED
@@ -4,6 +4,7 @@ local MAXIMUM_INTEGER = ____math.MAXIMUM_INTEGER
4
4
  local PI = ____math.PI
5
5
  local getRandomInt = GetRandomInt
6
6
  local getRandomReal = GetRandomReal
7
+ local select = _G.select
7
8
  local cos = math.cos
8
9
  local sin = math.sin
9
10
  local sqrt = math.sqrt
@@ -15,4 +16,16 @@ ____exports.randomXY = function(centerX, centerY, range)
15
16
  local t = getRandomReal(0, 1) * 2 * PI
16
17
  return centerX + r * cos(t), centerY + r * sin(t)
17
18
  end
19
+ ____exports.randomElement = function(array)
20
+ return array[getRandomInt(1, #array)]
21
+ end
22
+ ____exports.random = function(...)
23
+ return (select(
24
+ getRandomInt(
25
+ 1,
26
+ select("#", ...)
27
+ ),
28
+ ...
29
+ ))
30
+ end
18
31
  return ____exports
@@ -1,3 +1,4 @@
1
1
  /** @noSelfInFile */
2
- import { UnitPropulsionWindowField } from "../../object-field/unit";
2
+ import { UnitClassificationsField, UnitPropulsionWindowField } from "../../object-field/unit";
3
3
  export declare const PROPULSION_WINDOW_UNIT_FLOAT_FIELD: UnitPropulsionWindowField & symbol;
4
+ export declare const UNIT_CLASSIFICATIONS_FIELD: UnitClassificationsField & symbol;
@@ -1,5 +1,7 @@
1
1
  local ____exports = {}
2
2
  local ____unit = require("engine.object-field.unit")
3
+ local UnitClassificationsField = ____unit.UnitClassificationsField
3
4
  local UnitPropulsionWindowField = ____unit.UnitPropulsionWindowField
4
5
  ____exports.PROPULSION_WINDOW_UNIT_FLOAT_FIELD = UnitPropulsionWindowField:create(fourCC("urpw"))
6
+ ____exports.UNIT_CLASSIFICATIONS_FIELD = UnitClassificationsField:create(fourCC("utyp"))
5
7
  return ____exports
@@ -23,7 +23,7 @@ declare const enum TextTagPropertyKey {
23
23
  Y = 107
24
24
  }
25
25
  export declare class TextTag extends AbstractDestroyable {
26
- private readonly [TextTagPropertyKey.HANDLE];
26
+ private [TextTagPropertyKey.HANDLE]?;
27
27
  private [TextTagPropertyKey.CONFIGURATION]?;
28
28
  private [TextTagPropertyKey.TEXT]?;
29
29
  private [TextTagPropertyKey.FONT_SIZE]?;
@@ -11,6 +11,12 @@ local ____timer = require("core.types.timer")
11
11
  local Timer = ____timer.Timer
12
12
  local ____destroyable = require("destroyable")
13
13
  local AbstractDestroyable = ____destroyable.AbstractDestroyable
14
+ local ____playerCamera = require("core.types.playerCamera")
15
+ local worldCoordinatesToFrame = ____playerCamera.worldCoordinatesToFrame
16
+ local ____get_2Dterrain_2Dz = require("engine.internal.misc.get-terrain-z")
17
+ local getTerrainZ = ____get_2Dterrain_2Dz.getTerrainZ
18
+ local ____player_2Dlocal_2Dhandle = require("engine.internal.misc.player-local-handle")
19
+ local PLAYER_LOCAL_HANDLE = ____player_2Dlocal_2Dhandle.PLAYER_LOCAL_HANDLE
14
20
  local createTextTag = CreateTextTag
15
21
  local destroyTextTag = DestroyTextTag
16
22
  local setTextTagText = SetTextTagText
@@ -24,6 +30,12 @@ local setTextTagPermanent = SetTextTagPermanent
24
30
  local setTextTagAge = SetTextTagAge
25
31
  local setTextTagLifespan = SetTextTagLifespan
26
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
27
39
  local DEFAULT_FONT_SIZE = 0.024
28
40
  local function applyConfiguration(textTag, configuration)
29
41
  setTextTagFadepoint(textTag, configuration.fadepoint)
@@ -41,6 +53,33 @@ local function applyConfiguration(textTag, configuration)
41
53
  setTextTagVisibility(textTag, true)
42
54
  end
43
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
44
83
  ____exports.TextTag = __TS__Class()
45
84
  local TextTag = ____exports.TextTag
46
85
  TextTag.name = "TextTag"
@@ -50,7 +89,11 @@ function TextTag.prototype.____constructor(self, handle)
50
89
  self[101] = handle
51
90
  end
52
91
  function TextTag.prototype.onDestroy(self)
53
- destroyTextTag(self[101])
92
+ local handle = self[101]
93
+ if handle ~= nil then
94
+ destroyTextTag(handle)
95
+ self[101] = nil
96
+ end
54
97
  unitTextTags[self] = nil
55
98
  return AbstractDestroyable.prototype.onDestroy(self)
56
99
  end
@@ -61,14 +104,11 @@ function TextTag.flash(self, configuration, text, x, y, z)
61
104
  applyConfiguration(textTag, configuration)
62
105
  end
63
106
  function TextTag.create(self, configuration, text, unit)
64
- local handle = createTextTag()
65
- setTextTagText(handle, text, DEFAULT_FONT_SIZE)
66
- setTextTagPosUnit(handle, unit.handle, configuration.offsetZ)
67
- applyConfiguration(handle, configuration)
68
- setTextTagPermanent(handle, true)
69
- local textTag = __TS__New(____exports.TextTag, handle)
107
+ local textTag = __TS__New(____exports.TextTag)
108
+ textTag[103] = text
70
109
  textTag[100] = unit
71
110
  textTag[102] = configuration
111
+ ensureHandle(textTag)
72
112
  unitTextTags[textTag] = true
73
113
  return textTag
74
114
  end
@@ -80,7 +120,11 @@ __TS__SetDescriptor(
80
120
  return self[103] or ""
81
121
  end,
82
122
  set = function(self, text)
83
- setTextTagText(self[101], text, self[104] or DEFAULT_FONT_SIZE)
123
+ setTextTagText(
124
+ ensureHandle(self),
125
+ text,
126
+ self[104] or DEFAULT_FONT_SIZE
127
+ )
84
128
  self[103] = text
85
129
  end
86
130
  },
@@ -94,7 +138,11 @@ __TS__SetDescriptor(
94
138
  return self[104] or DEFAULT_FONT_SIZE
95
139
  end,
96
140
  set = function(self, fontSize)
97
- setTextTagText(self[101], self[103] or "", DEFAULT_FONT_SIZE)
141
+ setTextTagText(
142
+ ensureHandle(self),
143
+ self[103] or "",
144
+ fontSize
145
+ )
98
146
  self[104] = fontSize
99
147
  end
100
148
  },
@@ -109,7 +157,7 @@ __TS__SetDescriptor(
109
157
  end,
110
158
  set = function(self, color)
111
159
  setTextTagColor(
112
- self[101],
160
+ ensureHandle(self),
113
161
  color.r,
114
162
  color.g,
115
163
  color.b,
@@ -129,7 +177,11 @@ __TS__SetDescriptor(
129
177
  end,
130
178
  set = function(self, unit)
131
179
  if unit ~= nil then
132
- setTextTagPosUnit(self[101], unit.handle, 0)
180
+ setTextTagPosUnit(
181
+ ensureHandle(self),
182
+ unit.handle,
183
+ 0
184
+ )
133
185
  self[106] = nil
134
186
  self[107] = nil
135
187
  unitTextTags[self] = true
@@ -137,7 +189,12 @@ __TS__SetDescriptor(
137
189
  local unit = self[100]
138
190
  local x = unit.x
139
191
  local y = unit.y
140
- setTextTagPos(self[101], x, y, 0)
192
+ setTextTagPos(
193
+ ensureHandle(self),
194
+ x,
195
+ y,
196
+ 0
197
+ )
141
198
  self[106] = x
142
199
  self[107] = y
143
200
  unitTextTags[self] = nil
@@ -160,14 +217,14 @@ __TS__SetDescriptor(
160
217
  return ____self__106_2 or 0
161
218
  end,
162
219
  set = function(self, x)
163
- local ____self__101_6 = self[101]
220
+ local ____ensureHandle_result_6 = ensureHandle(self)
164
221
  local ____x_7 = x
165
222
  local ____self__107_5 = self[107]
166
223
  if ____self__107_5 == nil then
167
224
  local ____opt_3 = self[100]
168
225
  ____self__107_5 = ____opt_3 and ____opt_3.y
169
226
  end
170
- setTextTagPos(____self__101_6, ____x_7, ____self__107_5 or 0, 0)
227
+ setTextTagPos(____ensureHandle_result_6, ____x_7, ____self__107_5 or 0, 0)
171
228
  self[106] = x
172
229
  self[100] = nil
173
230
  unitTextTags[self] = nil
@@ -188,13 +245,13 @@ __TS__SetDescriptor(
188
245
  return ____self__107_10 or 0
189
246
  end,
190
247
  set = function(self, y)
191
- local ____self__101_14 = self[101]
248
+ local ____ensureHandle_result_14 = ensureHandle(self)
192
249
  local ____self__106_13 = self[106]
193
250
  if ____self__106_13 == nil then
194
251
  local ____opt_11 = self[100]
195
252
  ____self__106_13 = ____opt_11 and ____opt_11.x
196
253
  end
197
- setTextTagPos(____self__101_14, ____self__106_13 or 0, y, 0)
254
+ setTextTagPos(____ensureHandle_result_14, ____self__106_13 or 0, y, 0)
198
255
  self[107] = y
199
256
  self[100] = nil
200
257
  unitTextTags[self] = nil
@@ -268,7 +325,24 @@ TextTag.SHADOW_STRIKE = __TS__ObjectAssign(
268
325
  )
269
326
  Timer.onPeriod[1 / 64]:addListener(function()
270
327
  for textTag in pairs(unitTextTags) do
271
- setTextTagPosUnit(textTag[101], textTag[100].handle, textTag[102].offsetZ)
328
+ local unit = textTag[100].handle
329
+ local x = getUnitX(unit)
330
+ local y = getUnitY(unit)
331
+ local ____, ____, isInView = worldCoordinatesToFrame(
332
+ x,
333
+ y,
334
+ getUnitFlyHeight(unit) + getTerrainZ(x, y)
335
+ )
336
+ if isInView and not isUnitHidden(unit) and not isUnitLoaded(unit) and isUnitVisible(unit, PLAYER_LOCAL_HANDLE) then
337
+ setTextTagPosUnit(
338
+ ensureHandle(textTag),
339
+ unit,
340
+ textTag[102].offsetZ
341
+ )
342
+ elseif textTag[101] ~= nil then
343
+ destroyTextTag(textTag[101])
344
+ textTag[101] = nil
345
+ end
272
346
  end
273
347
  end)
274
348
  return ____exports
package/objutil/buff.lua CHANGED
@@ -762,7 +762,7 @@ Unit.onDamaging:addListener(function(source, target, event)
762
762
  end
763
763
  end)
764
764
  Unit.itemPickedUpEvent:addListener(function(unit, item)
765
- if item.powerup and item:hasAbility(fourCC("APdi")) then
765
+ if item.isPowerUp and item:hasAbility(fourCC("APdi")) then
766
766
  end
767
767
  end)
768
768
  return ____exports
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.e72b4b0",
4
+ "version": "0.0.1-dev.ea102a7",
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.251db08"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@typescript-eslint/eslint-plugin": "^8.13.0",
package/patch-lualib.lua CHANGED
@@ -3,7 +3,7 @@ local lualib = _G.require("lualib_bundle")
3
3
  local next = _G.next
4
4
  local ____type = _G.type
5
5
  lualib.__TS__ArrayIsArray = function(value)
6
- return ____type(value) == "table" and (value[1] ~= nil or ({next(value)}) == nil) and value.constructor == nil
6
+ return ____type(value) == "table" and (value[1] ~= nil or (next(value)) == nil) and value.constructor == nil
7
7
  end
8
8
  local __TS__SetDescriptor = lualib.__TS__SetDescriptor
9
9
  lualib.__TS__ObjectDefineProperty = function(target, key, desc)
@@ -5,6 +5,7 @@ export declare const joinToString: <T>(array: readonly T[], separator: string, t
5
5
  export declare const arrayOfNotNull: <T>(...elements: readonly (T | undefined | null)[]) => T[];
6
6
  export declare const array: <T, N extends number>(length: N, initialize: (index: number) => T) => TupleOf<T, N>;
7
7
  export declare const toLuaSet: <T extends AnyNotNil>(array: readonly T[]) => LuaSet<T>;
8
+ export declare const contains: <T>(array: readonly T[], element: T) => boolean;
8
9
  export declare const forEach: <T, Args extends any[]>(array: readonly T[], consumerOrKey: ((value: T, ...args: Args) => void) | KeysOfType<T, (this: T, ...args: Args) => void>, ...args: Args) => void;
9
10
  export declare const all: {
10
11
  <T>(array: readonly T[], transform: (value: T) => boolean): boolean;
@@ -49,6 +49,14 @@ ____exports.toLuaSet = function(array)
49
49
  end
50
50
  return result
51
51
  end
52
+ ____exports.contains = function(array, element)
53
+ for i = 1, #array do
54
+ if array[i] == element then
55
+ return true
56
+ end
57
+ end
58
+ return false
59
+ end
52
60
  ____exports.forEach = function(array, consumerOrKey, ...)
53
61
  if type(consumerOrKey) == "function" then
54
62
  for i = 1, #array do
@@ -0,0 +1,13 @@
1
+ /** @noSelfInFile */
2
+ type Callback = {
3
+ readonly __callback: unique symbol;
4
+ };
5
+ export type CallbackArray = {
6
+ readonly __callbackArray: unique symbol;
7
+ } & Callback[];
8
+ export declare const callbackArray: () => CallbackArray;
9
+ export declare function addCallback<Args extends any[]>(this: void, array: CallbackArray, callback: (...args: Args) => unknown, ...args: Args): void;
10
+ export declare function clearCallbacks(this: void, array: CallbackArray): void;
11
+ export declare function consumeCallbacks(this: void, array: CallbackArray): void;
12
+ export declare function invokeCallbacks(this: void, array: CallbackArray): void;
13
+ export {};
@@ -0,0 +1,46 @@
1
+ local ____exports = {}
2
+ local safeCall, tableUnpack
3
+ function ____exports.invokeCallbacks(array)
4
+ local length = array[1] or 2
5
+ local i = 2
6
+ while i ~= length do
7
+ local callback = array[i]
8
+ i = i + 1
9
+ local argsCount = array[i]
10
+ i = i + 1
11
+ safeCall(
12
+ callback,
13
+ tableUnpack(array, i, i + argsCount - 1)
14
+ )
15
+ i = i + argsCount
16
+ end
17
+ end
18
+ safeCall = warpack.safeCall
19
+ local select = _G.select
20
+ local tableMove = table.move
21
+ tableUnpack = table.unpack
22
+ ____exports.callbackArray = function() return {} end
23
+ function ____exports.addCallback(array, callback, ...)
24
+ local i = array[1] or 2
25
+ array[i] = callback
26
+ local argsCount = select("#", ...)
27
+ i = i + 1
28
+ array[i] = argsCount
29
+ for j = 1, argsCount do
30
+ i = i + 1
31
+ array[i] = (select(j, ...))
32
+ end
33
+ array[1] = i + 1
34
+ end
35
+ function ____exports.clearCallbacks(array)
36
+ local length = array[1] or 2
37
+ tableMove(array, length, length + length - 2, 1)
38
+ end
39
+ function ____exports.consumeCallbacks(array)
40
+ local length = array[1] or 2
41
+ ____exports.invokeCallbacks(array)
42
+ local newLength = array[1] or 2
43
+ tableMove(array, length, length + newLength - 3, 2)
44
+ array[1] = newLength - length + 2
45
+ end
46
+ return ____exports
@@ -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
@@ -4,6 +4,15 @@ export declare const emptyLuaMap: <K extends AnyNotNil, V>() => ReadonlyLuaMap<K
4
4
  export declare const mutableLuaMap: <K extends AnyNotNil, V>() => LuaMap<K, V>;
5
5
  export declare const mutableWeakLuaMap: <K extends AnyNotNil, V>() => LuaMap<K, V>;
6
6
  export declare const luaMapOf: <K extends AnyNotNil, V>(...pairs: Flatten<TupleOf<[K, V], 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40>>) => LuaMap<K, V>;
7
- export declare const luaMapInvert: <K extends AnyNotNil, V extends AnyNotNil>(luaMap: LuaMap<K, V>) => LuaMap<V, K>;
8
- export declare const mapValues: <K extends AnyNotNil, V1, V2>(luaMap: LuaMap<K, V1>, transform: (value: V1) => V2) => LuaMap<K, V2>;
7
+ export declare const luaMapInvert: <K extends AnyNotNil, V extends AnyNotNil>(luaMap: ReadonlyLuaMap<K, V | undefined | null>) => LuaMap<V, K>;
8
+ export declare const toLuaMap: <K extends PropertyKey, V>(record: Record<K, V>) => LuaMap<K, V>;
9
+ export declare const flattenKeys: <K extends AnyNotNil, V>(luaMap: ReadonlyLuaMap<readonly K[], V> | ReadonlyLuaMap<K[], V>) => LuaMap<K, V>;
10
+ export declare const mapKeys: {
11
+ <K1 extends AnyNotNil, K2 extends AnyNotNil, V>(luaMap: ReadonlyLuaMap<K1, V>, transform: (value: K1) => K2): LuaMap<K2, V>;
12
+ <K1 extends AnyNotNil, K2 extends keyof K1, V>(luaMap: ReadonlyLuaMap<K1, V>, key: K2): K1[K2] extends AnyNotNil ? LuaMap<K1[K2], V> : never;
13
+ };
14
+ export declare const mapValues: {
15
+ <K extends AnyNotNil, V1, V2>(luaMap: ReadonlyLuaMap<K, V1>, transform: (value: V1) => V2): LuaMap<K, V2>;
16
+ <K extends AnyNotNil, V1, V2 extends keyof V1>(luaMap: ReadonlyLuaMap<K, V1>, key: V2): LuaMap<K, V1[V2]>;
17
+ };
9
18
  export declare const getOrPut: <K extends AnyNotNil, V>(luaMap: LuaMap<K, V>, key: K, defaultValue: () => V) => V;
@@ -27,10 +27,41 @@ ____exports.luaMapInvert = function(luaMap)
27
27
  end
28
28
  return invertLuaMap
29
29
  end
30
+ ____exports.toLuaMap = function(record)
31
+ return record
32
+ end
33
+ ____exports.flattenKeys = function(luaMap)
34
+ local result = {}
35
+ for keys, value in pairs(luaMap) do
36
+ for ____, key in ipairs(keys) do
37
+ result[key] = value
38
+ end
39
+ end
40
+ return result
41
+ end
42
+ ____exports.mapKeys = function(luaMap, transform)
43
+ local result = {}
44
+ if type(transform) == "function" then
45
+ for key, value in pairs(luaMap) do
46
+ result[transform(key)] = value
47
+ end
48
+ else
49
+ for key, value in pairs(luaMap) do
50
+ result[key[transform]] = value
51
+ end
52
+ end
53
+ return result
54
+ end
30
55
  ____exports.mapValues = function(luaMap, transform)
31
56
  local result = {}
32
- for key, value in pairs(luaMap) do
33
- result[key] = transform(value)
57
+ if type(transform) == "function" then
58
+ for key, value in pairs(luaMap) do
59
+ result[key] = transform(value)
60
+ end
61
+ else
62
+ for key, value in pairs(luaMap) do
63
+ result[key] = value[transform]
64
+ end
34
65
  end
35
66
  return result
36
67
  end
@@ -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