factorio-types 1.1.0 → 1.2.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/index.d.ts CHANGED
@@ -3,13 +3,15 @@
3
3
  // Generated from JSON source https://lua-api.factorio.com/latest/runtime-api.json and https://lua-api.factorio.com/latest/prototype-api.json
4
4
  // Definition source https://github.com/sguest/factorio-types
5
5
 
6
- /// <reference path="./dist/core.d.ts" />
6
+ /// <reference path="./src/core.d.ts" />
7
+ /// <reference path="./src/settings.d.ts" />
8
+ /// <reference path="./src/serpent.d.ts" />
9
+ /// <reference path="./src/lualib/noise.d.ts" />
7
10
  /// <reference path="./dist/global.d.ts" />
8
11
  /// <reference path="./dist/classes.d.ts" />
9
12
  /// <reference path="./dist/concepts.d.ts" />
10
13
  /// <reference path="./dist/defines.d.ts" />
11
14
  /// <reference path="./dist/events.d.ts" />
12
- /// <reference path="./dist/serpent.d.ts" />
13
15
  /// <reference path="./dist/prototypes.d.ts" />
14
16
  /// <reference path="./dist/types.d.ts" />
15
17
  /// <reference types="lua-types/jit" />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "factorio-types",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Typescript declarations for the Factorio mod API",
5
5
  "main": "index.d.ts",
6
6
  "repository": "https://github.com/sguest/factorio-types.git",
@@ -8,13 +8,11 @@
8
8
  "license": "MIT",
9
9
  "scripts": {
10
10
  "validate": "tsc -p tsconfig.json",
11
- "copy-source": "cpy src/*.d.ts dist",
12
- "build": "ts-node json_parser/parser.ts && yarn run copy-source",
13
- "rebuild": "ts-node json_parser/parser.ts -clean && yarn run copy-source"
11
+ "build": "ts-node json_parser/parser.ts",
12
+ "rebuild": "ts-node json_parser/parser.ts -clean"
14
13
  },
15
14
  "devDependencies": {
16
15
  "@types/node": "^15.12.2",
17
- "cpy-cli": "^3.1.1",
18
16
  "node-html-parser": "^1.1.16",
19
17
  "ts-node": "^10.0.0",
20
18
  "typescript": "^5.4.2",
@@ -23,13 +21,14 @@
23
21
  "files": [
24
22
  "index.d.ts",
25
23
  "tsconfig.base.json",
24
+ "src/**/*.d.ts",
26
25
  "dist/**/*.d.ts"
27
26
  ],
28
- "factorioVersion": "1.1.107",
27
+ "factorioVersion": "1.1.108",
29
28
  "dependencies": {
30
29
  "lua-types": "^2.13.1"
31
30
  },
32
31
  "peerDependencies": {
33
32
  "typescript-to-lua": "^1.25.1"
34
33
  }
35
- }
34
+ }
@@ -5,6 +5,7 @@
5
5
 
6
6
  declare namespace table {
7
7
  function deepcopy<T>(this: void, value: T): T;
8
+ function compare(this: void, table1: object | [], table2: object | []): boolean;
8
9
  }
9
10
 
10
11
  declare const data: {
@@ -29,7 +30,46 @@ declare const serpent: Serpent;
29
30
  // can eventually fix these on a per-case basis
30
31
  type Table = any;
31
32
 
32
- // https://lua-api.factorio.com/latest/types/DataExtendMethod.html
33
+ type uint = number;
34
+
35
+ /*
36
+ * The data.extend method. It's the primary way to add prototypes to the data table.
37
+ *
38
+ * The method has two positional function parameters:
39
+ *
40
+ * - `self` :: [Data](prototype:Data): Usually provided by calling `data:extend(otherdata)`, which is syntax sugar for `data.extend(data, otherdata)`.
41
+ *
42
+ * - `otherdata` :: array[[AnyPrototype](prototype:AnyPrototype)]: A continuous array of non-abstract prototypes.",
43
+ * @example
44
+ * ```
45
+ * data:extend({\n {\n type = \"item\",
46
+ * name = \"a-thing\",
47
+ * icon = \"__base__/graphics/icons/coal.png\",
48
+ * icon_size = 64,
49
+ * stack_size = 2
50
+ * }
51
+ * })
52
+ * ```,
53
+ * @example
54
+ * ```
55
+ * local recipe_cat =
56
+ * {
57
+ * type = \"recipe-category\",
58
+ * name = \"my-category\"
59
+ * }
60
+ * local assembler =
61
+ * {
62
+ * type = \"assembling-machine\",
63
+ * name = \"cool-assembler\",
64
+ * energy_usage = \"30kW\",
65
+ * energy_source = {type = \"void\"},
66
+ * crafting_speed = 1,
67
+ * crafting_categories = {\"crafting\"}
68
+ * }
69
+ *
70
+ * data:extend({recipe_cat, assembler})
71
+ * ```
72
+ */
33
73
  type DataExtendMethod = (data: prototype.Data, ...otherData: any[]) => void;
34
74
 
35
75
  // The docs and json definition make reference to these types but have no information as to what they are
@@ -0,0 +1,194 @@
1
+ /** @noSelfInFile */
2
+ /** @noResolution */
3
+ declare module "noise" {
4
+ interface tileProps {
5
+ x: prototype.NoiseVariable,
6
+ y: prototype.NoiseVariable,
7
+ distance: prototype.NoiseExpression,
8
+ tier: prototype.NoiseExpression,
9
+ }
10
+
11
+ interface mapProps {
12
+ seed: prototype.NoiseVariable
13
+ width: prototype.NoiseVariable
14
+ height: prototype.NoiseVariable
15
+ starting_area_radius: prototype.NoiseVariable
16
+ segmentation_multiplier: prototype.NoiseVariable
17
+ terrace_elevation_offset: prototype.NoiseVariable
18
+ terrace_elevation_interval: prototype.NoiseVariable
19
+ /**
20
+ * Add this to your (presumably centered around 0) elevation to correct water coverage
21
+ */
22
+ wlc_elevation_offset: prototype.NoiseVariable
23
+ /**
24
+ * minimum elevation to be applied to areas outside the starting lake *after* the offset
25
+ */
26
+ wlc_elevation_minimum: prototype.NoiseVariable
27
+ water_level: prototype.NoiseVariable
28
+ finite_water_level: prototype.NoiseVariable
29
+ }
30
+
31
+ type NoiseOperand = prototype.NoiseExpression | number;
32
+
33
+ /**
34
+ * Emitted as overloaded operator - `noise.add(x, y)` becomes `x + y`
35
+ */
36
+ const add: LuaAddition<NoiseOperand, NoiseOperand, prototype.NoiseFunctionAdd>;
37
+ /**
38
+ * Emitted as overloaded operator - `noise.sub(x, y)` becomes `x - y`
39
+ */
40
+ const sub: LuaSubtraction<NoiseOperand, NoiseOperand, prototype.NoiseFunctionSubtract>;
41
+ /**
42
+ * Emitted as overloaded operator - `noise.mul(x, y)` becomes `x * y`
43
+ */
44
+ const mul: LuaMultiplication<NoiseOperand, NoiseOperand, prototype.NoiseFunctionMultiply>;
45
+ /**
46
+ * Emitted as overloaded operator - `noise.div(x, y)` becomes `x / y`
47
+ */
48
+ const div: LuaDivision<NoiseOperand, NoiseOperand, prototype.NoiseFunctionDivide>;
49
+ /**
50
+ * Emitted as overloaded operator - `noise.unm(x)` becomes `-x`
51
+ */
52
+ const unm: LuaNegation<NoiseOperand, prototype.NoiseFunctionSubtract>;
53
+ /**
54
+ * Emitted as overloaded operator - `noise.pow(x, y)` becomes `x ^ y`
55
+ */
56
+ const pow: LuaPower<NoiseOperand, NoiseOperand, prototype.NoiseFunctionExponentiate>;
57
+
58
+ type NoiseNumberLike = prototype.NoiseNumber | number;
59
+
60
+ /**
61
+ * @customName var
62
+ * @noSelf
63
+ * This is named "var" in lua and will compile as such thanks to annotations. However, var is a reserved word in typescript
64
+ */
65
+ function var_get(name: prototype.NoiseVariable['variable_name']): prototype.NoiseVariable
66
+
67
+ /**
68
+ *
69
+ * @param level number of levels up *from the caller* we want to take our location from, defaulting to 1.
70
+ */
71
+ function csloc(level: number): { filename: string, line_number: number }
72
+
73
+ /**
74
+ * 'to noise expression'
75
+ * turns simple values into noise expressions and adds a metatable so you can do arithmetic operations on noise expresssions
76
+ */
77
+ function to_noise_expression(v: any, sloc: string): prototype.NoiseExpression
78
+
79
+ /**
80
+ * Call this to...define a noise function using lua syntax.
81
+ * Your lua function will be passed x, y, tile properties, and map properties.
82
+ * The arguments are 'noise expression' objects to which arithmetic operations may be applied.
83
+ */
84
+ function define_noise_function(callback: (x: prototype.NoiseVariable, y: prototype.NoiseVariable, tileProps: tileProps, mapProps: mapProps) => void): prototype.NoiseExpression
85
+
86
+ function clamp(v: NoiseNumberLike, min: NoiseNumberLike, max: NoiseNumberLike, sloc: string): prototype.NoiseFunctionClamp
87
+
88
+ function compile_time_log(...args: NoiseNumberLike[]): prototype.NoiseFunctionCompileTimeLog
89
+
90
+ /**
91
+ * Useful for preventing tail-calls
92
+ * because we want to not lose part of the stacktrace
93
+ * in order that csloc() gives the desired result
94
+ */
95
+ function ident(x: prototype.NoiseExpression): prototype.NoiseExpression
96
+
97
+ function min(...args: NoiseNumberLike[]): prototype.NoiseNumber
98
+
99
+ function max(...args: NoiseNumberLike[]): prototype.NoiseNumber
100
+
101
+ function ridge(v: NoiseNumberLike, min: NoiseNumberLike, max: NoiseNumberLike, sloc: string): prototype.NoiseFunctionRidge
102
+
103
+ function terrace(v: NoiseNumberLike, offset: prototype.ConstantNoiseNumber, width: prototype.ConstantNoiseNumber, strength: NoiseNumberLike): prototype.NoiseFunctionTerrace
104
+
105
+ /**
106
+ * Terrace at elevations at which the game will place cliffs
107
+ * if change in elevation is steep enough.
108
+ * strength = 0: no-op; strength = 1: vertical slopes between terrace elevations
109
+ */
110
+ function terrace_for_cliffs(
111
+ v: NoiseNumberLike,
112
+ strength: NoiseNumberLike,
113
+ map: {
114
+ terrace_elevation_offset: prototype.NoiseVariable,
115
+ terrace_elevation_interval: prototype.NoiseVariable
116
+ }): prototype.NoiseExpression
117
+
118
+ function make_array(list: any[]): prototype.NoiseExpression
119
+
120
+ function make_point_list(list: any[]): prototype.NoiseArrayConstruction
121
+
122
+ function distance_from(
123
+ maximum_distance: prototype.ConstantNoiseNumber | undefined,
124
+ points: prototype.NoiseArrayConstruction,
125
+ x: NoiseNumberLike,
126
+ y: NoiseNumberLike): prototype.NoiseFunctionDistanceFromNearestPoint
127
+
128
+ function get_control_setting(name: string): prototype.NoiseExpression
129
+
130
+ function absolute_value(val: NoiseNumberLike): prototype.NoiseFunctionAbsoluteValue
131
+
132
+ function autoplace_probabililty(autoplace: prototype.NoiseLiteralObject): prototype.NoiseFunctionAutoplaceProbability
133
+
134
+ function autoplace_richness(autoplace: prototype.NoiseLiteralObject): prototype.NoiseFunctionAutoplaceRichness
135
+
136
+ function fraction(num: NoiseNumberLike, den: NoiseNumberLike): prototype.NoiseNumber
137
+
138
+ function function_application(name: string, arguments: prototype.NoiseExpression[], sloc: string): prototype.NoiseFunctionApplication
139
+
140
+ function if_else_chain(...arugments: prototype.NoiseExpression[]): prototype.NoiseIfElseChain
141
+
142
+ function literal_expression(x: prototype.NoiseExpression): prototype.NoiseLiteralExpression
143
+
144
+ function literal_object(val: prototype.AutoplaceSpecification): prototype.NoiseLiteralObject
145
+
146
+ function literal_string(str: string, sloc: string): prototype.NoiseLiteralString
147
+
148
+ function noise_layer_name_to_id(name: prototype.NoiseLiteralString): prototype.NoiseFunctionNoiseLayerNameToID
149
+
150
+ function random(amplitude: prototype.ConstantNoiseNumber): prototype.NoiseFunctionRandomPenalty
151
+
152
+ function random_between(lower: NoiseNumberLike, upper: NoiseNumberLike): prototype.NoiseFunctionRandomPenalty
153
+
154
+ function random_penalty(source: NoiseNumberLike, random_penalty_amplitude: prototype.ConstantNoiseNumber, opts: prototype.RandomPenaltyArguments): prototype.NoiseFunctionRandomPenalty
155
+
156
+ function delimit_procedure(expression: prototype.NoiseExpression): prototype.NoiseProcedureDelimiter
157
+
158
+ function log2(power: NoiseNumberLike): prototype.NoiseFunctionLog2
159
+
160
+ function fmod(lhs: NoiseNumberLike, rhs: NoiseNumberLike): prototype.NoiseFunctionModulo
161
+
162
+ function floor(value: NoiseNumberLike): prototype.NoiseFunctionFloor
163
+
164
+ function ceil(value: NoiseNumberLike): prototype.NoiseFunctionCeil
165
+
166
+ function band(...arguments: NoiseNumberLike[]): prototype.NoiseFunctionBitwiseAnd
167
+
168
+ function bor(...arguments: NoiseNumberLike[]): prototype.NoiseFunctionBitwiseOr
169
+
170
+ function bxor(...arguments: NoiseNumberLike[]): prototype.NoiseFunctionBitwiseXor
171
+
172
+ function bnot(...arguments: NoiseNumberLike[]): prototype.NoiseFunctionBitwiseNot
173
+
174
+ function sin(value: NoiseNumberLike): prototype.NoiseFunctionSin
175
+
176
+ function cos(value: NoiseNumberLike): prototype.NoiseFunctionCos
177
+
178
+ function atan2(value: NoiseNumberLike): prototype.NoiseFunctionAtan2
179
+
180
+ /**
181
+ * This results in a number that is '0' for 'false' or '1' for 'true'.
182
+ */
183
+ function less_than(lhs: NoiseNumberLike, rhs: NoiseNumberLike): prototype.NoiseFunctionLessThan
184
+
185
+ /**
186
+ * This results in a number that is '0' for 'false' or '1' for 'true'.
187
+ */
188
+ function less_or_equal(lhs: NoiseNumberLike, rhs: NoiseNumberLike): prototype.NoiseFunctionLessOrEqual
189
+
190
+ /**
191
+ * This results in a number that is '0' for 'false' or '1' for 'true'.
192
+ */
193
+ function equals(lhs: NoiseNumberLike, rhs: NoiseNumberLike): prototype.NoiseFunctionEquals
194
+ }
@@ -0,0 +1,133 @@
1
+ declare namespace settings {
2
+ type settingType =
3
+ /** This kind of seting is available in the prototype stage, and cannot be changed runtime. They have to be set to the same values for all players on a server.*/
4
+ 'startup' |
5
+ /** This kind of setting is global to an entire save game and can be changed runtime. On servers, only admins can change these settings. */
6
+ 'runtime-global' |
7
+ /** This kind of setting is only available runtime in the control.lua stage and each player has their own intance of this setting. When a player joins a server their local setting of "keep mod settings per save" determines if the local settings they have set are synced to the loaded save or if the save's settings are used. */
8
+ 'runtime-per-user'
9
+
10
+ /**
11
+ * The base type for all settings. Defines common values
12
+ */
13
+ interface SettingBase extends prototype.PrototypeBase {
14
+ /**
15
+ * The hidden property can be used to hide mod settings from GUIs, so that they cannot be seen or changed by players.
16
+ * However, other mods can still access hidden settings.
17
+ */
18
+ hidden?: boolean
19
+ /**
20
+ * Determines the stage of game at which the setting is available and which tab it is shown in the mod settings menu.
21
+ */
22
+ setting_type: settingType
23
+ }
24
+
25
+ /**
26
+ * A true/false checkbox
27
+ */
28
+ interface BoolSetting extends SettingBase {
29
+ /**
30
+ * Defines the default value of the setting, in this case whether the checkbox is checked or not.
31
+ */
32
+ default_value: boolean
33
+ /**
34
+ * Only loadoed if `hidden = true`. This forces the setting to be of this value. This can be useful for mod compatibility.
35
+ */
36
+ forced_value?: boolean
37
+ }
38
+
39
+ /**
40
+ * A signed 64 bit integer textfield (or selection dropdown)
41
+ */
42
+ interface IntSetting extends SettingBase {
43
+ /**
44
+ * Defines the value of the setting.
45
+ */
46
+ default_value: number
47
+
48
+ /**
49
+ * Defines the lowest possible number.
50
+ */
51
+ minimum_value?: number
52
+
53
+ /**
54
+ * Defines the highest possible number.
55
+ */
56
+ maximum_value?: number
57
+
58
+ /**
59
+ * Makes it possible to force the player to choose between the defined numbers, creates a dropdown instead of a textfield.
60
+ * If only one allowed value is given, the setting is forced to be of that value.
61
+ */
62
+ allowed_values?: number[]
63
+ }
64
+
65
+ /**
66
+ * A double precision floating point textfield (or selection dropdown)
67
+ */
68
+ interface DoubleSetting extends SettingBase {
69
+ /**
70
+ * Defines the value of the setting.
71
+ */
72
+ default_value: number
73
+
74
+ /**
75
+ * Defines the lowest possible number.
76
+ */
77
+ minimum_value?: number
78
+
79
+ /**
80
+ * Defines the highest possible number.
81
+ */
82
+ maximum_value?: number
83
+
84
+ /**
85
+ * Makes it possible to force the player to choose between the defined numbers, creates a dropdown instead of a textfield.
86
+ * If only one allowed value is given, the setting is forced to be of that value.
87
+ */
88
+ allowed_values?: number[]
89
+ }
90
+
91
+ /**
92
+ * A string textfield (or selection dropdown)
93
+ */
94
+ interface StringSetting extends SettingBase {
95
+ /**
96
+ * Defines the default value of the setting.
97
+ */
98
+ default_value: string
99
+
100
+ /**
101
+ * Defines whether it's possible for the user to set the textfield to empty and apply the setting.
102
+ */
103
+ allow_blank?: boolean
104
+
105
+ /**
106
+ * Whether values that are input by the user should have whitespace removed from both ends of the string.
107
+ */
108
+ auto_trim?: boolean
109
+
110
+ /**
111
+ * Makes it possible to force the player to choose between the defined strings, creates a dropdown instead of a textfield. The strings in the dropdown can be localized (translated) and can have a tooltip
112
+ * If only one allowed value is given, the setting is forced to be of that value.
113
+ */
114
+ allowed_values?: string[]
115
+ }
116
+
117
+ /**
118
+ * A color picker (sliders), with whole number textfields. Includes alpha.
119
+ */
120
+ interface ColorSetting extends SettingBase {
121
+ /**
122
+ * Defines the default value of the setting.
123
+ */
124
+ default_value: prototype.Color
125
+ }
126
+
127
+ type dataExtendType =
128
+ ({ type: 'bool-setting' } & BoolSetting) |
129
+ ({ type: 'int-setting' } & IntSetting) |
130
+ ({ type: 'double-setting' } & DoubleSetting) |
131
+ ({ type: 'string-setting' } & StringSetting) |
132
+ ({ type: 'color-setting' } & ColorSetting)
133
+ }
@@ -4,7 +4,7 @@
4
4
  "target": "esnext",
5
5
  "lib": ["esnext"],
6
6
  "strict": true,
7
- "types": ["@typescript-to-lua/language-extensions"],
7
+ "types": ["factorio-types", "@typescript-to-lua/language-extensions"],
8
8
  "strictNullChecks": false
9
9
  },
10
10
  "tstl": {
File without changes