typed-factorio 0.18.1 → 0.20.0-beta.1
Sign up to get free protection for your applications and to get access to all the features.
- package/Changelog.md +24 -8
- package/README.md +26 -15
- package/custom-index-template.d.ts +24 -0
- package/generated/builtin-types.d.ts +1 -3
- package/generated/classes.d.ts +5297 -6144
- package/generated/concepts.d.ts +1926 -1208
- package/generated/defines.d.ts +464 -163
- package/generated/events.d.ts +2196 -913
- package/generated/global-objects.d.ts +1 -2
- package/generated/index-types-strict.d.ts +52 -0
- package/generated/index-types.d.ts +38 -0
- package/package.json +2 -6
- package/runtime/index.d.ts +9 -1
- package/runtime/pairs.d.ts +1 -0
- package/runtime/strict-index-types.d.ts +18 -0
- package/runtime/util.d.ts +12 -12
- package/generated/index.d.ts +0 -9
package/Changelog.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
# v0.20.0
|
2
|
+
|
3
|
+
- Updated to factorio version 1.1.56
|
4
|
+
- Added custom-index-template.d.ts. You can use this if you would like to make a "custom" modification of the type definitions.
|
5
|
+
- **This is an opt-in**: Some numeric types which represent indices/number,e.g. player_index, entity_number, are now branded numbers with their own type, e.g. `PlayerIndex` and `EntityNumber`. See the README for more info.
|
6
|
+
|
7
|
+
# v0.19.0
|
8
|
+
|
9
|
+
- Updated to factorio version 1.1.53
|
10
|
+
- Updated to json api version 2
|
11
|
+
- Improved documentation comments
|
12
|
+
|
13
|
+
## Changes
|
14
|
+
|
15
|
+
- `Position`, `PositionArray`, and `PositionTable` have been replaced by `MapPosition`, `MapPositionArray`, and `MapPositionTable` respectively. These are now deprecated and may be removed in a future version.
|
16
|
+
|
1
17
|
# v0.18.1
|
2
18
|
|
3
19
|
- `TechnologyIdentification` now also has a more specific type when read.
|
@@ -23,8 +39,8 @@
|
|
23
39
|
# v0.15.0
|
24
40
|
|
25
41
|
- Table or array concepts are now declared in table form wherever it is an "read" position.
|
26
|
-
|
27
|
-
|
42
|
+
- This works with setter overloading for applicable properties: `player.color.x; player.color = [1, 1, 1]` is now valid!
|
43
|
+
- This also applies to concepts/complex types which contain table_or_array properties.
|
28
44
|
- 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`.
|
29
45
|
- 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.
|
30
46
|
- `MapPosition` is now a table or array concept.
|
@@ -40,17 +56,17 @@
|
|
40
56
|
- LuaStyle size, margin/padding setters now have more specific array types. These array types are `SizeArray` and `StyleValuesArray` for size and margin/padding, respectively.
|
41
57
|
- `@noSelf` annotation is now only present when necessary.
|
42
58
|
- For classes with subclasses:
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
59
|
+
- The original class name (e.g. `LuaItemStack`) still contains attributes of all subclasses (same as before).
|
60
|
+
- There is now a `Base` type (e.g. `BaseItemStack`) which only includes attributes common to all subclasses.
|
61
|
+
- 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).
|
62
|
+
- The above two can be optionally used for stricter types.
|
47
63
|
|
48
64
|
# v0.13.2
|
49
65
|
|
50
66
|
- Fix: resize_to_sprite property should not be on subclass sprite-button
|
51
67
|
- Fix: ChooseElemButtonSpec filters should be named elem_filters
|
52
68
|
- Switch back to `/latest` api docs link
|
53
|
-
|
69
|
+
- New version of web api docs is now active
|
54
70
|
|
55
71
|
# v0.13.0
|
56
72
|
|
@@ -86,7 +102,7 @@
|
|
86
102
|
# v0.7.3
|
87
103
|
|
88
104
|
- Update to factorio version 1.1.42
|
89
|
-
|
105
|
+
- No api changes, but improvements to descriptions
|
90
106
|
|
91
107
|
# v0.7.2
|
92
108
|
|
package/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Complete and featureful typescript definitions for the Factorio modding lua api. This is intended to be used with [TypescriptToLua](https://typescripttolua.github.io/).
|
4
4
|
|
5
|
-
This project aims to provide type definitions for the Factorio lua API that are as complete as possible. This means no `any`s or `unknown`s, correct nullability, and smart
|
5
|
+
This project aims to provide type definitions for the Factorio lua API that are as complete as possible. This means no `any`s or `unknown`s, correct nullability, and lots of smart type features. The generator integrates both the Factorio JSON api docs and manually defined additions and overrides.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -30,7 +30,10 @@ yarn add typed-factorio
|
|
30
30
|
|
31
31
|
This will add the types for the runtime stage to your entire project.
|
32
32
|
|
33
|
-
|
33
|
+
Notes:
|
34
|
+
> When types are updated, or released for a new factorio version, you will need update your package version to get the types.
|
35
|
+
>
|
36
|
+
> There is an opt-in feature for stricter index types, see [Strict index types](#Strict index types) for more details.
|
34
37
|
|
35
38
|
### Settings and data stage
|
36
39
|
|
@@ -42,7 +45,7 @@ Example:
|
|
42
45
|
|
43
46
|
```ts
|
44
47
|
import { Data, Mods } from "typed-factorio/data/types"
|
45
|
-
// or
|
48
|
+
// or
|
46
49
|
import { Data, Mods } from "typed-factorio/settings/types"
|
47
50
|
|
48
51
|
declare const data: Data
|
@@ -93,15 +96,6 @@ Variant parameter types (types with "additional fields can be specified dependin
|
|
93
96
|
|
94
97
|
The type for a specific variant is prefixed with the variant name, or with "Other" for variants without additional fields (e.g. `AmmoDamageTechnologyModifier`, `OtherTechnologyModifier`).
|
95
98
|
|
96
|
-
### Types with subclasses
|
97
|
-
|
98
|
-
Some classes have attributes that are documented to only work on particular subclasses. For these classes, e.g. `LuaEntity`, there are also these other types that you can _optionally_ use:
|
99
|
-
|
100
|
-
- a "Base" type, e.g. `BaseEntity`, which only contains members usable by all subclasses
|
101
|
-
- individual subclass types, e.g. `CraftingMachineEntity`, which extends the base type with members specific to that subclass
|
102
|
-
|
103
|
-
The simple class name, `LuaEntity` in this example, still contains attributes for _all_ subclasses.
|
104
|
-
|
105
99
|
### Events
|
106
100
|
|
107
101
|
`script.on_event()`, `script.get/set_filters()`, and `script.raise_event()` all have type checking on the event data/filter type, inferred from what is passed as the event name/id.
|
@@ -120,14 +114,31 @@ Table-or-array types will appear in the Table form when known to be in a read po
|
|
120
114
|
|
121
115
|
For some concepts, there is also a special form for when the concept is used in a "read" position, where all table-or-array types are in Table form. These types are suffixed with `Read`, e.g. `ScriptPositionRead`.
|
122
116
|
|
117
|
+
|
118
|
+
### Types with subclasses
|
119
|
+
|
120
|
+
Some classes have attributes that are documented to only work on particular subclasses. For these classes, e.g. `LuaEntity`, there are specific types that you can _optionally_ use:
|
121
|
+
|
122
|
+
- a "Base" type, e.g. `BaseEntity`, which only contains members usable by all subclasses
|
123
|
+
- individual subclass types, e.g. `CraftingMachineEntity`, which extends the base type with members specific to that subclass
|
124
|
+
|
125
|
+
The simple class name, `LuaEntity` in this example, contains attributes for _all_ subclasses.
|
126
|
+
|
123
127
|
### LuaGuiElement
|
124
128
|
|
125
129
|
`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`.
|
126
130
|
|
127
|
-
Similarly, the table passed to `LuaGuiElement.add`, referred to as `GuiSpec`, is also broken up into a discriminated union
|
131
|
+
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 gui spec type received.
|
128
132
|
|
129
133
|
This is done both to provide more accurate types, and for possible integration with [JSX](https://typescripttolua.github.io/docs/jsx/).
|
130
134
|
|
131
|
-
###
|
135
|
+
### Strict index types
|
136
|
+
|
137
|
+
This feature is recommended, but currently is a **opt-in**. To opt in, use `typed-factorio/runtime/strict-index-types` instead of `typed-factorio/runtime` in your `tsconfig.json`.
|
138
|
+
|
139
|
+
Some `uint` types which represent indices, e.g. player_index, entity_number, are now "branded" numbers with their own type, e.g. `PlayerIndex` and `EntityNumber`. These are assignable to `number`, but `number` is not assignable to them.
|
140
|
+
These are indices that do not index into an array-like structure, and otherwise should usually not have arithmetic done to them. So, using a separate type helps ensure correctness.
|
141
|
+
You can still use these types as keys in an index signature, e.g. `{ [index: PlayerIndex]: "foo" }`.
|
142
|
+
You can cast "plain" numbers to these types, e.g. `2 as PlayerIndex`, only do this with some care.
|
132
143
|
|
133
|
-
|
144
|
+
- `player_index` and `surface_index` still allow the numeric constant 1 as a valid index, representing the first player or the default surface, respectively. This is allowed as this is a common enough use case.
|
@@ -0,0 +1,24 @@
|
|
1
|
+
// This references the same files as "typed-factorio/runtime".
|
2
|
+
// For example, if you want to modify a file, copy the file you want to modify to your project and make the changes. Then, copy this template file into your project and remove the line corresponding to modified file.
|
3
|
+
// If you think your modification will be useful to others, please consider making a change suggestion by creating an issue on GitHub.
|
4
|
+
|
5
|
+
// Replace "index-types.d.ts" with "index-types-strict.d.ts" below if you want strict index types.
|
6
|
+
|
7
|
+
/// <reference types="lua-types/5.2" />
|
8
|
+
|
9
|
+
// generated
|
10
|
+
/// <reference types="typed-factorio/generated/builtin-types.d.ts" />
|
11
|
+
/// <reference types="typed-factorio/generated/global-objects.d.ts" />
|
12
|
+
/// <reference types="typed-factorio/generated/defines.d.ts" />
|
13
|
+
/// <reference types="typed-factorio/generated/events.d.ts" />
|
14
|
+
/// <reference types="typed-factorio/generated/classes.d.ts" />
|
15
|
+
/// <reference types="typed-factorio/generated/concepts.d.ts" />
|
16
|
+
/// <reference types="typed-factorio/generated/index-types.d.ts" />
|
17
|
+
|
18
|
+
// other runtime
|
19
|
+
/// <reference types="typed-factorio/runtime/librariesAndFunctions.d.ts" />
|
20
|
+
/// <reference types="typed-factorio/runtime/pairs.d.ts" />
|
21
|
+
|
22
|
+
// lualib
|
23
|
+
/// <reference types="typed-factorio/runtime/util.d.ts" />
|
24
|
+
/// <reference types="typed-factorio/runtime/mod-gui.d.ts" />
|
@@ -3,9 +3,7 @@
|
|
3
3
|
/** @noSelfInFile */
|
4
4
|
|
5
5
|
/**
|
6
|
-
* A floating-point number. This is a single-precision floating point number. Whilst Lua only uses double-precision
|
7
|
-
* numbers, when a function takes a float, the game engine will immediately convert the double-precision number to
|
8
|
-
* single-precision.
|
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.
|
9
7
|
*
|
10
8
|
* {@link https://lua-api.factorio.com/latest/Builtin-Types.html#float View documentation}
|
11
9
|
*/
|