typed-factorio 0.13.2 → 0.14.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/runtime/util.d.ts CHANGED
@@ -1,120 +1,120 @@
1
- // "util" is declared only as a module, even though it also modifies global variables
2
- // This is both because of limitations in `declare module`, and that modules are much friendlier to tooling.
3
-
4
- /** @noSelfInFile */
5
-
6
- /** @noResolution */
7
- declare module "util" {
8
- namespace table {
9
- function deepcopy<T>(table: T): T
10
-
11
- function compare<T>(tb1: T, tb2: T): boolean
12
- }
13
-
14
- function copy<T>(table: T): T
15
-
16
- function distance(position1: Position, position2: Position): number
17
-
18
- function positiontostr(position: Position): string
19
-
20
- function formattime(ticks: number): string
21
-
22
- /** Supports 'rrggbb', 'rgb', 'rrggbbaa', 'rgba', 'ww', 'w' */
23
- function color(hex: string): ColorTable
24
-
25
- function premul_color(color: Color): ColorTable
26
-
27
- function mix_color(c1: Color, c2: Color): ColorArray
28
-
29
- function multiply_color(c1: Color, n: number): ColorArray
30
-
31
- function moveposition(
32
- position: Position,
33
- direction: defines.direction.north | defines.direction.east | defines.direction.south | defines.direction.west,
34
- distance: number
35
- ): Position
36
- function moveposition(
37
- position: Position,
38
- direction: defines.direction, //todo: cardinal only
39
- distance: number
40
- ): Position | undefined
41
-
42
- function oppositedirection(direction: defines.direction): defines.direction
43
-
44
- /** Creates a new array where each element in `stripes` is duplicated `count` times */
45
- function multiplystripes<T>(count: number, stripes: T[]): T[]
46
-
47
- /** Gets tile position by pixel */
48
- function by_pixel(x: number, y: number): Position
49
-
50
- /** Gets tile position by pixel, hr */
51
- function by_pixel_hr(x: number, y: number): Position
52
-
53
- // omitted: foreach_sprite_definition
54
-
55
- function add_shift(a: PositionArray | undefined, b: PositionArray): PositionArray
56
- function add_shift(a: PositionArray, b: PositionArray | undefined): PositionArray
57
- function add_shift(a: PositionArray | undefined, b: PositionArray | undefined): PositionArray | undefined
58
-
59
- // omitted: add_shift_offset
60
-
61
- function mul_shift(shift: PositionArray, scale: number | undefined): PositionArray
62
- function mul_shift(shift: PositionArray | undefined, scale: number | undefined): PositionArray | undefined
63
-
64
- function format_number(amount: number, append_suffix?: boolean): string
65
-
66
- function increment(t: number[], index: number, v?: number): void
67
-
68
- // omitted: conditional_return
69
-
70
- /**
71
- * Recursively merges and/or deep-copies tables. Entries in later tables override entries in earlier ones, unless both
72
- * entries are themselves tables, in which case they are recursively merged. Non-merged tables are deep-copied, so
73
- * that the result is brand new.
74
- */
75
- function merge<T extends object>(tables: T[]): T
76
-
77
- function insert_safe(entity: LuaEntity | undefined, item_dict: Record<string, number> | undefined): void
78
-
79
- function remove_safe(entity: LuaEntity | undefined, item_dict: Record<string, number> | undefined): void
80
-
81
- function split_whitespace(string: string): string[]
82
-
83
- // omitted: split, string_starts_with. already TS functions for that
84
-
85
- // omitted: online_players. use game.connected_players
86
-
87
- function clamp(x: number, lower: number, upper: number): number
88
-
89
- // omitted: get_walkable_tile
90
-
91
- // omitted: combine_icons
92
- // omitted: technology_icons. Create an issue if you really want to see these
93
-
94
- function parse_energy(energy: string): number
95
-
96
- function product_amount(
97
- product: {
98
- probability: number
99
- } & (
100
- | {
101
- amount: number
102
- }
103
- | {
104
- amount_min: number
105
- amount_max: number
106
- }
107
- )
108
- ): number
109
-
110
- function empty_sprite(): object
111
-
112
- // omitted: draw_as_glow
113
- // omitted: remove_tile_references
114
-
115
- function remove_from_list<T>(list: T[], value: T): boolean
116
-
117
- function list_to_map<T extends keyof any>(list: T[]): Record<T, true>
118
- function list_to_map<T>(list: T[]): LuaTable<T, true>
119
- function list_to_map<T>(list: T): LuaTable<T[keyof T], true>
120
- }
1
+ // "util" is declared only as a module, even though it also modifies global variables
2
+ // This is both because of limitations in `declare module`, and that modules are much friendlier to tooling.
3
+
4
+ /** @noSelfInFile */
5
+
6
+ /** @noResolution */
7
+ declare module "util" {
8
+ namespace table {
9
+ function deepcopy<T>(table: T): T
10
+
11
+ function compare<T>(tb1: T, tb2: T): boolean
12
+ }
13
+
14
+ function copy<T>(table: T): T
15
+
16
+ function distance(position1: Position, position2: Position): number
17
+
18
+ function positiontostr(position: Position): string
19
+
20
+ function formattime(ticks: number): string
21
+
22
+ /** Supports 'rrggbb', 'rgb', 'rrggbbaa', 'rgba', 'ww', 'w' */
23
+ function color(hex: string): ColorTable
24
+
25
+ function premul_color(color: Color): ColorTable
26
+
27
+ function mix_color(c1: Color, c2: Color): ColorArray
28
+
29
+ function multiply_color(c1: Color, n: number): ColorArray
30
+
31
+ function moveposition(
32
+ position: Position,
33
+ direction: defines.direction.north | defines.direction.east | defines.direction.south | defines.direction.west,
34
+ distance: number
35
+ ): Position
36
+ function moveposition(
37
+ position: Position,
38
+ direction: defines.direction, //todo: cardinal only
39
+ distance: number
40
+ ): Position | undefined
41
+
42
+ function oppositedirection(direction: defines.direction): defines.direction
43
+
44
+ /** Creates a new array where each element in `stripes` is duplicated `count` times */
45
+ function multiplystripes<T>(count: number, stripes: T[]): T[]
46
+
47
+ /** Gets tile position by pixel */
48
+ function by_pixel(x: number, y: number): Position
49
+
50
+ /** Gets tile position by pixel, hr */
51
+ function by_pixel_hr(x: number, y: number): Position
52
+
53
+ // omitted: foreach_sprite_definition
54
+
55
+ function add_shift(a: PositionArray | undefined, b: PositionArray): PositionArray
56
+ function add_shift(a: PositionArray, b: PositionArray | undefined): PositionArray
57
+ function add_shift(a: PositionArray | undefined, b: PositionArray | undefined): PositionArray | undefined
58
+
59
+ // omitted: add_shift_offset
60
+
61
+ function mul_shift(shift: PositionArray, scale: number | undefined): PositionArray
62
+ function mul_shift(shift: PositionArray | undefined, scale: number | undefined): PositionArray | undefined
63
+
64
+ function format_number(amount: number, append_suffix?: boolean): string
65
+
66
+ function increment(t: number[], index: number, v?: number): void
67
+
68
+ // omitted: conditional_return
69
+
70
+ /**
71
+ * Recursively merges and/or deep-copies tables. Entries in later tables override entries in earlier ones, unless both
72
+ * entries are themselves tables, in which case they are recursively merged. Non-merged tables are deep-copied, so
73
+ * that the result is brand new.
74
+ */
75
+ function merge<T extends object>(tables: T[]): T
76
+
77
+ function insert_safe(entity: LuaEntity | undefined, item_dict: Record<string, number> | undefined): void
78
+
79
+ function remove_safe(entity: LuaEntity | undefined, item_dict: Record<string, number> | undefined): void
80
+
81
+ function split_whitespace(string: string): string[]
82
+
83
+ // omitted: split, string_starts_with. already TS functions for that
84
+
85
+ // omitted: online_players. use game.connected_players
86
+
87
+ function clamp(x: number, lower: number, upper: number): number
88
+
89
+ // omitted: get_walkable_tile
90
+
91
+ // omitted: combine_icons
92
+ // omitted: technology_icons. Create an issue if you really want to see these
93
+
94
+ function parse_energy(energy: string): number
95
+
96
+ function product_amount(
97
+ product: {
98
+ probability: number
99
+ } & (
100
+ | {
101
+ amount: number
102
+ }
103
+ | {
104
+ amount_min: number
105
+ amount_max: number
106
+ }
107
+ )
108
+ ): number
109
+
110
+ function empty_sprite(): object
111
+
112
+ // omitted: draw_as_glow
113
+ // omitted: remove_tile_references
114
+
115
+ function remove_from_list<T>(list: T[], value: T): boolean
116
+
117
+ function list_to_map<T extends keyof any>(list: T[]): Record<T, true>
118
+ function list_to_map<T>(list: T[]): LuaTable<T, true>
119
+ function list_to_map<T>(list: T): LuaTable<T[keyof T], true>
120
+ }
@@ -1,120 +1,120 @@
1
- // Based off of https://wiki.factorio.com/Tutorial:Mod_settings
2
-
3
- export type SettingType = "bool-setting" | "int-setting" | "double-setting" | "string-setting"
4
-
5
- export interface BaseSettingDefinition {
6
- type: SettingType
7
- /**
8
- * The name of the settings prototype should be unique to avoid mod conflicts since the mod settings are global across
9
- * all mods. Because of that it is recommended to prefix mod settings with your mod name,
10
- */
11
- name: string
12
- localized_name?: LocalisedString
13
- localized_description?: LocalisedString
14
-
15
- /**
16
- * The order property can be used to change how the mod settings are ordered in the settings gui. Mod settings are sorted
17
- *
18
- * - First by mod
19
- * - Then by the setting "order" string
20
- * - Then finally by the setting name.
21
- */
22
- order?: string
23
- /**
24
- * The hidden property can be used to hide mod settings from GUIs, so that they cannot be seen or changed by players.
25
- * However, other mods can still access hidden settings. {@link https://forums.factorio.com/83316}
26
- */
27
- hidden?: boolean
28
- /**
29
- * There are the overall kinds of settings:
30
- *
31
- * - **startup**: This kind of setting is available in the prototype stage, and can not be changed runtime. They have to
32
- * be set to the same values for all players on a server.
33
- * - **runtime-global**: This kind of setting is global to an entire save game and can be changed runtime. On servers,
34
- * only admins can change these settings.
35
- * - **runtime-per-user**: This kind of setting is only available runtime in the control.lua stage and each player has
36
- * their own instance of this setting. When a player joins a server their local setting of "keep mod settings per
37
- * save" determines if the local settings they have set are synced to the loaded save or if the save's settings are used.
38
- *
39
- * This "setting_type" also determines in which tab the setting is showed in the mod settings menu.
40
- */
41
-
42
- setting_type: "startup" | "runtime-global" | "runtime-per-user"
43
- }
44
- /** A true/false checkbox */
45
- export interface BoolSettingDefinition extends BaseSettingDefinition {
46
- type: "bool-setting"
47
- /** Defines the default value of the setting, in this case whether the checkbox is checked or not. */
48
- default_value: boolean
49
- /**
50
- * Only loaded if `hidden = true`. This forces the setting to be of this value. This can be useful for mod
51
- * compatibility. {@link https://forums.factorio.com/viewtopic.php?p=531322#p531322}
52
- */
53
- forced_value?: boolean
54
- }
55
- /** A signed 64 bit integer textfield (or selection dropdown) */
56
- export interface IntSettingDefinition extends BaseSettingDefinition {
57
- type: "int-setting"
58
- /** Defines the default value of the setting. */
59
- default_value: number
60
- /** Defines the lowest possible number. */
61
- minimum_value?: number
62
- /** Defines the highest possible number. */
63
- maximum_value?: number
64
- /**
65
- * Makes it possible to force the player to choose between the defined numbers, creates a dropdown instead of a
66
- * textfield. If only one allowed value is given, the settings is forced to be of that value.
67
- */
68
- allowed_values?: number[]
69
- }
70
- /** A double precision floating point textfield (or selection dropdown) */
71
- export interface DoubleSettingDefinition extends BaseSettingDefinition {
72
- type: "double-setting"
73
- /** Defines the default value of the setting. */
74
- default_value: number
75
- /** Defines the lowest possible number. */
76
- minimum_value?: number
77
- /** Defines the highest possible number. */
78
- maximum_value?: number
79
- /**
80
- * Makes it possible to force the player to choose between the defined numbers, creates a dropdown instead of a
81
- * textfield. If only one allowed value is given, the settings is forced to be of that value.
82
- */
83
- allowed_values?: number[]
84
- }
85
- /** A string textfield (or selection dropdown) */
86
- export interface StringSettingDefinition extends BaseSettingDefinition {
87
- type: "string-setting"
88
- /** Defines the default value of the setting. */
89
- default_value: string
90
- /** Defines whether it's possible for the user to set the textfield to empty and apply the setting. */
91
- allow_blank?: boolean
92
- /** Whether values that are input by the user should have whitespace removed from both ends of the string. */
93
- auto_trim?: boolean
94
- /**
95
- * Makes it possible to force the player to choose between the defined strings, creates a dropdown instead of a
96
- * textfield. The strings in the dropdown can be localized (translated) and can have a tooltip, see below. If only one
97
- * allowed value is given, the settings is forced to be of that value.
98
- */
99
- allowed_values?: string[]
100
- }
101
- /** Setting definitions. See {@link https://wiki.factorio.com/Tutorial:Mod_settings} for more info. */
102
- export type SettingDefinition =
103
- | BoolSettingDefinition
104
- | IntSettingDefinition
105
- | DoubleSettingDefinition
106
- | StringSettingDefinition
107
-
108
- export interface Data {
109
- readonly raw: {
110
- [T in SettingDefinition["type"]]: Record<string, Extract<SettingDefinition, { type: T }>>
111
- }
112
- /**
113
- * The `data` table expects a specific format for each item in the table. Missing properties will either fall back to
114
- * default values or give an error indicating what's missing. Extra properties that the game isn't looking for are
115
- * simply ignored.
116
- */
117
- extend(prototypes: SettingDefinition[]): void
118
- }
119
- /** A mapping of mod names to mod version for all enabled mods. */
120
- export type Mods = Record<string, string>
1
+ // Based off of https://wiki.factorio.com/Tutorial:Mod_settings
2
+
3
+ export type SettingType = "bool-setting" | "int-setting" | "double-setting" | "string-setting"
4
+
5
+ export interface BaseSettingDefinition {
6
+ type: SettingType
7
+ /**
8
+ * The name of the settings prototype should be unique to avoid mod conflicts since the mod settings are global across
9
+ * all mods. Because of that it is recommended to prefix mod settings with your mod name,
10
+ */
11
+ name: string
12
+ localized_name?: LocalisedString
13
+ localized_description?: LocalisedString
14
+
15
+ /**
16
+ * The order property can be used to change how the mod settings are ordered in the settings gui. Mod settings are sorted
17
+ *
18
+ * - First by mod
19
+ * - Then by the setting "order" string
20
+ * - Then finally by the setting name.
21
+ */
22
+ order?: string
23
+ /**
24
+ * The hidden property can be used to hide mod settings from GUIs, so that they cannot be seen or changed by players.
25
+ * However, other mods can still access hidden settings. {@link https://forums.factorio.com/83316}
26
+ */
27
+ hidden?: boolean
28
+ /**
29
+ * There are the overall kinds of settings:
30
+ *
31
+ * - **startup**: This kind of setting is available in the prototype stage, and can not be changed runtime. They have to
32
+ * be set to the same values for all players on a server.
33
+ * - **runtime-global**: This kind of setting is global to an entire save game and can be changed runtime. On servers,
34
+ * only admins can change these settings.
35
+ * - **runtime-per-user**: This kind of setting is only available runtime in the control.lua stage and each player has
36
+ * their own instance of this setting. When a player joins a server their local setting of "keep mod settings per
37
+ * save" determines if the local settings they have set are synced to the loaded save or if the save's settings are used.
38
+ *
39
+ * This "setting_type" also determines in which tab the setting is showed in the mod settings menu.
40
+ */
41
+
42
+ setting_type: "startup" | "runtime-global" | "runtime-per-user"
43
+ }
44
+ /** A true/false checkbox */
45
+ export interface BoolSettingDefinition extends BaseSettingDefinition {
46
+ type: "bool-setting"
47
+ /** Defines the default value of the setting, in this case whether the checkbox is checked or not. */
48
+ default_value: boolean
49
+ /**
50
+ * Only loaded if `hidden = true`. This forces the setting to be of this value. This can be useful for mod
51
+ * compatibility. {@link https://forums.factorio.com/viewtopic.php?p=531322#p531322}
52
+ */
53
+ forced_value?: boolean
54
+ }
55
+ /** A signed 64 bit integer textfield (or selection dropdown) */
56
+ export interface IntSettingDefinition extends BaseSettingDefinition {
57
+ type: "int-setting"
58
+ /** Defines the default value of the setting. */
59
+ default_value: number
60
+ /** Defines the lowest possible number. */
61
+ minimum_value?: number
62
+ /** Defines the highest possible number. */
63
+ maximum_value?: number
64
+ /**
65
+ * Makes it possible to force the player to choose between the defined numbers, creates a dropdown instead of a
66
+ * textfield. If only one allowed value is given, the settings is forced to be of that value.
67
+ */
68
+ allowed_values?: number[]
69
+ }
70
+ /** A double precision floating point textfield (or selection dropdown) */
71
+ export interface DoubleSettingDefinition extends BaseSettingDefinition {
72
+ type: "double-setting"
73
+ /** Defines the default value of the setting. */
74
+ default_value: number
75
+ /** Defines the lowest possible number. */
76
+ minimum_value?: number
77
+ /** Defines the highest possible number. */
78
+ maximum_value?: number
79
+ /**
80
+ * Makes it possible to force the player to choose between the defined numbers, creates a dropdown instead of a
81
+ * textfield. If only one allowed value is given, the settings is forced to be of that value.
82
+ */
83
+ allowed_values?: number[]
84
+ }
85
+ /** A string textfield (or selection dropdown) */
86
+ export interface StringSettingDefinition extends BaseSettingDefinition {
87
+ type: "string-setting"
88
+ /** Defines the default value of the setting. */
89
+ default_value: string
90
+ /** Defines whether it's possible for the user to set the textfield to empty and apply the setting. */
91
+ allow_blank?: boolean
92
+ /** Whether values that are input by the user should have whitespace removed from both ends of the string. */
93
+ auto_trim?: boolean
94
+ /**
95
+ * Makes it possible to force the player to choose between the defined strings, creates a dropdown instead of a
96
+ * textfield. The strings in the dropdown can be localized (translated) and can have a tooltip, see below. If only one
97
+ * allowed value is given, the settings is forced to be of that value.
98
+ */
99
+ allowed_values?: string[]
100
+ }
101
+ /** Setting definitions. See {@link https://wiki.factorio.com/Tutorial:Mod_settings} for more info. */
102
+ export type SettingDefinition =
103
+ | BoolSettingDefinition
104
+ | IntSettingDefinition
105
+ | DoubleSettingDefinition
106
+ | StringSettingDefinition
107
+
108
+ export interface Data {
109
+ readonly raw: {
110
+ [T in SettingDefinition["type"]]: Record<string, Extract<SettingDefinition, { type: T }>>
111
+ }
112
+ /**
113
+ * The `data` table expects a specific format for each item in the table. Missing properties will either fall back to
114
+ * default values or give an error indicating what's missing. Extra properties that the game isn't looking for are
115
+ * simply ignored.
116
+ */
117
+ extend(prototypes: SettingDefinition[]): void
118
+ }
119
+ /** A mapping of mod names to mod version for all enabled mods. */
120
+ export type Mods = Record<string, string>