warscript 0.0.1-dev.a319619 → 0.0.1-dev.a3deff8

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 (58) hide show
  1. package/attributes.d.ts +1 -0
  2. package/attributes.lua +9 -0
  3. package/core/types/frame.lua +14 -9
  4. package/core/types/player.d.ts +15 -0
  5. package/core/types/player.lua +53 -13
  6. package/core/types/playerCamera.lua +44 -0
  7. package/core/types/tileCell.d.ts +9 -0
  8. package/core/types/tileCell.lua +92 -0
  9. package/core/types/timer.d.ts +3 -2
  10. package/core/types/timer.lua +22 -2
  11. package/decl/native.d.ts +2 -2
  12. package/engine/behavior.d.ts +3 -0
  13. package/engine/behavior.lua +53 -0
  14. package/engine/behaviour/ability/remove-buffs.d.ts +9 -0
  15. package/engine/behaviour/ability/remove-buffs.lua +21 -0
  16. package/engine/behaviour/unit/stun-immunity.d.ts +2 -0
  17. package/engine/behaviour/unit/stun-immunity.lua +11 -2
  18. package/engine/behaviour/unit.d.ts +8 -2
  19. package/engine/behaviour/unit.lua +29 -2
  20. package/engine/buff.d.ts +9 -4
  21. package/engine/buff.lua +112 -82
  22. package/engine/internal/ability.d.ts +3 -1
  23. package/engine/internal/ability.lua +26 -9
  24. package/engine/internal/item+owner.lua +12 -6
  25. package/engine/internal/item.d.ts +13 -15
  26. package/engine/internal/item.lua +63 -49
  27. package/engine/internal/unit/ability.d.ts +14 -14
  28. package/engine/internal/unit/ability.lua +72 -45
  29. package/engine/internal/unit/main-selected.lua +12 -27
  30. package/engine/internal/unit+ability.lua +9 -8
  31. package/engine/internal/unit-missile-launch.lua +44 -20
  32. package/engine/internal/unit.d.ts +16 -9
  33. package/engine/internal/unit.lua +102 -54
  34. package/engine/local-client.d.ts +2 -0
  35. package/engine/local-client.lua +30 -0
  36. package/engine/object-data/entry/ability-type.lua +4 -1
  37. package/engine/object-field/ability.d.ts +3 -3
  38. package/engine/object-field/ability.lua +7 -6
  39. package/engine/object-field.d.ts +9 -3
  40. package/engine/object-field.lua +184 -93
  41. package/engine/random.d.ts +9 -0
  42. package/engine/random.lua +13 -0
  43. package/engine/synchronization.d.ts +11 -0
  44. package/engine/synchronization.lua +77 -0
  45. package/engine/text-tag.lua +3 -2
  46. package/net/socket.lua +1 -1
  47. package/objutil/buff.lua +1 -1
  48. package/package.json +2 -2
  49. package/patch-lualib.lua +1 -1
  50. package/utility/arrays.d.ts +1 -0
  51. package/utility/arrays.lua +8 -0
  52. package/utility/callback-array.d.ts +17 -0
  53. package/utility/callback-array.lua +61 -0
  54. package/utility/linked-set.d.ts +1 -0
  55. package/utility/linked-set.lua +19 -1
  56. package/utility/lua-maps.d.ts +11 -2
  57. package/utility/lua-maps.lua +33 -2
  58. package/utility/types.d.ts +3 -0
@@ -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
@@ -36,6 +36,7 @@ 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;
@@ -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
@@ -107,8 +124,9 @@ function LinkedSet.prototype.forEach(self, action, ...)
107
124
  local n = self.n
108
125
  local c = self.f
109
126
  while c ~= nil do
127
+ local next = n[c]
110
128
  action(c, ...)
111
- c = n[c]
129
+ c = next
112
130
  end
113
131
  end
114
132
  function LinkedSet.prototype.toArray(self)
@@ -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
@@ -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 {};