warscript 0.0.1-dev.ba37a78 → 0.0.1-dev.bcab4e5
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/attributes.d.ts +17 -0
- package/attributes.lua +23 -0
- package/binaryreader.d.ts +1 -0
- package/binaryreader.lua +3 -0
- package/config.d.ts +5 -0
- package/config.lua +10 -0
- package/core/types/effect.d.ts +14 -6
- package/core/types/effect.lua +131 -35
- package/core/types/frame.d.ts +8 -1
- package/core/types/frame.lua +93 -1
- package/core/types/group.d.ts +0 -1
- package/core/types/handle.d.ts +2 -1
- package/core/types/handle.lua +5 -0
- package/core/types/image.d.ts +0 -1
- package/core/types/missile.d.ts +2 -2
- package/core/types/missile.lua +8 -2
- package/core/types/order.d.ts +1 -0
- package/core/types/order.lua +11 -1
- package/core/types/sound.d.ts +17 -24
- package/core/types/sound.lua +99 -24
- package/core/types/timer.d.ts +6 -7
- package/core/types/timer.lua +18 -21
- package/core/types/unit.lua +8 -0
- package/core/util.d.ts +1 -1
- package/core/util.lua +18 -1
- package/decl/index.d.ts +1 -0
- package/decl/native.d.ts +840 -786
- package/engine/ability.d.ts +1 -1
- package/engine/behavior.d.ts +10 -10
- package/engine/behavior.lua +6 -6
- package/engine/behaviour/ability/always-enabled.d.ts +7 -0
- package/engine/behaviour/ability/always-enabled.lua +31 -0
- package/engine/behaviour/ability/apply-buff.d.ts +8 -5
- package/engine/behaviour/ability/apply-buff.lua +32 -0
- package/engine/behaviour/ability/apply-unit-behavior.d.ts +5 -1
- package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
- package/engine/behaviour/ability/damage.d.ts +39 -11
- package/engine/behaviour/ability/damage.lua +83 -37
- package/engine/behaviour/ability/emulate-impact.d.ts +6 -0
- package/engine/behaviour/ability/emulate-impact.lua +35 -0
- package/engine/behaviour/ability/heal.d.ts +33 -6
- package/engine/behaviour/ability/heal.lua +89 -10
- package/engine/behaviour/ability/instant-impact.d.ts +2 -2
- package/engine/behaviour/ability/instant-impact.lua +4 -15
- package/engine/behaviour/ability/on-command-impact.d.ts +8 -0
- package/engine/behaviour/ability/on-command-impact.lua +25 -0
- package/engine/behaviour/ability/remove-buffs.d.ts +16 -0
- package/engine/behaviour/ability/remove-buffs.lua +28 -0
- package/engine/behaviour/ability/restore-mana.d.ts +15 -0
- package/engine/behaviour/ability/restore-mana.lua +29 -0
- package/engine/behaviour/ability.d.ts +27 -4
- package/engine/behaviour/ability.lua +152 -17
- package/engine/behaviour/unit/stun-immunity.d.ts +0 -1
- package/engine/behaviour/unit.d.ts +16 -2
- package/engine/behaviour/unit.lua +91 -0
- package/engine/buff.d.ts +103 -41
- package/engine/buff.lua +465 -212
- package/engine/game-map.d.ts +7 -0
- package/engine/game-map.lua +32 -0
- package/engine/internal/ability.d.ts +18 -13
- package/engine/internal/ability.lua +87 -76
- package/engine/internal/item/ability.lua +106 -0
- package/engine/internal/item+owner.lua +2 -2
- package/engine/internal/item.d.ts +4 -3
- package/engine/internal/item.lua +56 -25
- package/engine/internal/mechanics/ability-duration.lua +1 -1
- package/engine/internal/misc/ability-disable-counter.d.ts +2 -0
- package/engine/internal/misc/ability-disable-counter.lua +13 -0
- package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
- package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
- package/engine/internal/object-data/auto-attack-speed-increase.d.ts +1 -1
- package/engine/internal/object-data/auto-attack-speed-increase.lua +2 -0
- package/engine/internal/object-data/evasion-probability.d.ts +2 -0
- package/engine/internal/object-data/evasion-probability.lua +16 -0
- package/engine/internal/unit/ability.d.ts +10 -1
- package/engine/internal/unit/ability.lua +36 -14
- package/engine/internal/unit/add-item-to-slot-init.d.ts +2 -0
- package/engine/internal/unit/add-item-to-slot-init.lua +23 -0
- package/engine/internal/unit/add-item-to-slot.d.ts +2 -0
- package/engine/internal/unit/add-item-to-slot.lua +52 -0
- package/engine/internal/unit/bonus.d.ts +11 -8
- package/engine/internal/unit/bonus.lua +23 -1
- package/engine/internal/unit/ignore-events-items.d.ts +2 -0
- package/engine/internal/unit/ignore-events-items.lua +5 -0
- package/engine/internal/unit/item.d.ts +24 -0
- package/engine/internal/unit/item.lua +78 -0
- package/engine/internal/unit/main-selected.d.ts +13 -0
- package/engine/internal/unit/main-selected.lua +51 -0
- package/engine/internal/unit+ability.lua +2 -2
- package/engine/internal/unit+damage.d.ts +2 -11
- package/engine/internal/unit+damage.lua +10 -14
- package/engine/internal/unit+spellSteal.lua +1 -2
- package/engine/internal/unit+transport.lua +4 -10
- package/engine/internal/unit-missile-launch.lua +25 -6
- package/engine/internal/unit.d.ts +83 -19
- package/engine/internal/unit.lua +525 -167
- package/engine/internal/utility.lua +12 -0
- package/engine/lightning.d.ts +12 -5
- package/engine/lightning.lua +48 -14
- package/engine/local-client.d.ts +7 -2
- package/engine/local-client.lua +82 -0
- package/engine/object-data/auxiliary/animation-name.d.ts +1 -0
- package/engine/object-data/auxiliary/animation-name.lua +16 -0
- package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -3
- package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
- package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
- package/engine/object-data/auxiliary/attack-type.lua +42 -0
- package/engine/object-data/auxiliary/combat-classification.d.ts +0 -2
- package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
- package/engine/object-data/auxiliary/movement-type.lua +22 -0
- package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
- package/engine/object-data/auxiliary/sound-eax.lua +2 -0
- package/engine/object-data/auxiliary/sound-preset-name.d.ts +5 -1
- package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
- package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
- package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
- package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
- package/engine/object-data/entry/ability-type/berserk.lua +13 -0
- package/engine/object-data/entry/ability-type/blank-configurable.d.ts +0 -1
- package/engine/object-data/entry/ability-type/blank-configurable.lua +12 -1
- package/engine/object-data/entry/ability-type/blank-passive.d.ts +0 -1
- package/engine/object-data/entry/ability-type/carrion-swarm.d.ts +14 -0
- package/engine/object-data/entry/ability-type/carrion-swarm.lua +65 -0
- package/engine/object-data/entry/ability-type/channel.d.ts +0 -1
- package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
- package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
- package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
- package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
- package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
- package/engine/object-data/entry/ability-type/mine.d.ts +10 -0
- package/engine/object-data/entry/ability-type/mine.lua +39 -0
- package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
- package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
- package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
- package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
- package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
- package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
- package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
- package/engine/object-data/entry/ability-type/shock-wave.d.ts +4 -0
- package/engine/object-data/entry/ability-type/shock-wave.lua +26 -0
- package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
- package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
- package/engine/object-data/entry/ability-type/spirit-touch.d.ts +2 -2
- package/engine/object-data/entry/ability-type/spirit-touch.lua +6 -6
- package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
- package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
- package/engine/object-data/entry/ability-type/web.d.ts +12 -0
- package/engine/object-data/entry/ability-type/web.lua +52 -0
- package/engine/object-data/entry/ability-type.d.ts +19 -18
- package/engine/object-data/entry/ability-type.lua +89 -33
- package/engine/object-data/entry/buff-type/applicable.d.ts +0 -1
- package/engine/object-data/entry/buff-type/applicable.lua +18 -37
- package/engine/object-data/entry/buff-type/blank.d.ts +0 -1
- package/engine/object-data/entry/buff-type.d.ts +6 -13
- package/engine/object-data/entry/buff-type.lua +13 -29
- package/engine/object-data/entry/destructible-type.d.ts +1 -2
- package/engine/object-data/entry/item-type/blank.d.ts +0 -1
- package/engine/object-data/entry/item-type.d.ts +15 -2
- package/engine/object-data/entry/item-type.lua +93 -2
- package/engine/object-data/entry/lightning-type.d.ts +1 -2
- package/engine/object-data/entry/sound-preset.d.ts +33 -0
- package/engine/object-data/entry/sound-preset.lua +140 -0
- package/engine/object-data/entry/unit-type.d.ts +50 -3
- package/engine/object-data/entry/unit-type.lua +452 -61
- package/engine/object-data/entry/upgrade/blank.d.ts +0 -1
- package/engine/object-data/entry/upgrade.d.ts +1 -2
- package/engine/object-data/entry/upgrade.lua +4 -4
- package/engine/object-data/entry.d.ts +18 -17
- package/engine/object-data/entry.lua +60 -32
- package/engine/object-data/utility/object-data-entry-id-generator.lua +7 -0
- package/engine/object-field/ability.d.ts +26 -3
- package/engine/object-field/ability.lua +54 -1
- package/engine/object-field/unit.d.ts +46 -3
- package/engine/object-field/unit.lua +173 -7
- package/engine/object-field.d.ts +11 -4
- package/engine/object-field.lua +162 -76
- package/engine/random.d.ts +1 -0
- package/engine/random.lua +9 -0
- package/engine/standard/entries/buff-type.d.ts +3 -0
- package/engine/standard/entries/buff-type.lua +3 -0
- package/engine/standard/entries/sound-preset.d.ts +10 -0
- package/engine/standard/entries/sound-preset.lua +10 -0
- package/engine/standard/entries/unit-type.d.ts +42 -1
- package/engine/standard/entries/unit-type.lua +42 -1
- package/engine/standard/fields/ability.d.ts +3 -1
- package/engine/standard/fields/ability.lua +3 -1
- package/engine/unit.d.ts +3 -0
- package/engine/unit.lua +12 -2
- package/event.d.ts +2 -3
- package/event.lua +9 -5
- package/index.d.ts +1 -0
- package/index.lua +1 -0
- package/lualib_bundle.lua +146 -42
- package/math/vec2.d.ts +2 -9
- package/math.d.ts +0 -2
- package/net/socket.d.ts +7 -1
- package/net/socket.lua +45 -4
- package/network.d.ts +1 -0
- package/network.lua +3 -2
- package/objutil/ability.d.ts +0 -1
- package/objutil/buff.d.ts +0 -1
- package/objutil/buff.lua +2 -3
- package/objutil/object.d.ts +0 -1
- package/objutil/unit.d.ts +0 -1
- package/objutil/unit.lua +8 -0
- package/package.json +13 -14
- package/patch-lua.d.ts +0 -0
- package/patch-lua.lua +10 -0
- package/property.d.ts +55 -0
- package/property.lua +374 -0
- package/string.d.ts +30 -0
- package/string.lua +14 -0
- package/util/stream.d.ts +0 -1
- package/utility/arrays.d.ts +12 -5
- package/utility/arrays.lua +37 -3
- package/utility/bit-set.d.ts +0 -2
- package/utility/functions.d.ts +1 -0
- package/utility/functions.lua +1 -0
- package/utility/lazy.d.ts +2 -0
- package/utility/lazy.lua +14 -0
- package/utility/linked-set.d.ts +12 -3
- package/utility/linked-set.lua +8 -2
- package/utility/lua-maps.d.ts +4 -2
- package/utility/lua-maps.lua +16 -0
- package/utility/lua-sets.d.ts +2 -2
- package/utility/lua-sets.lua +3 -0
- package/utility/reflection.lua +11 -7
- package/utility/types.d.ts +3 -2
- package/core/mapbounds.d.ts +0 -8
- package/core/mapbounds.lua +0 -12
package/string.d.ts
CHANGED
|
@@ -59,6 +59,22 @@ declare global {
|
|
|
59
59
|
function toNumber(string: string): number;
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
+
declare global {
|
|
63
|
+
namespace string {
|
|
64
|
+
/**
|
|
65
|
+
* Returns the index within the string of the first occurrence of the specified substring, starting from the specified `startIndex`,
|
|
66
|
+
* or -1 if the string does not contain such substring.
|
|
67
|
+
*/
|
|
68
|
+
function indexOf(string: string, substring: string, startIndex?: number): number;
|
|
69
|
+
}
|
|
70
|
+
interface String {
|
|
71
|
+
/**
|
|
72
|
+
* Returns the index within this string of the first occurrence of the specified substring, starting from the specified `startIndex`,
|
|
73
|
+
* or -1 if the string does not contain such substring.
|
|
74
|
+
*/
|
|
75
|
+
indexOf(substring: string, startIndex?: number): number;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
62
78
|
declare global {
|
|
63
79
|
interface String {
|
|
64
80
|
/**
|
|
@@ -103,4 +119,18 @@ declare global {
|
|
|
103
119
|
function isNotBlank(string: string): boolean;
|
|
104
120
|
}
|
|
105
121
|
}
|
|
122
|
+
declare global {
|
|
123
|
+
namespace string {
|
|
124
|
+
/**
|
|
125
|
+
* Returns the number of characters matching the given predicate.
|
|
126
|
+
*/
|
|
127
|
+
function count(string: string, predicate: (char: string) => boolean): number;
|
|
128
|
+
}
|
|
129
|
+
interface String {
|
|
130
|
+
/**
|
|
131
|
+
* Returns the number of characters matching the given predicate.
|
|
132
|
+
*/
|
|
133
|
+
count(predicate: (char: string) => boolean): number;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
106
136
|
export {};
|
package/string.lua
CHANGED
|
@@ -2,6 +2,7 @@ local ____exports = {}
|
|
|
2
2
|
local ____error = _G.error
|
|
3
3
|
local tonumber = _G.tonumber
|
|
4
4
|
local match = string.match
|
|
5
|
+
local find = string.find
|
|
5
6
|
local sub = string.sub
|
|
6
7
|
_G.string.removePrefix = function(____string, prefix)
|
|
7
8
|
local prefixLength = #prefix
|
|
@@ -17,6 +18,10 @@ end
|
|
|
17
18
|
_G.string.toNumber = function(____string)
|
|
18
19
|
return tonumber(____string) or ____error(("'" .. ____string) .. "' is not a valid representation of a number.")
|
|
19
20
|
end
|
|
21
|
+
_G.string.indexOf = function(____string, substring, startIndex)
|
|
22
|
+
local index = find(____string, substring, (startIndex or 0) + 1, true)
|
|
23
|
+
return (index or 0) - 1
|
|
24
|
+
end
|
|
20
25
|
_G.string.indexOfLast = function(____string, predicate)
|
|
21
26
|
for i = #____string, 1, -1 do
|
|
22
27
|
if predicate(sub(____string, i, i)) then
|
|
@@ -31,4 +36,13 @@ end
|
|
|
31
36
|
_G.string.isNotBlank = function(____string)
|
|
32
37
|
return (match(____string, "^%s*$")) == nil
|
|
33
38
|
end
|
|
39
|
+
_G.string.count = function(____string, predicate)
|
|
40
|
+
local result = 0
|
|
41
|
+
for i = 1, #____string do
|
|
42
|
+
if predicate(sub(____string, i, i)) then
|
|
43
|
+
result = result + 1
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
return result
|
|
47
|
+
end
|
|
34
48
|
return ____exports
|
package/util/stream.d.ts
CHANGED
package/utility/arrays.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
/// <reference types="@typescript-to-lua/language-extensions" />
|
|
2
1
|
/** @noSelfInFile */
|
|
3
2
|
import { TupleOf } from "./types";
|
|
4
3
|
export declare const emptyArray: <T>() => readonly T[];
|
|
5
4
|
export declare const joinToString: <T>(array: readonly T[], separator: string, transform?: (element: T) => string) => string;
|
|
6
|
-
export declare const arrayOfNotNull: <T>(...elements: readonly (T |
|
|
5
|
+
export declare const arrayOfNotNull: <T>(...elements: readonly (T | undefined | null)[]) => T[];
|
|
7
6
|
export declare const array: <T, N extends number>(length: N, initialize: (index: number) => T) => TupleOf<T, N>;
|
|
8
7
|
export declare const toLuaSet: <T extends AnyNotNil>(array: readonly T[]) => LuaSet<T>;
|
|
9
|
-
export declare const forEach: <T, Args extends any[]>(array: readonly T[], consumerOrKey:
|
|
8
|
+
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;
|
|
10
9
|
export declare const all: {
|
|
11
10
|
<T>(array: readonly T[], transform: (value: T) => boolean): boolean;
|
|
12
11
|
<T>(array: readonly T[], key: KeysOfType<T, boolean>): boolean;
|
|
@@ -23,6 +22,7 @@ export declare const mapToLuaSet: {
|
|
|
23
22
|
<T, R extends AnyNotNil>(array: readonly T[], transform: (value: T) => R): LuaSet<R>;
|
|
24
23
|
<T, K extends KeysOfType<T, AnyNotNil>>(array: readonly T[], key: K): LuaSet<T[K] extends AnyNotNil ? T[K] : never>;
|
|
25
24
|
};
|
|
25
|
+
export declare const flatten: <T>(array: readonly (readonly T[])[]) => T[];
|
|
26
26
|
export declare const flatMap: {
|
|
27
27
|
<T, R>(array: readonly T[], transform: (value: T) => readonly R[]): R[];
|
|
28
28
|
<T, K extends KeysOfType<T, readonly any[]>>(array: readonly T[], key: K): (T[K] extends readonly (infer R)[] ? R : never)[];
|
|
@@ -33,7 +33,10 @@ export declare const flatMapToLuaSet: {
|
|
|
33
33
|
};
|
|
34
34
|
export declare const mapIndexed: <T, R>(array: readonly T[], transform: (index: number, value: T) => R) => R[];
|
|
35
35
|
export declare const associate: <T, K extends AnyNotNil, V>(array: readonly T[], keySelector: (value: T) => K, valueSelector: (value: T) => V) => LuaMap<K, V>;
|
|
36
|
-
export declare const associateBy:
|
|
36
|
+
export declare const associateBy: {
|
|
37
|
+
<K extends AnyNotNil, V>(array: readonly V[], keySelector: (value: V) => K): LuaMap<K, V>;
|
|
38
|
+
<K extends KeysOfType<V, AnyNotNil>, V>(array: readonly V[], keySelector: K): LuaMap<V[K] extends AnyNotNil ? V[K] : never, V>;
|
|
39
|
+
};
|
|
37
40
|
export declare const associateByIndexed: <K extends AnyNotNil, V>(array: readonly V[], keySelector: (index: number, value: V) => K) => LuaMap<K, V>;
|
|
38
41
|
export declare const associateWith: <K extends AnyNotNil, V>(array: readonly K[], valueSelector: (value: K) => V) => LuaMap<K, V>;
|
|
39
42
|
export declare const associateWithIndexed: <K extends AnyNotNil, V>(array: readonly K[], valueSelector: (index: number, value: K) => V) => LuaMap<K, V>;
|
|
@@ -42,10 +45,14 @@ export declare const average: (array: readonly number[]) => number;
|
|
|
42
45
|
export declare const sum: (array: readonly number[]) => number;
|
|
43
46
|
export declare const product: (array: readonly number[]) => number;
|
|
44
47
|
export declare const max: (array: readonly number[]) => number;
|
|
48
|
+
export declare const maxBy: {
|
|
49
|
+
<T, Args extends any[]>(array: readonly T[], selector: (value: T, ...args: Args) => number, ...args: Args): T | undefined;
|
|
50
|
+
<T, K extends KeysOfType<T, number>>(array: readonly T[], key: K): T | undefined;
|
|
51
|
+
};
|
|
45
52
|
export declare const intersperse: <T>(array: readonly T[], delimiter: T) => T[];
|
|
46
53
|
export declare const zip: <T, R, V>(array: readonly T[], otherArray: readonly R[], transform: (value: T, otherValue: R) => V) => V[];
|
|
47
54
|
export declare const chunked: <T>(array: readonly T[], size: number) => T[][];
|
|
48
|
-
export declare const sortBy: <T, R>(array: T[], selector:
|
|
55
|
+
export declare const sortBy: <T, R>(array: T[], selector: ((value: T) => R) | KeysOfType<T, R>) => void;
|
|
49
56
|
export declare const sortedBy: {
|
|
50
57
|
<T, R>(array: readonly T[], selector: (value: T) => R): T[];
|
|
51
58
|
<T, K extends keyof T>(array: readonly T[], key: K): T[];
|
package/utility/arrays.lua
CHANGED
|
@@ -3,6 +3,8 @@ local __TS__New = ____lualib.__TS__New
|
|
|
3
3
|
local ____exports = {}
|
|
4
4
|
local ____exception = require("exception")
|
|
5
5
|
local IllegalArgumentException = ____exception.IllegalArgumentException
|
|
6
|
+
local ____functions = require("utility.functions")
|
|
7
|
+
local identity = ____functions.identity
|
|
6
8
|
local mathMax = math.max
|
|
7
9
|
local mathMin = math.min
|
|
8
10
|
local select = _G.select
|
|
@@ -120,6 +122,7 @@ ____exports.mapToLuaSet = function(array, transform)
|
|
|
120
122
|
end
|
|
121
123
|
return result
|
|
122
124
|
end
|
|
125
|
+
____exports.flatten = function(array) return ____exports.flatMap(array, identity) end
|
|
123
126
|
____exports.flatMap = function(array, transform)
|
|
124
127
|
local result = {}
|
|
125
128
|
local k = 1
|
|
@@ -178,9 +181,16 @@ ____exports.associate = function(array, keySelector, valueSelector)
|
|
|
178
181
|
end
|
|
179
182
|
____exports.associateBy = function(array, keySelector)
|
|
180
183
|
local result = {}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
+
if type(keySelector) == "function" then
|
|
185
|
+
for i = 1, #array do
|
|
186
|
+
local value = array[i]
|
|
187
|
+
result[keySelector(value)] = value
|
|
188
|
+
end
|
|
189
|
+
else
|
|
190
|
+
for i = 1, #array do
|
|
191
|
+
local value = array[i]
|
|
192
|
+
result[value[keySelector]] = value
|
|
193
|
+
end
|
|
184
194
|
end
|
|
185
195
|
return result
|
|
186
196
|
end
|
|
@@ -251,6 +261,30 @@ ____exports.max = function(array)
|
|
|
251
261
|
end
|
|
252
262
|
return mathMax(table.unpack(array))
|
|
253
263
|
end
|
|
264
|
+
____exports.maxBy = function(array, selector, ...)
|
|
265
|
+
local result = nil
|
|
266
|
+
local maxValue = -math.huge
|
|
267
|
+
if type(selector) == "function" then
|
|
268
|
+
for i = 1, #array do
|
|
269
|
+
local element = array[i]
|
|
270
|
+
local value = selector(element, ...)
|
|
271
|
+
if value > maxValue then
|
|
272
|
+
result = element
|
|
273
|
+
maxValue = value
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
else
|
|
277
|
+
for i = 1, #array do
|
|
278
|
+
local element = array[i]
|
|
279
|
+
local value = element[selector]
|
|
280
|
+
if value > maxValue then
|
|
281
|
+
result = element
|
|
282
|
+
maxValue = value
|
|
283
|
+
end
|
|
284
|
+
end
|
|
285
|
+
end
|
|
286
|
+
return result
|
|
287
|
+
end
|
|
254
288
|
____exports.intersperse = function(array, delimiter)
|
|
255
289
|
local result = {}
|
|
256
290
|
local length = #array
|
package/utility/bit-set.d.ts
CHANGED
package/utility/functions.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ export declare const apply: {
|
|
|
3
3
|
<T, ConsumerParameters extends any[]>(object: T, consumer: (value: T, ...parameters: ConsumerParameters) => void, ...parameters: ConsumerParameters): T;
|
|
4
4
|
<T, ConsumerParameters extends any[], K extends KeysOfType<T, (...parameters: ConsumerParameters) => void>>(object: T, key: K, ...parameters: ConsumerParameters): T;
|
|
5
5
|
};
|
|
6
|
+
export declare const identity: <T>(value: T) => T;
|
package/utility/functions.lua
CHANGED
package/utility/lazy.lua
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
local ____exports = {}
|
|
2
|
+
local rawset = _G.rawset
|
|
3
|
+
local setmetatable = _G.setmetatable
|
|
4
|
+
____exports.lazyRecord = function(initializer)
|
|
5
|
+
return setmetatable(
|
|
6
|
+
{},
|
|
7
|
+
{__index = function(self, key)
|
|
8
|
+
local value = initializer(key)
|
|
9
|
+
rawset(self, key, value)
|
|
10
|
+
return value
|
|
11
|
+
end}
|
|
12
|
+
)
|
|
13
|
+
end
|
|
14
|
+
return ____exports
|
package/utility/linked-set.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/// <reference types="@typescript-to-lua/language-extensions" />
|
|
2
1
|
/** @noSelfInFile */
|
|
2
|
+
import { NonEmptyArray, ReadonlyNonEmptyArray } from "./types";
|
|
3
3
|
type IteratorState<T extends AnyNotNil> = {
|
|
4
4
|
t: LuaMap<T, T>;
|
|
5
5
|
n?: T;
|
|
@@ -19,6 +19,11 @@ export interface ReadonlyLinkedSet<T extends AnyNotNil> extends LuaPairsKeyItera
|
|
|
19
19
|
toArray(): T[];
|
|
20
20
|
sumOf(selector: ((value: T) => number) | KeysOfType<T, number>): number;
|
|
21
21
|
}
|
|
22
|
+
export interface ReadonlyNonEmptyLinkedSet<T extends AnyNotNil> extends ReadonlyLinkedSet<T> {
|
|
23
|
+
first(): T;
|
|
24
|
+
last(): T;
|
|
25
|
+
toArray(): NonEmptyArray<T>;
|
|
26
|
+
}
|
|
22
27
|
export interface LinkedSet<T extends AnyNotNil> extends LuaPairsKeyIterable<T> {
|
|
23
28
|
readonly __linkedSet: unique symbol;
|
|
24
29
|
}
|
|
@@ -45,6 +50,10 @@ export declare class LinkedSet<T extends AnyNotNil> implements ReadonlyLinkedSet
|
|
|
45
50
|
protected __pairs(this: LinkedSet<T>): LuaIterator<T | undefined, IteratorState<T>>;
|
|
46
51
|
}
|
|
47
52
|
export declare const emptyLinkedSet: <T extends AnyNotNil>() => ReadonlyLinkedSet<T>;
|
|
48
|
-
export declare const
|
|
49
|
-
export declare const
|
|
53
|
+
export declare const mutableLinkedSet: <T extends AnyNotNil>() => LinkedSet<T>;
|
|
54
|
+
export declare const mutableLinkedSetOf: <T extends AnyNotNil>(...elements: ReadonlyArray<T>) => LinkedSet<T>;
|
|
55
|
+
export declare const mutableLinkedSetOfNotNull: <T extends AnyNotNil>(...elements: readonly (T | undefined | null)[]) => LinkedSet<T>;
|
|
56
|
+
export declare const linkedSetOf: <T extends AnyNotNil>(...elements: ReadonlyArray<T>) => ReadonlyLinkedSet<T>;
|
|
57
|
+
export declare const linkedSetOfNotNull: <T extends AnyNotNil>(...elements: ReadonlyArray<T>) => ReadonlyLinkedSet<T>;
|
|
58
|
+
export declare const nonEmptyLinkedSetOf: <T extends AnyNotNil>(...elements: ReadonlyNonEmptyArray<T>) => ReadonlyNonEmptyLinkedSet<T>;
|
|
50
59
|
export {};
|
package/utility/linked-set.lua
CHANGED
|
@@ -177,14 +177,17 @@ local EMPTY_LINKED_SET = __TS__New(EmptyLinkedSet)
|
|
|
177
177
|
____exports.emptyLinkedSet = function()
|
|
178
178
|
return EMPTY_LINKED_SET
|
|
179
179
|
end
|
|
180
|
-
____exports.
|
|
180
|
+
____exports.mutableLinkedSet = function()
|
|
181
|
+
return __TS__New(____exports.LinkedSet)
|
|
182
|
+
end
|
|
183
|
+
____exports.mutableLinkedSetOf = function(...)
|
|
181
184
|
local linkedSet = __TS__New(____exports.LinkedSet)
|
|
182
185
|
for i = 1, select("#", ...) do
|
|
183
186
|
linkedSet:add((select(i, ...)))
|
|
184
187
|
end
|
|
185
188
|
return linkedSet
|
|
186
189
|
end
|
|
187
|
-
____exports.
|
|
190
|
+
____exports.mutableLinkedSetOfNotNull = function(...)
|
|
188
191
|
local linkedSet = __TS__New(____exports.LinkedSet)
|
|
189
192
|
for i = 1, select("#", ...) do
|
|
190
193
|
local element = (select(i, ...))
|
|
@@ -194,4 +197,7 @@ ____exports.linkedSetOfNotNull = function(...)
|
|
|
194
197
|
end
|
|
195
198
|
return linkedSet
|
|
196
199
|
end
|
|
200
|
+
____exports.linkedSetOf = function(...) return ____exports.mutableLinkedSetOf(...) end
|
|
201
|
+
____exports.linkedSetOfNotNull = function(...) return ____exports.mutableLinkedSetOfNotNull(...) end
|
|
202
|
+
____exports.nonEmptyLinkedSetOf = function(...) return ____exports.linkedSetOf(...) end
|
|
197
203
|
return ____exports
|
package/utility/lua-maps.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
/// <reference types="@typescript-to-lua/language-extensions" />
|
|
2
1
|
/** @noSelfInFile */
|
|
3
2
|
import { Flatten, TupleOf } from "./types";
|
|
4
|
-
export declare const
|
|
3
|
+
export declare const mutableLuaMap: <K extends AnyNotNil, V>() => LuaMap<K, V>;
|
|
4
|
+
export declare const mutableWeakLuaMap: <K extends AnyNotNil, V>() => LuaMap<K, V>;
|
|
5
|
+
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>;
|
|
5
6
|
export declare const luaMapInvert: <K extends AnyNotNil, V extends AnyNotNil>(luaMap: LuaMap<K, V>) => LuaMap<V, K>;
|
|
6
7
|
export declare const mapValues: <K extends AnyNotNil, V1, V2>(luaMap: LuaMap<K, V1>, transform: (value: V1) => V2) => LuaMap<K, V2>;
|
|
8
|
+
export declare const getOrPut: <K extends AnyNotNil, V>(luaMap: LuaMap<K, V>, key: K, defaultValue: () => V) => V;
|
package/utility/lua-maps.lua
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
local ____exports = {}
|
|
2
2
|
local select = _G.select
|
|
3
|
+
local setmetatable = _G.setmetatable
|
|
4
|
+
local weakKeysMetatable = {__mode = "k"}
|
|
5
|
+
____exports.mutableLuaMap = function()
|
|
6
|
+
return {}
|
|
7
|
+
end
|
|
8
|
+
____exports.mutableWeakLuaMap = function()
|
|
9
|
+
return setmetatable({}, weakKeysMetatable)
|
|
10
|
+
end
|
|
3
11
|
____exports.luaMapOf = function(...)
|
|
4
12
|
local luaMap = {}
|
|
5
13
|
for i = 1, select("#", ...), 2 do
|
|
@@ -22,4 +30,12 @@ ____exports.mapValues = function(luaMap, transform)
|
|
|
22
30
|
end
|
|
23
31
|
return result
|
|
24
32
|
end
|
|
33
|
+
____exports.getOrPut = function(luaMap, key, defaultValue)
|
|
34
|
+
local value = luaMap[key]
|
|
35
|
+
if value == nil then
|
|
36
|
+
value = defaultValue()
|
|
37
|
+
luaMap[key] = value
|
|
38
|
+
end
|
|
39
|
+
return value
|
|
40
|
+
end
|
|
25
41
|
return ____exports
|
package/utility/lua-sets.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/// <reference types="@typescript-to-lua/language-extensions" />
|
|
2
1
|
/** @noSelfInFile */
|
|
2
|
+
export declare const mutableLuaSet: <T extends AnyNotNil>() => LuaSet<T>;
|
|
3
3
|
export declare const luaSetOf: <T extends AnyNotNil>(...elements: readonly T[]) => LuaSet<T>;
|
|
4
|
-
export declare const luaSetOfNotNull: <T extends AnyNotNil>(...elements: readonly (T |
|
|
4
|
+
export declare const luaSetOfNotNull: <T extends AnyNotNil>(...elements: readonly (T | undefined | null)[]) => LuaSet<T>;
|
|
5
5
|
export declare const luaSetIntersection: <T extends AnyNotNil>(firstLuaSet: ReadonlyLuaSet<T>, secondLuaSet: ReadonlyLuaSet<T>) => LuaSet<T>;
|
|
6
6
|
export declare const luaSetContainsAnyOf: <T extends AnyNotNil>(luaSet: ReadonlyLuaSet<T>, ...elements: readonly T[]) => boolean;
|
package/utility/lua-sets.lua
CHANGED
package/utility/reflection.lua
CHANGED
|
@@ -5,21 +5,25 @@ local checkNotNull = ____preconditions.checkNotNull
|
|
|
5
5
|
-- @internal For use by internal systems only.
|
|
6
6
|
____exports.implementReadonlyNumberIndexSupplier = function(clazz, supplier)
|
|
7
7
|
local metatable = checkNotNull(getmetatable(clazz))
|
|
8
|
-
local originalIndex = checkNotNull(metatable
|
|
8
|
+
local originalIndex = checkNotNull(rawget(metatable, "__index"))
|
|
9
9
|
local memoizedValueByKey = {}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
rawset(
|
|
11
|
+
metatable,
|
|
12
|
+
"__index",
|
|
13
|
+
function(self, key)
|
|
13
14
|
if type(key) == "number" then
|
|
14
|
-
local value =
|
|
15
|
-
|
|
15
|
+
local value = memoizedValueByKey[key]
|
|
16
|
+
if value == nil then
|
|
17
|
+
value = supplier(key)
|
|
18
|
+
memoizedValueByKey[key] = value
|
|
19
|
+
end
|
|
16
20
|
return value
|
|
17
21
|
end
|
|
18
22
|
if type(originalIndex) == "function" then
|
|
19
23
|
return originalIndex(self, key)
|
|
20
24
|
end
|
|
21
25
|
return originalIndex[key]
|
|
22
|
-
end
|
|
26
|
+
end
|
|
23
27
|
)
|
|
24
28
|
end
|
|
25
29
|
____exports.getClass = function(object)
|
package/utility/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
export type AnyNonNullable = {};
|
|
3
3
|
export type IsExactlyAny<T> = boolean extends (T extends never ? true : false) ? true : false;
|
|
4
4
|
export type NonEmptyArray<T> = [T, ...T[]];
|
|
5
|
+
export type ReadonlyNonEmptyArray<T> = readonly [T, ...T[]];
|
|
5
6
|
export type InvertRecordType<T extends Record<PropertyKey, PropertyKey | null | undefined>> = {
|
|
6
7
|
[P in keyof T as NonNullable<T[P]>]: P;
|
|
7
8
|
};
|
|
@@ -12,14 +13,14 @@ export type ValueOf<T> = T[keyof T];
|
|
|
12
13
|
export type EntryOf<T> = ValueOf<{
|
|
13
14
|
[K in keyof T]: [K, T[K]];
|
|
14
15
|
}>;
|
|
15
|
-
export type MutableKeys<T extends object> = {
|
|
16
|
+
export type MutableKeys<T extends object> = keyof T & {
|
|
16
17
|
[P in keyof T]-?: IfEquals<{
|
|
17
18
|
[Q in P]: T[P];
|
|
18
19
|
}, {
|
|
19
20
|
-readonly [Q in P]: T[P];
|
|
20
21
|
}, P>;
|
|
21
22
|
}[keyof T];
|
|
22
|
-
export type ReadonlyKeys<T extends object> = {
|
|
23
|
+
export type ReadonlyKeys<T extends object> = keyof T & {
|
|
23
24
|
[P in keyof T]-?: IfEquals<{
|
|
24
25
|
[Q in P]: T[P];
|
|
25
26
|
}, {
|
package/core/mapbounds.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/** @noSelfInFile */
|
|
2
|
-
import { Rect } from "./types/rect";
|
|
3
|
-
import { Region } from "./types/region";
|
|
4
|
-
export declare const boundRect: Rect;
|
|
5
|
-
export declare const boundRegion: Region;
|
|
6
|
-
export declare const boundMin: Readonly<Vec2>;
|
|
7
|
-
export declare const boundMax: Readonly<Vec2>;
|
|
8
|
-
export declare const boundCenter: Readonly<Vec2>;
|
package/core/mapbounds.lua
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
local ____exports = {}
|
|
2
|
-
local ____rect = require("core.types.rect")
|
|
3
|
-
local Rect = ____rect.Rect
|
|
4
|
-
local ____region = require("core.types.region")
|
|
5
|
-
local Region = ____region.Region
|
|
6
|
-
____exports.boundRect = Rect:of(GetWorldBounds())
|
|
7
|
-
____exports.boundRegion = Region:create()
|
|
8
|
-
____exports.boundRegion:addRect(____exports.boundRect)
|
|
9
|
-
____exports.boundMin = vec2(____exports.boundRect.minX, ____exports.boundRect.minY)
|
|
10
|
-
____exports.boundMax = vec2(____exports.boundRect.maxX, ____exports.boundRect.maxY)
|
|
11
|
-
____exports.boundCenter = (____exports.boundMin + ____exports.boundMax) * 0.5
|
|
12
|
-
return ____exports
|