You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/manuals/editor-scripts.md
+140-1Lines changed: 140 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -56,13 +56,17 @@ You can interact with the editor using `editor` package that defines this API:
56
56
- for atlas animations: `images` (same as `images` in atlas)
57
57
- for tilemaps: `layers` (list of editor nodes for layers in the tilemap)
58
58
- for tilemap layers: `tiles` (an unbounded 2d grid of tiles), see `tilemap.tiles.*` for more info
59
+
- for particlefx: `emitters` (list of emitter editor nodes) and `modifiers` (list of modifier editor nodes)
60
+
- for particlefx emitters: `modifiers` (list of modifier editor nodes)
61
+
- for collision objects: `shapes` (list of collision shape editor nodes)
62
+
- for GUI files: `layers` (list of layer editor nodes)
59
63
- some properties that are shown in the Properties view when you have selected something in the Outline view. These types of outline properties supported:
60
64
-`strings`
61
65
-`booleans`
62
66
-`numbers`
63
67
-`vec2`/`vec3`/`vec4`
64
68
-`resources`
65
-
69
+
-`curves`
66
70
Please note that some of these properties might be read-only, and some might be unavailable in different contexts, so you should use `editor.can_get` before reading them and `editor.can_set` before making editor set them. Hover over property name in Properties view to see a tooltip with information about how this property is named in editor scripts. You can set resource properties to `nil` by supplying `""` value.
67
71
-`editor.can_get(node_id, property)` — check if you can get this property so `editor.get()` won't throw an error.
68
72
-`editor.can_set(node_id, property)` — check if `editor.tx.set()` transaction step with this property won't throw an error.
@@ -269,6 +273,141 @@ editor.transact({
269
273
})
270
274
```
271
275
276
+
#### Editing particlefx
277
+
278
+
You can edit particlefx using `modifiers` and `emitters` properties. For example, adding a circle emitter with acceleration modifier is done like this:
279
+
```lua
280
+
editor.transact({
281
+
editor.tx.add("/fire.particlefx", "emitters", {
282
+
type="emitter-type-circle",
283
+
modifiers= {
284
+
{type="modifier-type-acceleration"}
285
+
}
286
+
})
287
+
})
288
+
```
289
+
Many particlefx properties are curves or curve spreads (i.e. curve + some randomizer value). Curves are represented as a table with a non-empty list of `points`, where each point is a table with the following properties:
290
+
-`x` - the x coordinate of the point, should start at 0 and end at 1
291
+
-`y` - the value of the point
292
+
-`tx` (0 to 1) and `ty` (-1 to 1) - tangents of the point. E.g., for an 80-degree angle, `tx` should be `math.cos(math.rad(80))` and `ty` should be `math.sin(math.rad(80))`.
293
+
Curve spreads additionally have a `spread` number property.
294
+
295
+
For example, setting a particle lifetime alpha curve for an already existing emitter might look like this:
{x=0, y=0, tx=0.1, ty=1}, -- start at 0, go up quickly
301
+
{x=0.2, y=1, tx=1, ty=0}, -- reach 1 at 20% of a lifetime
302
+
{x=1, y=0, tx=1, ty=0} -- slowly go down to 0
303
+
}})
304
+
})
305
+
```
306
+
Of course, it's also possible to use the `particle_key_alpha` key in a table when creating an emitter. Additionally, you can use a single number instead to represent a "static" curve.
307
+
308
+
#### Editing collision objects
309
+
310
+
In addition to default outline properties, collision objects define `shapes` node list property. Adding new collision shapes is done like this:
print(editor.can_reset(node_in_template, "text")) -- true (overrides a value in the template)
409
+
```
410
+
272
411
### Use shell commands
273
412
274
413
Inside the `run` handler, you can write to files (using `io` module) and execute shell commands (using `editor.execute()` command). When executing shell commands, it's possible to capture the output of a shell command as a string and then use it in code. For example, if you want to make a command for formatting JSON that shells out to globally installed [`jq`](https://jqlang.github.io/jq/), you can write the following command:
0 commit comments