factorio-types 1.2.4 → 1.2.6
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 +15 -60
- package/dist/classes.d.ts +4969 -3485
- package/dist/concepts.d.ts +2267 -643
- package/dist/datacollection.d.ts +210 -30
- package/dist/defines.d.ts +1244 -738
- package/dist/events.d.ts +509 -105
- package/dist/global.d.ts +10 -2
- package/dist/prototypes.d.ts +3304 -1984
- package/dist/types.d.ts +5707 -3063
- package/index.d.ts +0 -1
- package/package.json +2 -2
- package/src/lualib/noise.d.ts +0 -194
package/README.md
CHANGED
|
@@ -43,78 +43,33 @@ Note that since typescript has a single `number` type, the compiler will **not**
|
|
|
43
43
|
|
|
44
44
|
Various types in the Factorio API are implemented as lua tables, specifically those with a `complex_type` of `dictionary` or `LuaCustomTable`. These types have intentionally been implemented as [Record](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type) types instead of TypescriptToLua's [Lua Table Type](https://typescripttolua.github.io/docs/advanced/language-extensions/#lua-table-types) because `LuaTable`s cannot be instantiated with `{ key1: 'value1', key2: 'value2' }` initializer syntax, and instead repeated calls to `set()` would be required, making initialization of such objects considerably more verbose.
|
|
45
45
|
|
|
46
|
-
##
|
|
46
|
+
## Read vs Write attributes
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
Some attributes have separate read and write types defined, which is not supported by typescript. These are modeled by the read property having the attribute's name, and a separate `<name>_write` property representing writing to the property. This will map to the correct property name via a [@customName annotation](https://typescripttolua.github.io/docs/advanced/compiler-annotations/#customname). These properties are readable since typescript does not support the concept of writeonly, and reading them will succeed, but the type of the returned value will be wrong.
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
Typescript:
|
|
51
51
|
|
|
52
52
|
```typescript
|
|
53
|
-
|
|
54
|
-
let x = noise.var_get('x');
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
Also unlike the main factorio API, these types are not documented in a machine-readable way and therefore are not generated here along with the main API types. Instead, they are hand-written as needed and as a result are incomplete and more likely to be wrong. See the [existing declarations](https://github.com/sguest/factorio-types/tree/master/src/lualib).
|
|
58
|
-
|
|
59
|
-
If there are types of lualib that you need but do not exist, either open an issue asking for it, or write the type definitions and open a pull request. If you would like to continue working with these types while they do not exist in `factorio-types`, you can add the import path to `tstl.noResolvePaths` in tsconfig.json, and then `require()` the paths, which will be typed as `any`.
|
|
60
|
-
|
|
61
|
-
`tsconfig.json`
|
|
62
|
-
|
|
63
|
-
```json
|
|
53
|
+
function example(burner: LuaBurner)
|
|
64
54
|
{
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
55
|
+
let read: ItemIDAndQualityIDPair = burner.currently_burning;
|
|
56
|
+
burner.currently_burning_write = 'coal';
|
|
68
57
|
}
|
|
69
58
|
```
|
|
70
59
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
```typescript
|
|
74
|
-
const math2d = require('math2d');
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
### Noise
|
|
78
|
-
|
|
79
|
-
The `noise` module has mostly-complete type definitions. A couple notes on usage due to the limitations of typescript
|
|
80
|
-
|
|
81
|
-
The `noise.var` function is named `noise.var_get` since `var` is a reserved word in typscript. It will be emitted as `noise.var` thanks to a [@customName compiler annotation](https://typescripttolua.github.io/docs/advanced/compiler-annotations/#customname).
|
|
82
|
-
|
|
83
|
-
typescript
|
|
84
|
-
|
|
85
|
-
```ts
|
|
86
|
-
import * as noise from "noise";
|
|
87
|
-
let x = noise.var_get('x');
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
output lua
|
|
60
|
+
Output lua:
|
|
91
61
|
|
|
92
62
|
```lua
|
|
93
|
-
local
|
|
94
|
-
local
|
|
63
|
+
local function example(burner)
|
|
64
|
+
local read = burner.currently_burning
|
|
65
|
+
burner.currently_burning = "coal"
|
|
66
|
+
end
|
|
95
67
|
```
|
|
96
68
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
- Addition: `noise.add`
|
|
100
|
-
- Subraction: `noise.sub`
|
|
101
|
-
- Multiplication: `noise.mul`
|
|
102
|
-
- Division: `noise.div`
|
|
103
|
-
- Unary Negation: `noise.unm`
|
|
104
|
-
- Exponentiation: `noise.pow`
|
|
105
|
-
|
|
106
|
-
typescript
|
|
69
|
+
## Lualib
|
|
107
70
|
|
|
108
|
-
|
|
109
|
-
let x = noise.var_get('x');
|
|
110
|
-
let y = noise.var_get('y');
|
|
111
|
-
let sum = noise.add(x, y);
|
|
112
|
-
```
|
|
71
|
+
Factorio makes various lua functions available to mods via [LuaLib](https://github.com/wube/factorio-data/tree/master/core/lualib)
|
|
113
72
|
|
|
114
|
-
|
|
73
|
+
Unlike the main parts of the factorio API, these do not exist as ambient globals but instead must be imported
|
|
115
74
|
|
|
116
|
-
|
|
117
|
-
local x = noise.var("x")
|
|
118
|
-
local y = noise.var("y")
|
|
119
|
-
local sum = x + y;
|
|
120
|
-
```
|
|
75
|
+
The `noise` lualib definitions were previous present in this library. However, as of version 2.0.7, `noise.lua` was [removed from lualib in the factorio-data repo](https://github.com/wube/factorio-data/commit/7522d3763e76e09ce1a46cba676dfc2b6d12b127). This was accompanied by many of the required supporting types being removed from the prototype definitions, and therefore the noise definitions have been removed from this library, at least temporarily.
|