Go library for parsing the Godot TSCN file format.
Powered by the great participle parser library.
package main
import (
"fmt"
"os"
"github.com/atomicptr/godot-tscn-parser/pkg/tscn"
)
func main() {
// open the file
f, err := os.Open("./path/to/my/scene.tscn")
if err != nil {
panic(err)
}
defer f.Close()
// parse the scene, this accepts an io.Reader
scene, err := tscn.ParseScene(f)
if err != nil {
panic(err)
}
// get the node "Sprite" which is a child of "Player" which is a child of
// of the root node
playerSpriteNode, err := scene.GetNode("Player/Sprite")
if err != nil {
panic(err)
}
// access a field, keep in mind that TSCN files only store non default values
position := playerSpriteNode.Fields["position"]
fmt.Printf("Player/Sprite is at position %v\n", position)
}
Please open an issue with your TSCN file.
Or even better, open a pull request which adds the file to test/fixtures.
Godot does not store default values in TSCN files. Which means you'll only see stuff you've added or changed yourself in these files.
If you have an instanced scene in your scene, and you mark it as editable (and actually edit something), you might find nodes with the type "VolatileNode" in your tree. Since Godot doesn't store unchanged things, these nodes are a band aid for this library to render a proper tree structure. You can basically ignore them.
MIT