Skip to content

Commit 5b5c2fd

Browse files
Site changes [skip-ci]
1 parent 97cf038 commit 5b5c2fd

File tree

2 files changed

+146
-0
lines changed

2 files changed

+146
-0
lines changed

llms-full.txt

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

2234+
#### Editing game objects
2235+
2236+
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:
2237+
```lua
2238+
editor.transact({
2239+
editor.tx.add("/npc.go", "components", {
2240+
type = "sprite",
2241+
id = "view"
2242+
}),
2243+
editor.tx.add("/npc.go", "components", {
2244+
type = "collisionobject",
2245+
id = "collision",
2246+
shapes = {
2247+
{
2248+
type = "shape-type-box",
2249+
dimensions = {32, 32, 32}
2250+
}
2251+
}
2252+
}),
2253+
editor.tx.add("/npc.go", "components", {
2254+
type = "component-reference",
2255+
path = "/npc.script"
2256+
id = "controller",
2257+
__hp = 100 -- set a go property defined in the script
2258+
})
2259+
})
2260+
```
2261+
2262+
#### Editing collections
2263+
It's possible to edit collections using editor scripts. You can add game objects (embedded or referenced) and collections (referenced). For example:
2264+
```lua
2265+
local coll = "/char.collection"
2266+
editor.transact({
2267+
editor.tx.add(coll, "children", {
2268+
-- embbedded game object
2269+
type = "go",
2270+
id = "root",
2271+
children = {
2272+
{
2273+
-- referenced game object
2274+
type = "go-reference",
2275+
path = "/char-view.go"
2276+
id = "view"
2277+
},
2278+
{
2279+
-- referenced collection
2280+
type = "collection-reference",
2281+
path = "/body-attachments.collection"
2282+
id = "attachments"
2283+
}
2284+
},
2285+
-- embedded gos can also have components
2286+
components = {
2287+
{
2288+
type = "collisionobject",
2289+
id = "collision",
2290+
shapes = {
2291+
{type = "shape-type-box", dimensions = {2.5, 2.5, 2.5}}
2292+
}
2293+
},
2294+
{
2295+
type = "component-reference",
2296+
id = "controller",
2297+
path = "/char.script",
2298+
__hp = 100 -- set a go property defined in the script
2299+
}
2300+
}
2301+
})
2302+
})
2303+
```
2304+
2305+
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.
2306+
22342307
### Use shell commands
22352308

22362309
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:

manuals/editor-scripts.md

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

433+
#### Editing game objects
434+
435+
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:
436+
```lua
437+
editor.transact({
438+
editor.tx.add("/npc.go", "components", {
439+
type = "sprite",
440+
id = "view"
441+
}),
442+
editor.tx.add("/npc.go", "components", {
443+
type = "collisionobject",
444+
id = "collision",
445+
shapes = {
446+
{
447+
type = "shape-type-box",
448+
dimensions = {32, 32, 32}
449+
}
450+
}
451+
}),
452+
editor.tx.add("/npc.go", "components", {
453+
type = "component-reference",
454+
path = "/npc.script"
455+
id = "controller",
456+
__hp = 100 -- set a go property defined in the script
457+
})
458+
})
459+
```
460+
461+
#### Editing collections
462+
It's possible to edit collections using editor scripts. You can add game objects (embedded or referenced) and collections (referenced). For example:
463+
```lua
464+
local coll = "/char.collection"
465+
editor.transact({
466+
editor.tx.add(coll, "children", {
467+
-- embbedded game object
468+
type = "go",
469+
id = "root",
470+
children = {
471+
{
472+
-- referenced game object
473+
type = "go-reference",
474+
path = "/char-view.go"
475+
id = "view"
476+
},
477+
{
478+
-- referenced collection
479+
type = "collection-reference",
480+
path = "/body-attachments.collection"
481+
id = "attachments"
482+
}
483+
},
484+
-- embedded gos can also have components
485+
components = {
486+
{
487+
type = "collisionobject",
488+
id = "collision",
489+
shapes = {
490+
{type = "shape-type-box", dimensions = {2.5, 2.5, 2.5}}
491+
}
492+
},
493+
{
494+
type = "component-reference",
495+
id = "controller",
496+
path = "/char.script",
497+
__hp = 100 -- set a go property defined in the script
498+
}
499+
}
500+
})
501+
})
502+
```
503+
504+
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.
505+
433506
### Use shell commands
434507

435508
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)