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 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
- ## Lualib
46
+ ## Read vs Write attributes
47
47
 
48
- Factorio makes various lua functions available to mods via [LuaLib](https://github.com/wube/factorio-data/tree/master/core/lualib)
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
- Unlike the main parts of the factorio API, these do not exist as ambient globals but instead must be imported
50
+ Typescript:
51
51
 
52
52
  ```typescript
53
- import * as noise from "noise";
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
- "tstl": {
66
- "noResolvePaths": ["math2d"]
67
- }
55
+ let read: ItemIDAndQualityIDPair = burner.currently_burning;
56
+ burner.currently_burning_write = 'coal';
68
57
  }
69
58
  ```
70
59
 
71
- `some-file.ts`
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 noise = require("noise")
94
- local x = noise.var("x")
63
+ local function example(burner)
64
+ local read = burner.currently_burning
65
+ burner.currently_burning = "coal"
66
+ end
95
67
  ```
96
68
 
97
- Noise values have operator overloads for common arithmetic operations, however Typescript does not support operator overloading. These are implemented as [Operator map types](https://typescripttolua.github.io/docs/advanced/language-extensions#operator-map-types) in the noise library, which will emit as regular operators in lua. Available operators are named following lua conventions for overloaded operators without the preceding double-underscore:
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
- ```ts
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
- Output lua
73
+ Unlike the main parts of the factorio API, these do not exist as ambient globals but instead must be imported
115
74
 
116
- ```lua
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.