typed-factorio 3.18.0 → 3.19.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/README.md +48 -47
- package/package.json +2 -2
- package/prototype/generated/prototypes.d.ts +2140 -2110
- package/prototype/generated/types.d.ts +2133 -2110
- package/runtime/generated/classes.d.ts +3705 -3679
- package/runtime/generated/concepts.d.ts +5925 -5925
- package/runtime/generated/defines.d.ts +199 -188
- package/runtime/generated/events.d.ts +205 -205
- package/runtime/generated/global-functions.d.ts +3 -3
- package/runtime/generated/global-objects.d.ts +8 -8
package/README.md
CHANGED
@@ -4,18 +4,17 @@
|
|
4
4
|
|
5
5
|
Complete and featureful typescript definitions for the Factorio modding lua API, for use with [TypescriptToLua](https://typescripttolua.github.io/).
|
6
6
|
|
7
|
-
This project aims to provide type definitions are as complete as possible.
|
8
|
-
The generator uses both the Factorio api docs JSON and manually defined additions.
|
7
|
+
This project aims to provide type definitions that are as complete as possible.
|
9
8
|
|
10
9
|
## Installation
|
11
10
|
|
12
11
|
To use in your [TypescriptToLua](https://typescripttolua.github.io/) project:
|
13
12
|
|
14
|
-
1. Install this package: `npm install typed-factorio`
|
13
|
+
1. Install this package: `npm install --save-dev typed-factorio`
|
15
14
|
|
16
|
-
|
15
|
+
> Note: When types are updated for a new factorio version, you will need to update this package.
|
17
16
|
|
18
|
-
2. Add types for the [stages](https://lua-api.factorio.com/
|
17
|
+
2. Add types for the [Factorio stages](https://lua-api.factorio.com/latest) used to your `tsconfig.json` under `compilerOptions > types`.
|
19
18
|
The available stages are `"typed-factorio/settings"`, `"typed-factorio/prototype"`, and `"typed-factorio/runtime"`.
|
20
19
|
|
21
20
|
Example:
|
@@ -29,16 +28,16 @@ Example:
|
|
29
28
|
}
|
30
29
|
```
|
31
30
|
|
32
|
-
|
33
|
-
You can include multiple stages, but there are some caveats.
|
31
|
+
Each stage will define the global variables used in that stage.
|
32
|
+
You can include multiple stages, but there are some caveats. For more info, see [Using multiple stages in the same project](#using-multiple-loading-stages-in-the-same-project).
|
34
33
|
|
35
34
|
## Usage notes
|
36
35
|
|
37
|
-
|
36
|
+
Some more info on using types.
|
38
37
|
|
39
38
|
### Types for other stages
|
40
39
|
|
41
|
-
No matter which stage(s) are selected,
|
40
|
+
No matter which stage(s) are selected, type definitions for all stages are available in the modules `"factorio:settings"`, `"factorio:prototype"`, and `"factorio:runtime"`:
|
42
41
|
|
43
42
|
```ts
|
44
43
|
import { BoolSettingDefinition } from "factorio:settings"
|
@@ -46,14 +45,39 @@ import { ItemPrototype } from "factorio:prototype"
|
|
46
45
|
import { LuaEntity } from "factorio:runtime"
|
47
46
|
```
|
48
47
|
|
49
|
-
You can also include just `"typed-factorio"` in your `types
|
48
|
+
You can also include just `"typed-factorio"` in your tsconfig's `types`. This will define only global variables that are available to _all_ stages.
|
50
49
|
|
51
|
-
### `
|
50
|
+
### The `storage` table
|
51
|
+
|
52
|
+
The `storage` table (in the runtime stage) can have any shape, so it is not defined here. Instead, you can define it yourself:
|
53
|
+
|
54
|
+
- Add `declare const storage: <Your type>` in a `.d.ts` file. Make sure this file is included by your tsconfig!
|
55
|
+
- Add `declare global { const storage: <Your type> }` in a `.ts` file included in your project.
|
56
|
+
- Add `declare const storage: {...}` to each file where needed. This way, you can define only properties that each file specifically uses.
|
57
|
+
|
58
|
+
### Factorio lualib modules
|
59
|
+
|
60
|
+
There are types for the following [Factorio lualib modules](https://github.com/wube/factorio-data/tree/master/core/lualib):
|
61
|
+
|
62
|
+
- `util`
|
63
|
+
- `mod-gui`
|
64
|
+
|
65
|
+
These can be imported as modules:
|
66
|
+
|
67
|
+
```ts
|
68
|
+
import * as util from "util"
|
69
|
+
|
70
|
+
const foo = util.copy(bar)
|
71
|
+
```
|
72
|
+
|
73
|
+
If you wish to see types for more lualib modules, feel free to open an issue or pull request.
|
74
|
+
|
75
|
+
### Types for `data.extend()`
|
52
76
|
|
53
77
|
In the settings and prototype stages, the `data` global variable is available.
|
54
78
|
|
55
79
|
For [performance reasons](https://github.com/microsoft/TypeScript/wiki/Performance#preferring-base-types-over-unions), `data.extend()` is by default loosely typed.
|
56
|
-
To get full type checking, you can use
|
80
|
+
To get full strict type checking, you can use one of the following methods:
|
57
81
|
|
58
82
|
```ts
|
59
83
|
// Use `satisfies` to check types:
|
@@ -69,7 +93,7 @@ data.extend([
|
|
69
93
|
} satisfies ItemPrototype,
|
70
94
|
])
|
71
95
|
|
72
|
-
// List types as a type argument to `extend`:
|
96
|
+
// List types used as a type argument to `extend`:
|
73
97
|
data.extend<AmmoCategory | ItemPrototype>([
|
74
98
|
{
|
75
99
|
type: "ammo-category",
|
@@ -92,31 +116,6 @@ const barItem: ItemPrototype = {
|
|
92
116
|
data.extend([fooCategory, barItem])
|
93
117
|
```
|
94
118
|
|
95
|
-
### Factorio lualib modules
|
96
|
-
|
97
|
-
There are types for the following [Factorio lualib modules](https://github.com/wube/factorio-data/tree/master/core/lualib):
|
98
|
-
|
99
|
-
- `util`
|
100
|
-
- `mod-gui`
|
101
|
-
|
102
|
-
These can be imported as modules:
|
103
|
-
|
104
|
-
```ts
|
105
|
-
import * as util from "util"
|
106
|
-
|
107
|
-
const foo = util.copy(bar)
|
108
|
-
```
|
109
|
-
|
110
|
-
If you wish to see types for more lualib modules, feel free to open an issue or pull request.
|
111
|
-
|
112
|
-
### The `storage` table
|
113
|
-
|
114
|
-
The `storage` table (in the runtime stage) can have any shape, so it is not defined here. Instead, you can define it yourself:
|
115
|
-
|
116
|
-
- Add `declare const storage: <Your type>` in a `.d.ts` file. Make sure this file is included by your tsconfig!
|
117
|
-
- Add `declare global { const storage: <Your type> }` in a `.ts` file included in your project.
|
118
|
-
- Add `declare const storage: {...}` to each file where needed. This way, you can define only properties that each file specifically uses.
|
119
|
-
|
120
119
|
## Using multiple loading stages in the same project
|
121
120
|
|
122
121
|
Every Factorio loading stage declares different global variables.
|
@@ -157,11 +156,11 @@ Parameter tables with variants (having "additional attributes can be specified d
|
|
157
156
|
|
158
157
|
### Events
|
159
158
|
|
160
|
-
Event IDs (`defines.events`) hold type info
|
159
|
+
Event IDs (`defines.events`) hold type info on their corresponding event data type and filters, which is used by various methods in `script`.
|
161
160
|
|
162
|
-
You can pass
|
161
|
+
You can pass a type parameter to `script.generate_event_name<T>()`, and it will return a `CustomEventId` that includes type info.
|
163
162
|
|
164
|
-
### Optional
|
163
|
+
### Optional CustomInput name checking
|
165
164
|
|
166
165
|
You can optionally enable type-checking for custom input names (for `script.on_event` and `CustomInputPrototype`).
|
167
166
|
To do so, specify names by extending the CustomInputNames interface like so:
|
@@ -174,27 +173,29 @@ declare module "factorio:common" {
|
|
174
173
|
}
|
175
174
|
|
176
175
|
script.on_event("my-custom-input", () => {}) // type-checked
|
176
|
+
// script.on_event("my-customm-input", () => {}) // mispelled, will error
|
177
177
|
```
|
178
178
|
|
179
|
-
|
179
|
+
The type `CustomInputName` (not plural) will be a union of strings, for all custom input names.
|
180
|
+
If not specified like above, `CustomInputName` defaults to just `string`.
|
180
181
|
|
181
182
|
### Array-like classes
|
182
183
|
|
183
|
-
|
184
|
+
A few classes that have an index operator, a length operator, and have an array-like structure, which will subclass from `(Readonly)Array`. These are `LuaInventory`, `LuaFluidBox`, `LuaTransportLine`.
|
184
185
|
This allows you to use these classes like arrays, e.g. having array methods and `.length` translating to the lua length operator. However, this means like typescript arrays, they are **0-indexed, not 1-indexed**.
|
185
186
|
|
186
187
|
### Read and write variants
|
187
188
|
|
188
|
-
For concepts that can take a table
|
189
|
-
Concepts in a "read" position are in table form
|
189
|
+
For concepts that can take a table-or-array form, the main type (e.g. `MapPosition`) defines the table form, and a type suffixed with `Array` (e.g. `MapPositionArray`) defines the array form.
|
190
|
+
Concepts in a "read" position are in table form. Concepts in a "write" position may be in either table or array form (e.g. `MapPosition | MapPositionArray`).
|
190
191
|
Concepts that include table-or-array concepts may have an additional `Write` variant (e.g. `ScriptArea`, `ScriptAreaWrite`).
|
191
192
|
|
192
193
|
### Classes with subclasses
|
193
194
|
|
194
|
-
Some classes have attributes that only work for particular subclasses
|
195
|
+
Some classes have attributes that only work for particular subclasses (e.g. LuaEntity.recipe only works if this is crafting-machine). For these classes, there are more specific types you can _optionally_ use:
|
195
196
|
|
196
197
|
- A "Base" type (e.g. `BaseEntity`) which contains only members usable by all subclasses
|
197
|
-
-
|
198
|
+
- Subclass types, e.g. `CraftingMachineEntity`, which extends the base type with members specific to that subclass.
|
198
199
|
|
199
200
|
The original class name (e.g. `LuaEntity`) contains attributes for _all_ subclasses.
|
200
201
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "typed-factorio",
|
3
|
-
"version": "3.
|
3
|
+
"version": "3.19.1",
|
4
4
|
"description": "Featureful typescript definitions for the Factorio modding api.",
|
5
5
|
"keywords": [
|
6
6
|
"factorio",
|
@@ -62,5 +62,5 @@
|
|
62
62
|
"typescript": "~5.4.2",
|
63
63
|
"typescript-to-lua": "^1.25.0"
|
64
64
|
},
|
65
|
-
"factorioVersion": "2.0.
|
65
|
+
"factorioVersion": "2.0.44"
|
66
66
|
}
|