warscript 0.0.1-dev.f0a9ffe → 0.0.1-dev.f0daa48

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 (132) hide show
  1. package/attributes.d.ts +1 -0
  2. package/attributes.lua +9 -0
  3. package/core/types/frame.lua +24 -21
  4. package/core/types/player.d.ts +16 -0
  5. package/core/types/player.lua +60 -15
  6. package/core/types/playerCamera.d.ts +2 -0
  7. package/core/types/playerCamera.lua +123 -5
  8. package/core/types/sound.lua +1 -1
  9. package/core/types/tileCell.d.ts +11 -1
  10. package/core/types/tileCell.lua +97 -0
  11. package/core/types/timer.d.ts +3 -2
  12. package/core/types/timer.lua +22 -2
  13. package/decl/native.d.ts +2 -2
  14. package/destroyable.d.ts +1 -0
  15. package/destroyable.lua +9 -0
  16. package/engine/behavior.d.ts +12 -1
  17. package/engine/behavior.lua +199 -65
  18. package/engine/behaviour/ability/apply-buff.lua +4 -4
  19. package/engine/behaviour/ability/remove-buffs.d.ts +9 -0
  20. package/engine/behaviour/ability/remove-buffs.lua +21 -0
  21. package/engine/behaviour/ability.d.ts +11 -6
  22. package/engine/behaviour/ability.lua +31 -1
  23. package/engine/behaviour/unit/stun-immunity.d.ts +9 -5
  24. package/engine/behaviour/unit/stun-immunity.lua +17 -7
  25. package/engine/behaviour/unit.d.ts +15 -5
  26. package/engine/behaviour/unit.lua +126 -22
  27. package/engine/buff.d.ts +64 -21
  28. package/engine/buff.lua +360 -178
  29. package/engine/internal/ability.d.ts +3 -1
  30. package/engine/internal/ability.lua +26 -9
  31. package/engine/internal/item+owner.lua +12 -6
  32. package/engine/internal/item.d.ts +13 -15
  33. package/engine/internal/item.lua +63 -49
  34. package/engine/internal/mechanics/cast-ability.lua +6 -3
  35. package/engine/internal/misc/frame-coordinates.lua +21 -0
  36. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  37. package/engine/internal/misc/get-terrain-z.lua +11 -0
  38. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  39. package/engine/internal/misc/player-local-handle.lua +5 -0
  40. package/engine/internal/object-data/armor-bonus.d.ts +2 -0
  41. package/engine/internal/object-data/attribute-bonus.lua +2 -2
  42. package/engine/internal/object-data/health-bonus.d.ts +2 -0
  43. package/engine/internal/object-data/health-bonus.lua +16 -0
  44. package/engine/internal/object-data/mana-bonus.d.ts +2 -0
  45. package/engine/internal/object-data/mana-bonus.lua +16 -0
  46. package/engine/internal/object-data/mana-regeneration-rate-increase-factor.d.ts +2 -0
  47. package/engine/internal/object-data/mana-regeneration-rate-increase-factor.lua +16 -0
  48. package/engine/internal/unit/ability.d.ts +14 -14
  49. package/engine/internal/unit/ability.lua +72 -45
  50. package/engine/internal/unit/attributes.d.ts +17 -0
  51. package/engine/internal/unit/attributes.lua +46 -0
  52. package/engine/internal/unit/bonus.d.ts +6 -0
  53. package/engine/internal/unit/bonus.lua +33 -3
  54. package/engine/internal/unit/fly-height.d.ts +7 -0
  55. package/engine/internal/unit/fly-height.lua +20 -0
  56. package/engine/internal/unit/interrupts.d.ts +12 -0
  57. package/engine/internal/unit/interrupts.lua +28 -0
  58. package/engine/internal/unit/item.lua +1 -1
  59. package/engine/internal/unit/main-selected.lua +12 -27
  60. package/engine/internal/unit/range-event.d.ts +12 -0
  61. package/engine/internal/unit/range-event.lua +90 -0
  62. package/engine/internal/unit/scale.d.ts +7 -0
  63. package/engine/internal/unit/scale.lua +20 -0
  64. package/engine/internal/unit+ability.lua +10 -1
  65. package/engine/internal/unit+bonus.lua +3 -3
  66. package/engine/internal/unit-missile-launch.lua +51 -20
  67. package/engine/internal/unit.d.ts +18 -22
  68. package/engine/internal/unit.lua +179 -200
  69. package/engine/local-client.d.ts +2 -0
  70. package/engine/local-client.lua +30 -0
  71. package/engine/object-data/auxiliary/health-regeneration-type.d.ts +8 -0
  72. package/engine/object-data/auxiliary/health-regeneration-type.lua +2 -0
  73. package/engine/object-data/auxiliary/unit-attribute.lua +1 -1
  74. package/engine/object-data/entry/ability-type/{armor-increase.d.ts → armor-bonus.d.ts} +3 -3
  75. package/engine/object-data/entry/ability-type/{armor-increase.lua → armor-bonus.lua} +9 -9
  76. package/engine/object-data/entry/ability-type/health-bonus.d.ts +8 -0
  77. package/engine/object-data/entry/ability-type/health-bonus.lua +26 -0
  78. package/engine/object-data/entry/ability-type/mana-bonus.d.ts +8 -0
  79. package/engine/object-data/entry/ability-type/mana-bonus.lua +26 -0
  80. package/engine/object-data/entry/ability-type/mana-regeneration.d.ts +8 -0
  81. package/engine/object-data/entry/ability-type/mana-regeneration.lua +26 -0
  82. package/engine/object-data/entry/ability-type/reincarnation.d.ts +8 -0
  83. package/engine/object-data/entry/ability-type/reincarnation.lua +26 -0
  84. package/engine/object-data/entry/ability-type.d.ts +2 -0
  85. package/engine/object-data/entry/ability-type.lua +88 -5
  86. package/engine/object-data/entry/buff-type/applicable.lua +113 -109
  87. package/engine/object-data/entry/destructible-type.d.ts +27 -1
  88. package/engine/object-data/entry/destructible-type.lua +155 -0
  89. package/engine/object-data/entry/unit-type.d.ts +4 -0
  90. package/engine/object-data/entry/unit-type.lua +76 -32
  91. package/engine/object-field/ability.d.ts +3 -3
  92. package/engine/object-field/ability.lua +9 -8
  93. package/engine/object-field/unit.d.ts +20 -5
  94. package/engine/object-field/unit.lua +61 -0
  95. package/engine/object-field.d.ts +12 -4
  96. package/engine/object-field.lua +273 -126
  97. package/engine/random.d.ts +10 -0
  98. package/engine/random.lua +21 -0
  99. package/engine/standard/fields/ability.d.ts +2 -2
  100. package/engine/standard/fields/ability.lua +2 -2
  101. package/engine/standard/fields/unit.d.ts +11 -3
  102. package/engine/standard/fields/unit.lua +15 -2
  103. package/engine/synchronization.d.ts +11 -0
  104. package/engine/synchronization.lua +77 -0
  105. package/engine/text-tag.d.ts +1 -1
  106. package/engine/text-tag.lua +92 -17
  107. package/engine/unit.d.ts +5 -0
  108. package/engine/unit.lua +5 -0
  109. package/lualib_bundle.lua +118 -47
  110. package/net/socket.lua +1 -1
  111. package/objutil/buff.lua +10 -8
  112. package/objutil/object.lua +1 -1
  113. package/operation.lua +23 -17
  114. package/package.json +5 -5
  115. package/patch-lua.lua +15 -0
  116. package/patch-lualib.lua +1 -1
  117. package/utility/arrays.d.ts +1 -0
  118. package/utility/arrays.lua +8 -0
  119. package/utility/callback-array.d.ts +17 -0
  120. package/utility/callback-array.lua +61 -0
  121. package/utility/linked-map.d.ts +34 -0
  122. package/utility/linked-map.lua +101 -0
  123. package/utility/linked-set.d.ts +3 -1
  124. package/utility/linked-set.lua +40 -1
  125. package/utility/lua-maps.d.ts +11 -2
  126. package/utility/lua-maps.lua +33 -2
  127. package/utility/records.lua +20 -1
  128. package/utility/types.d.ts +3 -0
  129. /package/engine/internal/{object-data/armor-increase.d.ts → misc/frame-coordinates.d.ts} +0 -0
  130. /package/engine/internal/object-data/{armor-increase.lua → armor-bonus.lua} +0 -0
  131. /package/engine/object-data/entry/ability-type/{attribute-increase.d.ts → attribute-bonus.d.ts} +0 -0
  132. /package/engine/object-data/entry/ability-type/{attribute-increase.lua → attribute-bonus.lua} +0 -0
package/objutil/buff.lua CHANGED
@@ -29,6 +29,8 @@ local ____timer = require("core.types.timer")
29
29
  local Timer = ____timer.Timer
30
30
  local ____exception = require("exception")
31
31
  local IllegalStateException = ____exception.IllegalStateException
32
+ local ____linked_2Dmap = require("utility.linked-map")
33
+ local LinkedMap = ____linked_2Dmap.LinkedMap
32
34
  local ____assert = _G.assert
33
35
  local ____pairs = _G.pairs
34
36
  ____exports.BuffDefinition = __TS__Class()
@@ -461,7 +463,7 @@ local buffs = setmetatable(
461
463
  {
462
464
  __mode = "k",
463
465
  __index = function(self, unit)
464
- local ____table = {}
466
+ local ____table = __TS__New(LinkedMap)
465
467
  self[unit] = ____table
466
468
  return ____table
467
469
  end
@@ -494,7 +496,7 @@ function Buff.prototype.____constructor(self, unit, source, duration, level, pre
494
496
  end
495
497
  local constructor = self.constructor
496
498
  local instances = buffs[unit]
497
- local instance = instances[constructor]
499
+ local instance = instances:get(constructor)
498
500
  if instance then
499
501
  instance:destroy()
500
502
  if not instance.destroyed then
@@ -507,7 +509,7 @@ function Buff.prototype.____constructor(self, unit, source, duration, level, pre
507
509
  )
508
510
  end
509
511
  end
510
- instances[constructor] = self
512
+ instances:put(constructor, self)
511
513
  if preset then
512
514
  local unitHandle = unit.handle
513
515
  local slowPoisonMethod = not preset.positive and not preset.magic
@@ -586,13 +588,13 @@ function Buff.apply(self, ...)
586
588
  end
587
589
  end
588
590
  function Buff.getInstance(self, unit)
589
- return buffs[unit][self]
591
+ return buffs[unit]:get(self)
590
592
  end
591
593
  function Buff.isApplied(self, unit)
592
- return buffs[unit][self] ~= nil
594
+ return buffs[unit]:get(self) ~= nil
593
595
  end
594
596
  function Buff.ifApplied(self, unit, action)
595
- local instance = buffs[unit][self]
597
+ local instance = buffs[unit]:get(self)
596
598
  if instance then
597
599
  ____assert(__TS__InstanceOf(instance, self))
598
600
  action(instance)
@@ -615,7 +617,7 @@ function Buff.prototype.destroy(self)
615
617
  if self.preset then
616
618
  self.unit:removeAbility(self.preset.buffId)
617
619
  end
618
- buffs[self.unit][self.constructor] = nil
620
+ buffs[self.unit]:remove(self.constructor)
619
621
  self.destroyed = true
620
622
  end
621
623
  function Buff.prototype.onDispel(self, source)
@@ -762,7 +764,7 @@ Unit.onDamaging:addListener(function(source, target, event)
762
764
  end
763
765
  end)
764
766
  Unit.itemPickedUpEvent:addListener(function(unit, item)
765
- if item.powerup and item:hasAbility(fourCC("APdi")) then
767
+ if item.isPowerUp and item:hasAbility(fourCC("APdi")) then
766
768
  end
767
769
  end)
768
770
  return ____exports
@@ -153,7 +153,7 @@ end
153
153
  function ObjectDefinition.getLevelArrayFieldValue(self, level, value, values)
154
154
  return type(values) == "function" and values(level, value) or (__TS__ArrayIsArray(values[1]) and values[1] or values)
155
155
  end
156
- ____exports.ObjectType = ObjectType or ({})
156
+ ____exports.ObjectType = ____exports.ObjectType or ({})
157
157
  ____exports.ObjectType.ABILITY = 0
158
158
  ____exports.ObjectType[____exports.ObjectType.ABILITY] = "ABILITY"
159
159
  ____exports.ObjectType.ITEM = 1
package/operation.lua CHANGED
@@ -22,10 +22,7 @@ OperationMonitor.name = "OperationMonitor"
22
22
  __TS__ClassExtends(OperationMonitor, __TS__Promise)
23
23
  function OperationMonitor.prototype.____constructor(self, operation, ...)
24
24
  local args = {...}
25
- __TS__Promise.prototype.____constructor(
26
- self,
27
- table.unpack(args)
28
- )
25
+ __TS__Promise.prototype.____constructor(self, ...)
29
26
  self.o = operation
30
27
  end
31
28
  function OperationMonitor.prototype.cancel(self)
@@ -57,6 +54,7 @@ function Operation.prototype.execute(self)
57
54
  return __TS__AsyncAwaiter(function(____awaiter_resolve)
58
55
  local result
59
56
  local progress = self.progress
57
+ local ____hasReturned, ____returnValue
60
58
  local ____try = __TS__AsyncAwaiter(function()
61
59
  local maximum = __TS__Await(self:estimate())
62
60
  self.maximum = maximum
@@ -79,7 +77,8 @@ function Operation.prototype.execute(self)
79
77
  if onComplete ~= nil then
80
78
  Event.invoke(onComplete, self, false, reason)
81
79
  end
82
- return ____awaiter_resolve(nil)
80
+ ____hasReturned = true
81
+ return
83
82
  end
84
83
  result = __TS__Await(self:work())
85
84
  if self.progress ~= progress or self.maximum ~= maximum then
@@ -93,21 +92,28 @@ function Operation.prototype.execute(self)
93
92
  end
94
93
  until not (result == OperationContinue)
95
94
  end)
96
- __TS__Await(____try.catch(
95
+ ____try = ____try.catch(
97
96
  ____try,
98
97
  function(____, reason)
99
- reject(nil, reason)
100
- local onFailure = ____rawget(self, "onFailure")
101
- if onFailure ~= nil then
102
- Event.invoke(onFailure, self, reason)
103
- end
104
- local onComplete = ____rawget(self, "onComplete")
105
- if onComplete ~= nil then
106
- Event.invoke(onComplete, self, false, reason)
107
- end
108
- return ____awaiter_resolve(nil)
98
+ return __TS__AsyncAwaiter(function()
99
+ reject(nil, reason)
100
+ local onFailure = ____rawget(self, "onFailure")
101
+ if onFailure ~= nil then
102
+ Event.invoke(onFailure, self, reason)
103
+ end
104
+ local onComplete = ____rawget(self, "onComplete")
105
+ if onComplete ~= nil then
106
+ Event.invoke(onComplete, self, false, reason)
107
+ end
108
+ ____hasReturned = true
109
+ return
110
+ end)
109
111
  end
110
- ))
112
+ )
113
+ __TS__Await(____try)
114
+ if ____hasReturned then
115
+ return ____awaiter_resolve(nil, ____returnValue)
116
+ end
111
117
  resolve(nil, result)
112
118
  local onSuccess = ____rawget(self, "onSuccess")
113
119
  if onSuccess ~= nil then
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.f0a9ffe",
4
+ "version": "0.0.1-dev.f0daa48",
5
5
  "description": "A typescript library for Warcraft III using Warpack.",
6
6
  "keywords": [
7
7
  "warcraft",
@@ -22,13 +22,13 @@
22
22
  },
23
23
  "peerDependencies": {
24
24
  "@warscript/language-extensions": "^0.0.1",
25
- "@warscript/tstl-plugin": "^0.0.4",
25
+ "@warscript/tstl-plugin": "^0.0.5",
26
26
  "lua-types": "^2.13.1",
27
- "warpack": "0.0.1-dev.78d2c64"
27
+ "warpack": "0.0.1-dev.e490aaf"
28
28
  },
29
29
  "devDependencies": {
30
- "@typescript-eslint/eslint-plugin": "^8.13.0",
31
- "@typescript-eslint/parser": "^8.13.0",
30
+ "@typescript-eslint/eslint-plugin": "^8.61.1",
31
+ "@typescript-eslint/parser": "^8.61.1",
32
32
  "async": "^3.2.6",
33
33
  "copyfiles": "^2.4.1",
34
34
  "eslint": "^9.14.0",
package/patch-lua.lua CHANGED
@@ -1,5 +1,9 @@
1
+ local error = _G.error
1
2
  local getmetatable = _G.getmetatable
2
3
  local ipairs = _G.ipairs
4
+ local select = _G.select
5
+ local tostring = _G.tostring
6
+ local tableconcat = table.concat
3
7
 
4
8
  _G.ipairs = function(t)
5
9
  local metatable = getmetatable(t)
@@ -8,3 +12,14 @@ _G.ipairs = function(t)
8
12
  end
9
13
  return ipairs(t)
10
14
  end
15
+
16
+ _G.assert = function(v, ...)
17
+ if not v then
18
+ local args = {}
19
+ for i = 1, select("#", ...) do
20
+ args[i] = tostring(select(i, ...))
21
+ end
22
+ error(tableconcat(args, " "))
23
+ end
24
+ return v, ...
25
+ end
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,17 @@
1
+ /** @noSelfInFile */
2
+ type Callback = {
3
+ readonly __callback: unique symbol;
4
+ };
5
+ export type CallbackId = number & {
6
+ readonly __callbackId: unique symbol;
7
+ };
8
+ export type CallbackArray = {
9
+ readonly __callbackArray: unique symbol;
10
+ } & Callback[];
11
+ export declare const callbackArray: () => CallbackArray;
12
+ export declare function addCallback<Args extends any[]>(this: void, array: CallbackArray, callback: (...args: Args) => unknown, ...args: Args): CallbackId;
13
+ export declare function clearCallbacks(this: void, array: CallbackArray): void;
14
+ export declare function consumeCallback(this: void, array: CallbackArray, id: CallbackId): void;
15
+ export declare function consumeCallbacks(this: void, array: CallbackArray): void;
16
+ export declare function invokeCallbacks(this: void, array: CallbackArray): void;
17
+ export {};
@@ -0,0 +1,61 @@
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
+ local function doNothing()
24
+ end
25
+ function ____exports.addCallback(array, callback, ...)
26
+ local id = array[1] or 2
27
+ local i = id
28
+ array[i] = callback
29
+ local argsCount = select("#", ...)
30
+ i = i + 1
31
+ array[i] = argsCount
32
+ for j = 1, argsCount do
33
+ i = i + 1
34
+ array[i] = (select(j, ...))
35
+ end
36
+ array[1] = i + 1
37
+ return id
38
+ end
39
+ function ____exports.clearCallbacks(array)
40
+ local length = array[1] or 2
41
+ tableMove(array, length, length + length - 2, 1)
42
+ end
43
+ function ____exports.consumeCallback(array, id)
44
+ local callback = array[id]
45
+ array[id] = doNothing
46
+ id = id + 1
47
+ local argsCount = array[id]
48
+ id = id + 1
49
+ safeCall(
50
+ callback,
51
+ tableUnpack(array, id, id + argsCount - 1)
52
+ )
53
+ end
54
+ function ____exports.consumeCallbacks(array)
55
+ local length = array[1] or 2
56
+ ____exports.invokeCallbacks(array)
57
+ local newLength = array[1] or 2
58
+ tableMove(array, length, length + newLength - 3, 2)
59
+ array[1] = newLength - length + 2
60
+ end
61
+ return ____exports
@@ -0,0 +1,34 @@
1
+ /** @noSelfInFile */
2
+ import { ReadonlyLinkedSet } from "./linked-set";
3
+ type IteratorState<K extends AnyNotNil, V> = {
4
+ n?: K;
5
+ t: LuaMap<K, K>;
6
+ v: LuaMap<K, V>;
7
+ };
8
+ type OneSidedTypeGuard = {
9
+ readonly __oneSidedTypeGuard: unique symbol;
10
+ };
11
+ export interface ReadonlyLinkedMap<K extends AnyNotNil, V> extends LuaPairsIterable<K, V> {
12
+ readonly keys: ReadonlyLinkedSet<K>;
13
+ get(key: K): V | undefined;
14
+ contains(key: AnyNotNil): key is K & OneSidedTypeGuard;
15
+ readonly size: number;
16
+ }
17
+ export interface LinkedMap<K extends AnyNotNil, V> extends LuaPairsIterable<K, V> {
18
+ readonly __linkedSet: unique symbol;
19
+ }
20
+ export declare class LinkedMap<K extends AnyNotNil, V> implements ReadonlyLinkedMap<K, V> {
21
+ private k;
22
+ private v;
23
+ get keys(): ReadonlyLinkedSet<K>;
24
+ get(key: K): V | undefined;
25
+ getOrPut(key: K, defaultValue: (this: void) => V): V;
26
+ put(key: K, value: V): void;
27
+ remove(key: K): boolean;
28
+ contains(key: AnyNotNil): key is K & OneSidedTypeGuard;
29
+ get size(): number;
30
+ protected __pairs(this: LinkedMap<K, V>): LuaIterator<LuaMultiReturn<[K | undefined, V | undefined]>, IteratorState<K, V>>;
31
+ }
32
+ export declare const emptyLinkedMap: <K extends AnyNotNil, V>() => ReadonlyLinkedMap<K, V>;
33
+ export declare const mutableLinkedMap: <K extends AnyNotNil, V>() => LinkedMap<K, V>;
34
+ export {};
@@ -0,0 +1,101 @@
1
+ local ____lualib = require("lualib_bundle")
2
+ local __TS__Class = ____lualib.__TS__Class
3
+ local __TS__New = ____lualib.__TS__New
4
+ local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
5
+ local __TS__ClassExtends = ____lualib.__TS__ClassExtends
6
+ local ____exports = {}
7
+ local ____linked_2Dset = require("utility.linked-set")
8
+ local LinkedSet = ____linked_2Dset.LinkedSet
9
+ local ____exception = require("exception")
10
+ local UnsupportedOperationException = ____exception.UnsupportedOperationException
11
+ local function linkedMapNext(state)
12
+ local n = state.n
13
+ state.n = state.t[n]
14
+ return n, state.v[n]
15
+ end
16
+ ____exports.LinkedMap = __TS__Class()
17
+ local LinkedMap = ____exports.LinkedMap
18
+ LinkedMap.name = "LinkedMap"
19
+ function LinkedMap.prototype.____constructor(self)
20
+ self.k = __TS__New(LinkedSet)
21
+ self.v = {}
22
+ end
23
+ function LinkedMap.prototype.get(self, key)
24
+ return self.v[key]
25
+ end
26
+ function LinkedMap.prototype.getOrPut(self, key, defaultValue)
27
+ local value = self.v[key]
28
+ if value ~= nil then
29
+ return value
30
+ end
31
+ value = defaultValue()
32
+ self.k:add(key)
33
+ self.v[key] = value
34
+ return value
35
+ end
36
+ function LinkedMap.prototype.put(self, key, value)
37
+ self.k:add(key)
38
+ self.v[key] = value
39
+ end
40
+ function LinkedMap.prototype.remove(self, key)
41
+ if self.k:remove(key) then
42
+ self.v[key] = nil
43
+ return true
44
+ end
45
+ return false
46
+ end
47
+ function LinkedMap.prototype.contains(self, key)
48
+ return self.keys:contains(key)
49
+ end
50
+ function LinkedMap.prototype.__pairs(self)
51
+ return linkedMapNext, {n = self.k.f, t = self.k.n, v = self.v}, nil
52
+ end
53
+ __TS__SetDescriptor(
54
+ LinkedMap.prototype,
55
+ "keys",
56
+ {get = function(self)
57
+ return self.k
58
+ end},
59
+ true
60
+ )
61
+ __TS__SetDescriptor(
62
+ LinkedMap.prototype,
63
+ "size",
64
+ {get = function(self)
65
+ return self.keys.size
66
+ end},
67
+ true
68
+ )
69
+ local emptyIteratorState = {t = {}, v = {}}
70
+ local EmptyLinkedMap = __TS__Class()
71
+ EmptyLinkedMap.name = "EmptyLinkedMap"
72
+ __TS__ClassExtends(EmptyLinkedMap, ____exports.LinkedMap)
73
+ function EmptyLinkedMap.prototype.getOrPut(self)
74
+ error(
75
+ __TS__New(UnsupportedOperationException),
76
+ 0
77
+ )
78
+ end
79
+ function EmptyLinkedMap.prototype.put(self)
80
+ error(
81
+ __TS__New(UnsupportedOperationException),
82
+ 0
83
+ )
84
+ end
85
+ function EmptyLinkedMap.prototype.remove(self)
86
+ error(
87
+ __TS__New(UnsupportedOperationException),
88
+ 0
89
+ )
90
+ end
91
+ function EmptyLinkedMap.prototype.__pairs(self)
92
+ return linkedMapNext, emptyIteratorState, nil
93
+ end
94
+ local EMPTY_LINKED_MAP = __TS__New(EmptyLinkedMap)
95
+ ____exports.emptyLinkedMap = function()
96
+ return EMPTY_LINKED_MAP
97
+ end
98
+ ____exports.mutableLinkedMap = function()
99
+ return __TS__New(____exports.LinkedMap)
100
+ end
101
+ return ____exports
@@ -14,7 +14,7 @@ export interface ReadonlyLinkedSet<T extends AnyNotNil> extends LuaPairsKeyItera
14
14
  next(key: T): T | undefined;
15
15
  previous(key: T): T | undefined;
16
16
  contains(key: AnyNotNil): key is T & OneSidedTypeGuard;
17
- size: number;
17
+ readonly size: number;
18
18
  forEach<Args extends any[]>(action: (value: T, ...args: Args) => void, ...args: Args): void;
19
19
  toArray(): T[];
20
20
  sumOf(selector: ((value: T) => number) | KeysOfType<T, number>): number;
@@ -36,9 +36,11 @@ export declare class LinkedSet<T extends AnyNotNil> implements ReadonlyLinkedSet
36
36
  copyOf(): LinkedSet<T>;
37
37
  first(): T | undefined;
38
38
  last(): T | undefined;
39
+ pop(): T | undefined;
39
40
  next(key: T): T | undefined;
40
41
  previous(key: T): T | undefined;
41
42
  add(key: T): boolean;
43
+ protected addBefore(value: T, key: T): boolean;
42
44
  remove(key: T): boolean;
43
45
  contains(key: AnyNotNil): key is T & OneSidedTypeGuard;
44
46
  clear(): void;
@@ -42,6 +42,23 @@ end
42
42
  function LinkedSet.prototype.last(self)
43
43
  return self.l
44
44
  end
45
+ function LinkedSet.prototype.pop(self)
46
+ local f = self.f
47
+ if f == nil then
48
+ return nil
49
+ end
50
+ local n = self.n
51
+ local next = n[f]
52
+ n[f] = nil
53
+ self.f = next
54
+ if next ~= nil then
55
+ self.p[next] = nil
56
+ else
57
+ self.l = nil
58
+ end
59
+ self.s = self.s - 1
60
+ return f
61
+ end
45
62
  function LinkedSet.prototype.next(self, key)
46
63
  return self.n[key]
47
64
  end
@@ -68,6 +85,23 @@ function LinkedSet.prototype.add(self, key)
68
85
  end
69
86
  return true
70
87
  end
88
+ function LinkedSet.prototype.addBefore(self, value, key)
89
+ local n = self.n
90
+ local p = self.p
91
+ local previous = p[value]
92
+ if previous ~= nil then
93
+ n[previous] = key
94
+ p[key] = previous
95
+ elseif value == self.f then
96
+ self.f = key
97
+ else
98
+ return false
99
+ end
100
+ n[key] = value
101
+ p[value] = key
102
+ self.s = self.s + 1
103
+ return true
104
+ end
71
105
  function LinkedSet.prototype.remove(self, key)
72
106
  local n = self.n
73
107
  local next = n[key]
@@ -107,8 +141,9 @@ function LinkedSet.prototype.forEach(self, action, ...)
107
141
  local n = self.n
108
142
  local c = self.f
109
143
  while c ~= nil do
144
+ local next = n[c]
110
145
  action(c, ...)
111
- c = n[c]
146
+ c = next
112
147
  end
113
148
  end
114
149
  function LinkedSet.prototype.toArray(self)
@@ -164,6 +199,7 @@ __TS__SetDescriptor(
164
199
  end},
165
200
  true
166
201
  )
202
+ local emptyIteratorState = {t = {}}
167
203
  local EmptyLinkedSet = __TS__Class()
168
204
  EmptyLinkedSet.name = "EmptyLinkedSet"
169
205
  __TS__ClassExtends(EmptyLinkedSet, ____exports.LinkedSet)
@@ -173,6 +209,9 @@ function EmptyLinkedSet.prototype.add(self)
173
209
  0
174
210
  )
175
211
  end
212
+ function EmptyLinkedSet.prototype.__pairs(self)
213
+ return linkedSetNext, emptyIteratorState, nil
214
+ end
176
215
  local EMPTY_LINKED_SET = __TS__New(EmptyLinkedSet)
177
216
  ____exports.emptyLinkedSet = function()
178
217
  return EMPTY_LINKED_SET
@@ -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,9 +1,28 @@
1
1
  local ____exports = {}
2
+ local ____pairs = _G.pairs
3
+ local tableSort = table.sort
2
4
  ____exports.invertRecord = function(record)
3
5
  local invertRecord = {}
4
- for key, value in pairs(record) do
6
+ for key, value in ____pairs(record) do
5
7
  invertRecord[value] = key
6
8
  end
7
9
  return invertRecord
8
10
  end
11
+ local sortedKeysInternal = {}
12
+ local lastSortedKeysLength = 0
13
+ ---
14
+ -- @internal For use by internal systems only.
15
+ ____exports.sortedKeysUnnested = function(record)
16
+ local length = 0
17
+ for key in ____pairs(record) do
18
+ length = length + 1
19
+ sortedKeysInternal[length] = key
20
+ end
21
+ for i = length + 1, lastSortedKeysLength do
22
+ sortedKeysInternal[i] = nil
23
+ end
24
+ lastSortedKeysLength = length
25
+ tableSort(sortedKeysInternal)
26
+ return sortedKeysInternal
27
+ end
9
28
  return ____exports
@@ -37,4 +37,7 @@ export type Flatten<T extends readonly any[], A extends readonly any[] = []> = T
37
37
  export type Prohibit<T, K extends keyof any> = T & {
38
38
  [P in K]?: never;
39
39
  };
40
+ type TupleSplit<T, N extends number, O extends readonly any[] = readonly []> = O["length"] extends N ? [O, T] : T extends readonly [infer F, ...infer R] ? TupleSplit<readonly [...R], N, readonly [...O, F]> : [O, T];
41
+ export type TakeFirst<T extends readonly any[], N extends number> = TupleSplit<T, N>[0];
42
+ export type SkipFirst<T extends readonly any[], N extends number> = TupleSplit<T, N>[1];
40
43
  export {};