warscript 0.0.1-dev.d1983c6 → 0.0.1-dev.d1b563b
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/core/types/frame.lua +14 -9
- package/core/types/playerCamera.lua +44 -0
- package/core/types/tileCell.d.ts +9 -0
- package/core/types/tileCell.lua +92 -0
- package/core/types/timer.lua +16 -2
- package/decl/native.d.ts +2 -2
- package/engine/behavior.d.ts +3 -0
- package/engine/behavior.lua +53 -0
- package/engine/behaviour/unit.d.ts +6 -2
- package/engine/behaviour/unit.lua +24 -2
- package/engine/buff.d.ts +0 -3
- package/engine/buff.lua +59 -80
- package/engine/internal/ability.d.ts +3 -1
- package/engine/internal/ability.lua +26 -9
- package/engine/internal/item+owner.lua +12 -6
- package/engine/internal/item.d.ts +1 -3
- package/engine/internal/item.lua +22 -23
- package/engine/internal/unit/ability.lua +1 -1
- package/engine/internal/unit+ability.lua +10 -1
- package/engine/internal/unit.d.ts +3 -3
- package/engine/internal/unit.lua +19 -17
- package/engine/object-field/ability.d.ts +3 -3
- package/engine/object-field/ability.lua +7 -6
- package/engine/object-field.d.ts +2 -2
- package/engine/object-field.lua +8 -6
- package/engine/random.d.ts +9 -0
- package/engine/random.lua +13 -0
- package/package.json +2 -2
- package/patch-lualib.lua +1 -1
- package/utility/callback-array.d.ts +13 -0
- package/utility/callback-array.lua +46 -0
- package/utility/lua-maps.d.ts +6 -1
- package/utility/lua-maps.lua +20 -2
package/engine/object-field.d.ts
CHANGED
|
@@ -17,8 +17,8 @@ declare abstract class ObjectFieldBase<ObjectDataEntryType extends ObjectDataEnt
|
|
|
17
17
|
readonly id: ObjectFieldId;
|
|
18
18
|
protected abstract getNativeFieldById(id: number): NativeFieldType;
|
|
19
19
|
protected abstract getObjectDataEntryId(instance: InstanceType): ObjectDataEntryIdType<ObjectDataEntryType>;
|
|
20
|
-
protected abstract hasNativeFieldValue(
|
|
21
|
-
hasValue(
|
|
20
|
+
protected abstract hasNativeFieldValue(objectDataEntryId: ObjectDataEntryIdType<ObjectDataEntryType>): boolean;
|
|
21
|
+
hasValue(objectDataEntryId: ObjectDataEntryIdType<ObjectDataEntryType>): boolean;
|
|
22
22
|
constructor(id: number, isGlobal?: boolean);
|
|
23
23
|
static create<T extends ObjectFieldBase<any, any, any, any>>(this: ObjectFieldConstructor<T>, id?: number, isGlobal?: boolean): T & symbol;
|
|
24
24
|
static of<T extends ObjectFieldBase<any, any, any, any>>(this: ObjectFieldAbstractConstructor<T>, id: number): T | undefined;
|
package/engine/object-field.lua
CHANGED
|
@@ -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,
|
|
61
|
+
function ObjectFieldBase.prototype.hasValue(self, objectDataEntryId)
|
|
62
62
|
local defaultValueByObjectDataEntryId = defaultValueByObjectDataEntryIdByObjectFieldId[self.id]
|
|
63
|
-
return self.isGlobal or defaultValueByObjectDataEntryId ~= nil and defaultValueByObjectDataEntryId[
|
|
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())[
|
|
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(
|
|
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())[
|
|
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(
|
|
495
|
+
if not self:hasNativeFieldValue(objectDataEntryId) then
|
|
494
496
|
return false
|
|
495
497
|
end
|
|
496
498
|
local previousValue = self:getNativeFieldValue(entry, level)
|
package/engine/random.d.ts
CHANGED
|
@@ -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
|
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.
|
|
4
|
+
"version": "0.0.1-dev.d1b563b",
|
|
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.
|
|
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 (
|
|
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)
|
|
@@ -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
|
package/utility/lua-maps.d.ts
CHANGED
|
@@ -5,5 +5,10 @@ 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
7
|
export declare const luaMapInvert: <K extends AnyNotNil, V extends AnyNotNil>(luaMap: LuaMap<K, V>) => LuaMap<V, K>;
|
|
8
|
-
export declare const
|
|
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: LuaMap<readonly K[], V>) => LuaMap<K, V>;
|
|
10
|
+
export declare const mapValues: {
|
|
11
|
+
<K extends AnyNotNil, V1, V2>(luaMap: ReadonlyLuaMap<K, V1>, transform: (value: V1) => V2): LuaMap<K, V2>;
|
|
12
|
+
<K extends AnyNotNil, V1, V2 extends keyof V1>(luaMap: ReadonlyLuaMap<K, V1>, key: V2): LuaMap<K, V1[V2]>;
|
|
13
|
+
};
|
|
9
14
|
export declare const getOrPut: <K extends AnyNotNil, V>(luaMap: LuaMap<K, V>, key: K, defaultValue: () => V) => V;
|
package/utility/lua-maps.lua
CHANGED
|
@@ -27,10 +27,28 @@ ____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
|
|
30
42
|
____exports.mapValues = function(luaMap, transform)
|
|
31
43
|
local result = {}
|
|
32
|
-
|
|
33
|
-
|
|
44
|
+
if type(transform) == "function" then
|
|
45
|
+
for key, value in pairs(luaMap) do
|
|
46
|
+
result[key] = transform(value)
|
|
47
|
+
end
|
|
48
|
+
else
|
|
49
|
+
for key, value in pairs(luaMap) do
|
|
50
|
+
result[key] = value[transform]
|
|
51
|
+
end
|
|
34
52
|
end
|
|
35
53
|
return result
|
|
36
54
|
end
|