typed-factorio 1.3.2 → 1.5.1
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/Changelog.md +45 -9
- package/README.md +14 -19
- package/custom-index-template.d.ts +1 -0
- package/generated/builtin-types.d.ts +24 -19
- package/generated/classes.d.ts +6399 -8786
- package/generated/concepts.d.ts +3263 -1961
- package/generated/defines.d.ts +126 -193
- package/generated/events.d.ts +250 -446
- package/generated/global-functions.d.ts +33 -0
- package/generated/global-objects.d.ts +7 -14
- package/package.json +22 -21
- package/runtime/index.d.ts +1 -0
- package/runtime/librariesAndFunctions.d.ts +0 -32
package/Changelog.md
CHANGED
@@ -1,6 +1,42 @@
|
|
1
|
+
# v1.5.1
|
2
|
+
|
3
|
+
- Added old `Read` types as deprecated type aliases of new types; to help with migration.
|
4
|
+
|
5
|
+
# v1.5.0
|
6
|
+
|
7
|
+
### BREAKING
|
8
|
+
|
9
|
+
- Read-only forms of concepts (the most common form used) is now specified with just the name; forms with a `Read` or `Table` suffix have been removed.
|
10
|
+
- Write forms are now specified as either a union of table and array forms, or with a `Write` suffix for concepts.
|
11
|
+
- For table-or-array concepts: `MapPositionRead` -> `MapPosition`, `MapPosition` -> `MapPosition | PositionArray`
|
12
|
+
- For table concepts: `ScriptAreaRead` -> `ScriptArea`, `ScriptArea` -> `ScriptAreaWrite`
|
13
|
+
- The minimum TSTL version has been increased to v1.6.1 (A bug with documentation comments was fixed in that version).
|
14
|
+
|
15
|
+
### Other
|
16
|
+
|
17
|
+
- Updated to factorio version 1.1.63.
|
18
|
+
- Upgraded to factorio api docs json version 3.
|
19
|
+
- The new type `nil` is used instead of `undefined` (they are equivalent).
|
20
|
+
- More complete type for `BlueprintEntity`.
|
21
|
+
- Fixed missing read-write forms for more concepts.
|
22
|
+
- Improved documentation comments (enabled by json docs version 3).
|
23
|
+
- Improved documentation comments for variant parameter groups.
|
24
|
+
|
25
|
+
# v1.4.0
|
26
|
+
|
27
|
+
- Improve doc comments for enum concepts
|
28
|
+
- Improve doc comment formatting
|
29
|
+
- Improve types of concepts with literal union types
|
30
|
+
- Add read-specific types to AutoplaceControl and ComparatorString
|
31
|
+
|
32
|
+
# v1.3.2
|
33
|
+
|
34
|
+
- Move "notes" comment into the main body of doc comment, instead of in @remarks. This works around #13.
|
35
|
+
- Add manually defined overload for LuaControl::teleport().
|
36
|
+
|
1
37
|
# v1.3.1
|
2
38
|
|
3
|
-
- Use @linkplain instead of @link for web links. This works around issue #13
|
39
|
+
- Use @linkplain instead of @link for web links. This hopefully works around issue #13
|
4
40
|
|
5
41
|
# v1.3.0
|
6
42
|
|
@@ -60,8 +96,8 @@
|
|
60
96
|
# v0.15.0
|
61
97
|
|
62
98
|
- Table or array concepts are now declared in table form wherever it is an "read" position.
|
63
|
-
|
64
|
-
|
99
|
+
- This works with setter overloading for applicable properties: `player.color.x; player.color = [1, 1, 1]` is now valid!
|
100
|
+
- This also applies to concepts/complex types which contain table_or_array properties.
|
65
101
|
- Some concepts now also have a special form where it is known to be in a "read" position, where all table_or_array concepts are declared in table form. These concepts are suffixed with "Read", e.g. `ScriptAreaRead`.
|
66
102
|
- Arrays which are known to be in a "write" only form (e.g. method parameters) now are marked readonly. This means you can now pass readonly arrays to these methods.
|
67
103
|
- `MapPosition` is now a table or array concept.
|
@@ -77,17 +113,17 @@
|
|
77
113
|
- LuaStyle size, margin/padding setters now have more specific array types. These array types are `SizeArray` and `StyleValuesArray` for size and margin/padding, respectively.
|
78
114
|
- `@noSelf` annotation is now only present when necessary.
|
79
115
|
- For classes with subclasses:
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
116
|
+
- The original class name (e.g. `LuaItemStack`) still contains attributes of all subclasses (same as before).
|
117
|
+
- There is now a `Base` type (e.g. `BaseItemStack`) which only includes attributes common to all subclasses.
|
118
|
+
- There is a separate type definition for each subclass, e.g. `BlueprintItem`. Note that one instance may still belong to multiple subclasses (the subclasses are not mutually exclusive).
|
119
|
+
- The above two can be optionally used for stricter types.
|
84
120
|
|
85
121
|
# v0.13.2
|
86
122
|
|
87
123
|
- Fix: resize_to_sprite property should not be on subclass sprite-button
|
88
124
|
- Fix: ChooseElemButtonSpec filters should be named elem_filters
|
89
125
|
- Switch back to `/latest` api docs link
|
90
|
-
|
126
|
+
- New version of web api docs is now active
|
91
127
|
|
92
128
|
# v0.13.0
|
93
129
|
|
@@ -123,7 +159,7 @@
|
|
123
159
|
# v0.7.3
|
124
160
|
|
125
161
|
- Update to factorio version 1.1.42
|
126
|
-
|
162
|
+
- No api changes, but improvements to descriptions
|
127
163
|
|
128
164
|
# v0.7.2
|
129
165
|
|
package/README.md
CHANGED
@@ -64,41 +64,36 @@ If you have a need for types to more lualib modules, feel free to open an issue
|
|
64
64
|
|
65
65
|
### The `global` table
|
66
66
|
|
67
|
-
The `global` table is
|
67
|
+
The `global` table is a lua table which can have any shape, so it is not defined in typed-factorio. Instead, you can either:
|
68
68
|
|
69
69
|
- add `declare const global: <Your type>` in a `.d.ts` file included in your project, to apply it project-wide, or
|
70
|
-
- add `declare const global: {...}` to each module/file where needed. This way, you can
|
70
|
+
- add `declare const global: {...}` to each module/file where needed. This way, you can define only attributes that each module/file specifically uses.
|
71
71
|
|
72
72
|
## Type features
|
73
73
|
|
74
|
-
|
74
|
+
### `nil`
|
75
75
|
|
76
|
-
|
77
|
-
|
78
|
-
The types consistently use `undefined` to represent `nil`.
|
76
|
+
`nil` is equivalent to `undefined`.
|
79
77
|
|
80
78
|
A class attribute is marked as possibly undefined only if the _read_ type is possibly `nil`. For properties where `nil` is not possible on _read_, but possible on _write_, you can write `nil` by using `undefined!` or `myNullableValue!`, e.g. `controlBehavior.parameters = undefined!`.
|
81
79
|
|
82
80
|
### Parameter Variants
|
83
81
|
|
84
|
-
|
82
|
+
Parameter tables with variants (having "additional attributes can be specified depending on type ...") are defined as a union of all variants. The type for a specific variant is prefixed with the variant name, or "Other" types variants without extra properties (e.g. `AmmoDamageTechnologyModifier`, `OtherTechnologyModifier`).
|
85
83
|
|
86
84
|
### Events
|
87
85
|
|
88
|
-
Event IDs (`defines.events`) carry information about their event type and
|
89
|
-
You can pass
|
86
|
+
Event IDs (`defines.events`) carry information about their event type and filters, which is used by the various methods on `script`.
|
87
|
+
You can pass an event data type parameter to `script.generate_event_name<T>()`, and it will return a `CustomEventId` that holds type info of the event data.
|
90
88
|
|
91
89
|
### Array-like classes
|
92
90
|
|
93
|
-
Classes that have an index operator, a length operator, and have an array-like structure, inherit from `(Readonly)Array
|
94
|
-
|
95
|
-
### Table-or-array concepts, and "Read" variants
|
96
|
-
|
97
|
-
For table-or-array types (e.g. Position), there also are types such as `PositionTable` and `PositionArray` that refer to the table or array form.
|
91
|
+
Classes that have an index operator, a length operator, and have an array-like structure, inherit from `(Readonly)Array` (these are `LuaInventory`, `LuaFluidBox`, `LuaTransportLine`). This allows you to use these classes like arrays, meaning having array methods, and `.length` translating to the lua length operator. However, this also means, like typescript arrays, they are **0-indexed, not 1-indexed**.
|
98
92
|
|
99
|
-
|
93
|
+
### Read and write variants
|
100
94
|
|
101
|
-
For
|
95
|
+
For concepts that can take a table or array form, the main type (e.g. `MapPosition`) defines the table form, and an `Array` suffix (e.g. `MapPositionArray`) defines the array form.
|
96
|
+
Concepts in a "read" position will always be in the table form, and concepts in a "write" position may be either in table or array form (e.g. `MapPosition | MapPositionArray`). This is including within other concepts (e.g. in `ScriptArea`, via the `ScriptAreaWrite` type).
|
102
97
|
|
103
98
|
### Classes with subclasses
|
104
99
|
|
@@ -113,7 +108,7 @@ For stricter types, use the `Base` type generally, and the specific subclass typ
|
|
113
108
|
You can also create your own type-narrowing functions, like so:
|
114
109
|
|
115
110
|
```ts
|
116
|
-
function isCraftingMachineEntity(entity:
|
111
|
+
function isCraftingMachineEntity(entity: BaseEntity): entity is CraftingMachineEntity {
|
117
112
|
return entity.type === "crafting-machine"
|
118
113
|
}
|
119
114
|
```
|
@@ -122,7 +117,7 @@ function isCraftingMachineEntity(entity: LuaEntity): entity is CraftingMachineEn
|
|
122
117
|
|
123
118
|
`LuaGuiElement` is broken up into a [discriminated union](https://basarat.gitbook.io/typescript/type-system/discriminated-unions), with a separate type for each gui element type. Individual gui element types can be referred to by `<Type>GuiElement`, e.g. `ButtonGuiElement`.
|
124
119
|
|
125
|
-
Similarly, the table passed to `LuaGuiElement.add`, referred to as `GuiSpec`, is also broken up into a discriminated union. The type for a specific GuiSpec is `<Type>GuiSpec`, e.g. `ListBoxGuiSpec`. `LuaGuiElement.add` will return the appropriate gui element type corresponding to the
|
120
|
+
Similarly, the table passed to `LuaGuiElement.add`, referred to as `GuiSpec`, is also broken up into a discriminated union. The type for a specific GuiSpec is `<Type>GuiSpec`, e.g. `ListBoxGuiSpec`. `LuaGuiElement.add` will return the appropriate gui element type corresponding to the GuiSpec type received.
|
126
121
|
|
127
122
|
This is done both to provide more accurate types, and for possible integration with [JSX](https://typescripttolua.github.io/docs/jsx/).
|
128
123
|
|
@@ -130,6 +125,6 @@ This is done both to provide more accurate types, and for possible integration w
|
|
130
125
|
|
131
126
|
This is a recommended **opt-in** feature. To opt in, add `"typed-factorio/strict-index-types"` to `compilerOptions > types` in your tsconfig.json (in addition to `"typed-factorio/runtime"`).
|
132
127
|
|
133
|
-
Some `uint` types which represent unique indices, e.g. player_index, entity_number, can be "branded" numbers
|
128
|
+
Some `uint` types which represent unique indices, e.g. player_index, entity_number, can be "branded" numbers, e.g. `PlayerIndex` and `EntityNumber`. If opted-in, these index-types will be still assignable to `number`, but a plain `number` is not directly assignable to them. This helps ensure their correct use.
|
134
129
|
You can use these types as keys in an index signature, e.g. `{ [index: PlayerIndex]: "foo" }`.
|
135
130
|
You can cast "plain" numbers to these types, e.g. `1 as PlayerIndex`, do this with caution.
|
@@ -7,6 +7,7 @@
|
|
7
7
|
// generated
|
8
8
|
/// <reference types="typed-factorio/generated/builtin-types.d.ts" />
|
9
9
|
/// <reference types="typed-factorio/generated/global-objects.d.ts" />
|
10
|
+
/// <reference types="typed-factorio/generated/global-functions.d.ts" />
|
10
11
|
/// <reference types="typed-factorio/generated/defines.d.ts" />
|
11
12
|
/// <reference types="typed-factorio/generated/events.d.ts" />
|
12
13
|
/// <reference types="typed-factorio/generated/classes.d.ts" />
|
@@ -4,63 +4,68 @@
|
|
4
4
|
|
5
5
|
/**
|
6
6
|
* A floating-point number. This is a single-precision floating point number. Whilst Lua only uses double-precision numbers, when a function takes a float, the game engine will immediately convert the double-precision number to single-precision.
|
7
|
-
*
|
8
|
-
* {@link https://lua-api.factorio.com/latest/Builtin-Types.html#float View documentation}
|
7
|
+
* @see {@link https://lua-api.factorio.com/latest/Builtin-Types.html#float Online documentation}
|
9
8
|
*/
|
10
9
|
type float = number
|
11
10
|
|
12
11
|
/**
|
13
12
|
* A double-precision floating-point number. This is the same data type as all Lua numbers use.
|
14
|
-
*
|
15
|
-
* {@link https://lua-api.factorio.com/latest/Builtin-Types.html#double View documentation}
|
13
|
+
* @see {@link https://lua-api.factorio.com/latest/Builtin-Types.html#double Online documentation}
|
16
14
|
*/
|
17
15
|
type double = number
|
18
16
|
|
19
17
|
/**
|
20
18
|
* 32-bit signed integer. Possible values are -2,147,483,648 to 2,147,483,647.
|
21
|
-
*
|
22
|
-
* {@link https://lua-api.factorio.com/latest/Builtin-Types.html#int View documentation}
|
19
|
+
* @see {@link https://lua-api.factorio.com/latest/Builtin-Types.html#int Online documentation}
|
23
20
|
*/
|
24
21
|
type int = number
|
25
22
|
|
26
23
|
/**
|
27
24
|
* 8-bit signed integer. Possible values are -128 to 127.
|
28
|
-
*
|
29
|
-
* {@link https://lua-api.factorio.com/latest/Builtin-Types.html#int8 View documentation}
|
25
|
+
* @see {@link https://lua-api.factorio.com/latest/Builtin-Types.html#int8 Online documentation}
|
30
26
|
*/
|
31
27
|
type int8 = number
|
32
28
|
|
33
29
|
/**
|
34
30
|
* 32-bit unsigned integer. Possible values are 0 to 4,294,967,295.
|
35
|
-
*
|
36
|
-
* {@link https://lua-api.factorio.com/latest/Builtin-Types.html#uint View documentation}
|
31
|
+
* @see {@link https://lua-api.factorio.com/latest/Builtin-Types.html#uint Online documentation}
|
37
32
|
*/
|
38
33
|
type uint = number
|
39
34
|
|
40
35
|
/**
|
41
36
|
* 8-bit unsigned integer. Possible values are 0 to 255.
|
42
|
-
*
|
43
|
-
* {@link https://lua-api.factorio.com/latest/Builtin-Types.html#uint8 View documentation}
|
37
|
+
* @see {@link https://lua-api.factorio.com/latest/Builtin-Types.html#uint8 Online documentation}
|
44
38
|
*/
|
45
39
|
type uint8 = number
|
46
40
|
|
47
41
|
/**
|
48
42
|
* 16-bit unsigned integer. Possible values are 0 to 65535.
|
49
|
-
*
|
50
|
-
* {@link https://lua-api.factorio.com/latest/Builtin-Types.html#uint16 View documentation}
|
43
|
+
* @see {@link https://lua-api.factorio.com/latest/Builtin-Types.html#uint16 Online documentation}
|
51
44
|
*/
|
52
45
|
type uint16 = number
|
53
46
|
|
54
47
|
/**
|
55
48
|
* 64-bit unsigned integer. Possible values are 0 to 18,446,744,073,709,551,615.
|
56
|
-
*
|
57
|
-
* {@link https://lua-api.factorio.com/latest/Builtin-Types.html#uint64 View documentation}
|
49
|
+
* @see {@link https://lua-api.factorio.com/latest/Builtin-Types.html#uint64 Online documentation}
|
58
50
|
*/
|
59
51
|
type uint64 = number
|
60
52
|
|
61
53
|
/**
|
62
|
-
*
|
63
|
-
*
|
64
|
-
|
54
|
+
* Nil is the type of the value `nil`, whose main property is to be different from any other value. It usually represents the absence of a useful value.
|
55
|
+
* @see {@link https://lua-api.factorio.com/latest/Builtin-Types.html#nil Online documentation}
|
56
|
+
*/
|
57
|
+
type nil = undefined
|
58
|
+
|
59
|
+
/**
|
60
|
+
* Tables are enclosed in curly brackets, like this `{}`.
|
61
|
+
* @see {@link https://lua-api.factorio.com/latest/Builtin-Types.html#table Online documentation}
|
65
62
|
*/
|
66
63
|
type table = object
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Any LuaObject listed on the {@linkplain https://lua-api.factorio.com/latest/Classes.html Classes} page.
|
67
|
+
* @see {@link https://lua-api.factorio.com/latest/Builtin-Types.html#LuaObject Online documentation}
|
68
|
+
*/
|
69
|
+
interface LuaObject {
|
70
|
+
readonly object_name: string
|
71
|
+
}
|