Skip to content

Commit 7525881

Browse files
committed
edits
1 parent 0064f58 commit 7525881

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

docs/en/manuals/editor-scripts.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,79 @@ editor.transact({
409409
print(editor.can_reset(node_in_template, "text")) -- true (overrides a value in the template)
410410
```
411411

412+
#### Editing game objects
413+
414+
It's possible to edit components of a game object file using editor scripts. The components come in 2 flavors: referenced and embedded. Referenced components use type `component-reference` and act as references to other resources, only allowing overrides of go properties defined in scripts. Embedded components use types like `sprite`, `label`, etc., and allow editing of all properties defined in the component type, as well as adding sub-components like shapes of collision objects. For example, you can use the following code to set up a game object:
415+
```lua
416+
editor.transact({
417+
editor.tx.add("/npc.go", "components", {
418+
type = "sprite",
419+
id = "view"
420+
}),
421+
editor.tx.add("/npc.go", "components", {
422+
type = "collisionobject",
423+
id = "collision",
424+
shapes = {
425+
{
426+
type = "shape-type-box",
427+
dimensions = {32, 32, 32}
428+
}
429+
}
430+
}),
431+
editor.tx.add("/npc.go", "components", {
432+
type = "component-reference",
433+
path = "/npc.script"
434+
id = "controller",
435+
__hp = 100 -- set a go property defined in the script
436+
})
437+
})
438+
```
439+
440+
#### Editing collections
441+
It's possible to edit collections using editor scripts. You can add game objects (embedded or referenced) and collections (referenced). For example:
442+
```lua
443+
local coll = "/char.collection"
444+
editor.transact({
445+
editor.tx.add(coll, "children", {
446+
-- embbedded game object
447+
type = "go",
448+
id = "root",
449+
children = {
450+
{
451+
-- referenced game object
452+
type = "go-reference",
453+
path = "/char-view.go"
454+
id = "view"
455+
},
456+
{
457+
-- referenced collection
458+
type = "collection-reference",
459+
path = "/body-attachments.collection"
460+
id = "attachments"
461+
}
462+
},
463+
-- embedded gos can also have components
464+
components = {
465+
{
466+
type = "collisionobject",
467+
id = "collision",
468+
shapes = {
469+
{type = "shape-type-box", dimensions = {2.5, 2.5, 2.5}}
470+
}
471+
},
472+
{
473+
type = "component-reference",
474+
id = "controller",
475+
path = "/char.script",
476+
__hp = 100 -- set a go property defined in the script
477+
}
478+
}
479+
})
480+
})
481+
```
482+
483+
Like in the editor, referenced collections can only be added to the root of the edited collection, and game objects can only be added to embedded or referenced game objects, but not to referenced collections or game objects within these referenced collections.
484+
412485
### Use shell commands
413486

414487
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

Comments
 (0)