typed-factorio 0.5.0 → 0.7.0
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 +12 -12
- package/generated/classes.d.ts +33 -23
- package/generated/concepts.d.ts +387 -255
- package/generated/defines.d.ts +279 -200
- package/generated/events.d.ts +15 -198
- package/package.json +4 -4
package/README.md
CHANGED
@@ -34,9 +34,11 @@ Note: When types are updated, or released for a new factorio version, you will n
|
|
34
34
|
|
35
35
|
### Settings and data stage
|
36
36
|
|
37
|
-
There are also
|
37
|
+
There are also definitions for the settings/data stage.
|
38
38
|
|
39
|
-
To avoid type conflicts, the global tables for the settings/data stages have to be declared manually where you need them.
|
39
|
+
To avoid type conflicts, the global tables for the settings/data stages have to be declared manually where you need them. These types can be imported from `typed-factorio/data/types` or `typed-factorio/settings/types`.
|
40
|
+
|
41
|
+
Example:
|
40
42
|
|
41
43
|
```ts
|
42
44
|
import { Data, Mods } from "typed-factorio/data/types"
|
@@ -58,27 +60,25 @@ Currently, there are types for the following modules:
|
|
58
60
|
- `util`
|
59
61
|
- `mod-gui`
|
60
62
|
|
61
|
-
If you have a need for types to more lualib modules, feel free to open an issue or pull request.
|
63
|
+
If you have a need for types to more lualib modules, feel free to open an issue or pull request on GitHub.
|
62
64
|
|
63
65
|
## Type features
|
64
66
|
|
65
|
-
Typed-factorio has
|
66
|
-
|
67
|
-
The only incomplete type is `BlueprintControlBehavior`, which isn't documented anywhere.
|
67
|
+
Typed-factorio has 100% complete types for the runtime stage. Description-only concepts and some not documented types are filled in manually.
|
68
68
|
|
69
69
|
### Lua features
|
70
70
|
|
71
71
|
The types include [TypescriptToLua language extensions](https://typescripttolua.github.io/docs/advanced/language-extensions/)
|
72
|
-
and [lua-types](https://github.com/TypeScriptToLua/lua-types) (for v5.2)
|
72
|
+
and [lua-types](https://github.com/TypeScriptToLua/lua-types) (for v5.2) as dependencies.
|
73
73
|
|
74
74
|
This is to use tstl features such as `LuaLengthMethod` and `LuaMultiReturn`.
|
75
75
|
|
76
76
|
### `nil`
|
77
77
|
|
78
78
|
The types consistently use `undefined` to represent `nil`.
|
79
|
-
`null` is not used,
|
79
|
+
`null` is not used, because `undefined` in typescript is much more similar to `nil` in lua, and optional parameters/properties already use `undefined`.
|
80
80
|
|
81
|
-
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 is possible on
|
81
|
+
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 is possible on _write_, you can write `nil` by using `undefined!` or `myNullableValue!`, e.g. `controlBehavior.parameters = undefined!`.
|
82
82
|
|
83
83
|
### Variant parameter types
|
84
84
|
|
@@ -90,7 +90,7 @@ The type for a specific variant is prefixed with the either variant name or "Oth
|
|
90
90
|
|
91
91
|
`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.
|
92
92
|
|
93
|
-
You can pass a type parameter to `script.generate_event_name()
|
93
|
+
You can pass a type parameter to `script.generate_event_name()`, and it will return an `EventId` that holds type info of the event data. Event functions on `script` can then use the type data when the `EventId` is passed.
|
94
94
|
|
95
95
|
### Array-like types
|
96
96
|
|
@@ -98,7 +98,7 @@ Classes that have an index operator, a length operator, and have an array-like s
|
|
98
98
|
|
99
99
|
### Table or array types
|
100
100
|
|
101
|
-
For table or array types (e.g. Position), there also are types such as `PositionTable` and `PositionArray`
|
101
|
+
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 specifically.
|
102
102
|
|
103
103
|
### LuaGuiElement
|
104
104
|
|
@@ -110,4 +110,4 @@ This is done both to provide more accurate types, and for possible integration w
|
|
110
110
|
|
111
111
|
### Examples
|
112
112
|
|
113
|
-
Check out the `
|
113
|
+
Check out the `test` directory on GitHub for more examples on particular type features.
|
package/generated/classes.d.ts
CHANGED
@@ -241,11 +241,6 @@ type RaiseableEvents =
|
|
241
241
|
| typeof defines.events.script_raised_revive
|
242
242
|
| typeof defines.events.script_raised_set_tiles
|
243
243
|
|
244
|
-
/** A custom event id created by {@link LuaBootstrap.generate_event_name}, with type data of the event. */
|
245
|
-
type CustomEventId<T extends table> = uint & {
|
246
|
-
_eventData: T
|
247
|
-
}
|
248
|
-
|
249
244
|
/**
|
250
245
|
* Entry point for registering event handlers. It is accessible through the global object named `script`.
|
251
246
|
*
|
@@ -336,14 +331,13 @@ interface LuaBootstrap {
|
|
336
331
|
* @param f - The handler for this event. Passing `nil` will unregister it.
|
337
332
|
* @param filters - The filters for this event. Can only be used when registering for individual events.
|
338
333
|
*/
|
339
|
-
on_event<E extends
|
334
|
+
on_event<E extends EventId<any, table>>(
|
340
335
|
event: E,
|
341
|
-
f: ((data:
|
342
|
-
filters?:
|
336
|
+
f: ((data: E["_eventData"]) => void) | undefined,
|
337
|
+
filters?: E["_filter"][]
|
343
338
|
): void
|
344
|
-
on_event<E extends
|
339
|
+
on_event<E extends EventId<any, any>>(event: E | E[], f: ((data: E["_eventData"]) => void) | undefined): void
|
345
340
|
on_event(event: string, f: ((data: CustomInputEvent) => void) | undefined): void
|
346
|
-
on_event<T extends table>(event: CustomEventId<T>, f: ((data: T) => void) | undefined): void
|
347
341
|
/**
|
348
342
|
* Register a handler to run every nth-tick(s). When the game is on tick 0 it will trigger all registered handlers.
|
349
343
|
*
|
@@ -388,9 +382,8 @@ interface LuaBootstrap {
|
|
388
382
|
* @param event - The event identifier to get a handler for.
|
389
383
|
* @returns Reference to the function currently registered as the handler.
|
390
384
|
*/
|
391
|
-
get_event_handler<E extends
|
385
|
+
get_event_handler<E extends EventId<any>>(event: E): (data: E["_eventData"]) => void
|
392
386
|
get_event_handler(event: string): (data: CustomInputEvent) => void
|
393
|
-
get_event_handler<T extends table>(event: CustomEventId<T>): (data: T) => void
|
394
387
|
/**
|
395
388
|
* Gets the mod event order as a string.
|
396
389
|
*
|
@@ -427,7 +420,7 @@ interface LuaBootstrap {
|
|
427
420
|
* @param event - ID of the event to filter.
|
428
421
|
* @param filters - The filters or `nil` to clear them.
|
429
422
|
*/
|
430
|
-
set_event_filter<E extends
|
423
|
+
set_event_filter<E extends EventId<any, table>>(event: E, filters: E["_filter"][] | undefined): void
|
431
424
|
/**
|
432
425
|
* Gets the filters for the given event.
|
433
426
|
*
|
@@ -436,7 +429,7 @@ interface LuaBootstrap {
|
|
436
429
|
* @param event - ID of the event to get.
|
437
430
|
* @returns The filters or `nil` if none are defined.
|
438
431
|
*/
|
439
|
-
get_event_filter<E extends
|
432
|
+
get_event_filter<E extends EventId<any, table>>(event: E): E["_filter"][] | undefined
|
440
433
|
/**
|
441
434
|
* Raise an event. Only events generated with
|
442
435
|
* {@link LuaBootstrap.generate_event_name LuaBootstrap::generate_event_name} and the following can be raised:
|
@@ -464,8 +457,10 @@ interface LuaBootstrap {
|
|
464
457
|
* @param event - ID of the event to raise.
|
465
458
|
* @param data - Table with extra data that will be passed to the event handler.
|
466
459
|
*/
|
467
|
-
raise_event<
|
468
|
-
|
460
|
+
raise_event<E extends RaiseableEvents | CustomEventId<any>>(
|
461
|
+
event: E,
|
462
|
+
data: Omit<E["_eventData"], keyof EventData>
|
463
|
+
): void
|
469
464
|
/**
|
470
465
|
* Raises {@link OnConsoleChatEvent on_console_chat} with the given parameters.
|
471
466
|
*
|
@@ -6036,7 +6031,7 @@ interface LuaEquipment {
|
|
6036
6031
|
}
|
6037
6032
|
|
6038
6033
|
/**
|
6039
|
-
* Prototype of
|
6034
|
+
* Prototype of an equipment category.
|
6040
6035
|
*
|
6041
6036
|
* {@link https://lua-api.factorio.com/next/LuaEquipmentCategoryPrototype.html View documentation}
|
6042
6037
|
*
|
@@ -8543,6 +8538,15 @@ interface LuaGameScript {
|
|
8543
8538
|
* {@link https://lua-api.factorio.com/next/LuaGameScript.html#LuaGameScript.players View documentation}
|
8544
8539
|
*/
|
8545
8540
|
readonly players: LuaCustomTable<uint | string, LuaPlayer>
|
8541
|
+
/**
|
8542
|
+
* The currently active set of map settings. Even though this property is marked as read-only, the members of the
|
8543
|
+
* dictionary that is returned can be modified mid-game.
|
8544
|
+
*
|
8545
|
+
* **Note**: This does not contain difficulty settings, use
|
8546
|
+
* {@link LuaGameScript.difficulty_settings LuaGameScript::difficulty_settings} instead.
|
8547
|
+
*
|
8548
|
+
* {@link https://lua-api.factorio.com/next/LuaGameScript.html#LuaGameScript.map_settings View documentation}
|
8549
|
+
*/
|
8546
8550
|
readonly map_settings: MapSettings
|
8547
8551
|
/**
|
8548
8552
|
* The currently active set of difficulty settings. Even though this property is marked as read-only, the members of
|
@@ -9271,7 +9275,6 @@ interface ScrollPaneGuiSpec extends BaseGuiSpec {
|
|
9271
9275
|
| "always"
|
9272
9276
|
| "auto-and-reserve-space"
|
9273
9277
|
| "dont-show-but-allow-scrolling"
|
9274
|
-
| "auto"
|
9275
9278
|
/**
|
9276
9279
|
* Policy of the vertical scroll bar. Possible values are `"auto"`, `"never"`, `"always"`,
|
9277
9280
|
* `"auto-and-reserve-space"`, `"dont-show-but-allow-scrolling"`. Defaults to `"auto"`.
|
@@ -9282,7 +9285,6 @@ interface ScrollPaneGuiSpec extends BaseGuiSpec {
|
|
9282
9285
|
| "always"
|
9283
9286
|
| "auto-and-reserve-space"
|
9284
9287
|
| "dont-show-but-allow-scrolling"
|
9285
|
-
| "auto"
|
9286
9288
|
}
|
9287
9289
|
|
9288
9290
|
interface DropDownGuiSpec extends BaseGuiSpec {
|
@@ -9481,7 +9483,7 @@ interface SwitchGuiSpec extends BaseGuiSpec {
|
|
9481
9483
|
* Possible values are `"left"`, `"right"`, or `"none"`. If set to "none", `allow_none_state` must be `true`.
|
9482
9484
|
* Defaults to `"left"`.
|
9483
9485
|
*/
|
9484
|
-
readonly switch_state?: "left" | "right" | "none"
|
9486
|
+
readonly switch_state?: "left" | "right" | "none"
|
9485
9487
|
/** Whether the switch can be set to a middle state. Defaults to `false`. */
|
9486
9488
|
readonly allow_none_state?: boolean
|
9487
9489
|
readonly left_label_caption?: LocalisedString
|
@@ -10076,7 +10078,7 @@ interface ListBoxGuiElementMembers extends BaseGuiElement {
|
|
10076
10078
|
* @param scroll_mode - Where the item should be positioned in the scroll-pane. Must be either `"in-view"` or
|
10077
10079
|
* `"top-third"`. Defaults to `"in-view"`.
|
10078
10080
|
*/
|
10079
|
-
scroll_to_item(index: int, scroll_mode?: "in-view" | "top-third"
|
10081
|
+
scroll_to_item(index: int, scroll_mode?: "in-view" | "top-third"): void
|
10080
10082
|
}
|
10081
10083
|
|
10082
10084
|
type ListBoxGuiElement = ListBoxGuiElementMembers & GuiElementIndex
|
@@ -10132,7 +10134,7 @@ interface ScrollPaneGuiElementMembers extends BaseGuiElement {
|
|
10132
10134
|
* @param scroll_mode - Where the element should be positioned in the scroll-pane. Must be either `"in-view"` or
|
10133
10135
|
* `"top-third"`. Defaults to `"in-view"`.
|
10134
10136
|
*/
|
10135
|
-
scroll_to_element(element: LuaGuiElement, scroll_mode?: "in-view" | "top-third"
|
10137
|
+
scroll_to_element(element: LuaGuiElement, scroll_mode?: "in-view" | "top-third"): void
|
10136
10138
|
/**
|
10137
10139
|
* Policy of the horizontal scroll bar. Possible values are `"auto"`, `"never"`, `"always"`,
|
10138
10140
|
* `"auto-and-reserve-space"`, `"dont-show-but-allow-scrolling"`.
|
@@ -14440,12 +14442,20 @@ interface LuaPlayer extends LuaControl {
|
|
14440
14442
|
/**
|
14441
14443
|
* The display resolution for this player.
|
14442
14444
|
*
|
14445
|
+
* **Note**: During {@link OnPlayerCreatedEvent on_player_created}, this attribute will always return a resolution of
|
14446
|
+
* `{width=1920, height=1080}`. To get the actual resolution, listen to the
|
14447
|
+
* {@link OnPlayerDisplayResolutionChangedEvent on_player_display_resolution_changed} event raised shortly afterwards.
|
14448
|
+
*
|
14443
14449
|
* {@link https://lua-api.factorio.com/next/LuaPlayer.html#LuaPlayer.display_resolution View documentation}
|
14444
14450
|
*/
|
14445
14451
|
readonly display_resolution: DisplayResolution
|
14446
14452
|
/**
|
14447
14453
|
* The display scale for this player.
|
14448
14454
|
*
|
14455
|
+
* **Note**: During {@link OnPlayerCreatedEvent on_player_created}, this attribute will always return a scale of `1`.
|
14456
|
+
* To get the actual scale, listen to the {@link OnPlayerDisplayScaleChangedEvent on_player_display_scale_changed}
|
14457
|
+
* event raised shortly afterwards.
|
14458
|
+
*
|
14449
14459
|
* {@link https://lua-api.factorio.com/next/LuaPlayer.html#LuaPlayer.display_scale View documentation}
|
14450
14460
|
*/
|
14451
14461
|
readonly display_scale: double
|
@@ -17364,7 +17374,7 @@ interface ResourceSurfaceCreateEntity extends BaseSurfaceCreateEntity {
|
|
17364
17374
|
|
17365
17375
|
interface UndergroundBeltSurfaceCreateEntity extends BaseSurfaceCreateEntity {
|
17366
17376
|
/** `"output"` or `"input"`; default is `"input"`. */
|
17367
|
-
readonly type?: "output" | "input"
|
17377
|
+
readonly type?: "output" | "input"
|
17368
17378
|
}
|
17369
17379
|
|
17370
17380
|
interface ProgrammableSpeakerSurfaceCreateEntity extends BaseSurfaceCreateEntity {
|