typed-factorio 1.4.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
package/Changelog.md CHANGED
@@ -1,3 +1,31 @@
1
+ # v1.6.0
2
+
3
+ - Updated to factorio version 1.1.64
4
+
5
+ # v1.5.1
6
+
7
+ - Added old `Read` types as deprecated type aliases of new types; to help with migration.
8
+
9
+ # v1.5.0
10
+
11
+ ### BREAKING
12
+
13
+ - 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.
14
+ - Write forms are now specified as either a union of table and array forms, or with a `Write` suffix for concepts.
15
+ - For table-or-array concepts: `MapPositionRead` -> `MapPosition`, `MapPosition` -> `MapPosition | PositionArray`
16
+ - For table concepts: `ScriptAreaRead` -> `ScriptArea`, `ScriptArea` -> `ScriptAreaWrite`
17
+ - The minimum TSTL version has been increased to v1.6.1 (A bug with documentation comments was fixed in that version).
18
+
19
+ ### Other
20
+
21
+ - Updated to factorio version 1.1.63.
22
+ - Upgraded to factorio api docs json version 3.
23
+ - The new type `nil` is used instead of `undefined` (they are equivalent).
24
+ - More complete type for `BlueprintEntity`.
25
+ - Fixed missing read-write forms for more concepts.
26
+ - Improved documentation comments (enabled by json docs version 3).
27
+ - Improved documentation comments for variant parameter groups.
28
+
1
29
  # v1.4.0
2
30
 
3
31
  - Improve doc comments for enum concepts
@@ -72,8 +100,8 @@
72
100
  # v0.15.0
73
101
 
74
102
  - Table or array concepts are now declared in table form wherever it is an "read" position.
75
- - This works with setter overloading for applicable properties: `player.color.x; player.color = [1, 1, 1]` is now valid!
76
- - This also applies to concepts/complex types which contain table_or_array properties.
103
+ - This works with setter overloading for applicable properties: `player.color.x; player.color = [1, 1, 1]` is now valid!
104
+ - This also applies to concepts/complex types which contain table_or_array properties.
77
105
  - 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`.
78
106
  - 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.
79
107
  - `MapPosition` is now a table or array concept.
@@ -89,17 +117,17 @@
89
117
  - LuaStyle size, margin/padding setters now have more specific array types. These array types are `SizeArray` and `StyleValuesArray` for size and margin/padding, respectively.
90
118
  - `@noSelf` annotation is now only present when necessary.
91
119
  - For classes with subclasses:
92
- - The original class name (e.g. `LuaItemStack`) still contains attributes of all subclasses (same as before).
93
- - There is now a `Base` type (e.g. `BaseItemStack`) which only includes attributes common to all subclasses.
94
- - 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).
95
- - The above two can be optionally used for stricter types.
120
+ - The original class name (e.g. `LuaItemStack`) still contains attributes of all subclasses (same as before).
121
+ - There is now a `Base` type (e.g. `BaseItemStack`) which only includes attributes common to all subclasses.
122
+ - 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).
123
+ - The above two can be optionally used for stricter types.
96
124
 
97
125
  # v0.13.2
98
126
 
99
127
  - Fix: resize_to_sprite property should not be on subclass sprite-button
100
128
  - Fix: ChooseElemButtonSpec filters should be named elem_filters
101
129
  - Switch back to `/latest` api docs link
102
- - New version of web api docs is now active
130
+ - New version of web api docs is now active
103
131
 
104
132
  # v0.13.0
105
133
 
@@ -135,7 +163,7 @@
135
163
  # v0.7.3
136
164
 
137
165
  - Update to factorio version 1.1.42
138
- - No api changes, but improvements to descriptions
166
+ - No api changes, but improvements to descriptions
139
167
 
140
168
  # v0.7.2
141
169
 
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 just a lua table which can have any shape the mod desires, so it is not defined in typed-factorio. Instead, you can either:
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 also only define attributes that each module/file specifically uses.
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
- Here is a quick overview of type features:
74
+ ### `nil`
75
75
 
76
- ### Nullability
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
- Parameters with variants (with "additional fields 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`).
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 possible filters, which is used by the various methods on `script`.
89
- You can pass a type parameter to `script.generate_event_name<T>()`, and it will return an `EventId` that holds type info of the event data.
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`. 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**.
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
- Table-or-array types will appear in Table form when known to be in a read position. This also applies to other concepts/types that have table-or-array attributes.
93
+ ### Read and write variants
100
94
 
101
- For some concepts, there is also a special form for when it 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`, `BoundingBoxRead`.
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: LuaEntity): entity is CraftingMachineEntity {
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 gui spec type received.
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 with their own type, 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 correctness.
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
- * Tables are enclosed in curly brackets, like this `{}`
63
- *
64
- * {@link https://lua-api.factorio.com/latest/Builtin-Types.html#table View documentation}
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
+ }