Code Monkey home page Code Monkey logo

godot-tscn-parser's Introduction

Godot TSCN Parser

Travis CI Go Report Card Coverage Status

Go library for parsing the Godot TSCN file format.

Powered by the great participle parser library.

Usage

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

FAQ

My TSCN file isn't working, can you fix it?

Please open an issue with your TSCN file.

Or even better, open a pull request which adds the file to test/fixtures.

Why can't I read a certain value?

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.

What are "Volatile Nodes"?

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.

License

MIT

godot-tscn-parser's People

Contributors

atomicptr avatar mrombout avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

godot-tscn-parser's Issues

Add a proper scene representation

I don't want to return raw participle structures to the user, so we need to build a proper representation of a Scene (with a node tree) etc.

Add unknown arguments to a generic field

Currently on some things like Node we're only adding known values into fields. There should be a field that collects everything else that is specified.

That or maybe the known fields should be converted into methods instead ๐Ÿค” .

Unexpected token error on parsing GdValue with some E notation values

It appears that floats written in the scientific E notation can not be parsed when their first component is an integer. For example floats written as 1e-05 will not parse, but when written as 1.0e05 it will.

The following test will fail with a 2:24: unexpected token "-05" error:

func TestScientificENotation(t *testing.T) {
	content := `[gd_scene]
scientific_e_float = 1e-05`

	_, err := Parse(strings.NewReader(content))
	assert.NoError(t, err)
}

After some investigation I noticed the regular expression used in the lexer for Float values (-?[0-9]*\.[0-9]+(e\-[0-9]+)?\b) does not match the specific case above, and the Ident regular expression matches too liberally.

Token@test:1:1{-6, "["}
Token@test:1:2{-2, "gd_scene"}
Token@test:1:11{-2, "format"}
Token@test:1:17{-6, "="}
Token@test:1:18{-5, "2"}
Token@test:1:19{-6, "]"}
Token@test:2:1{-2, "scientific_e_float"}
Token@test:2:20{-6, "="}
Token@test:2:22{-2, "1e"}
Token@test:2:24{-5, "-05"}
Token@test:2:27{-1, ""}

It looks like it's just a matter of finding a more fitting regular expression that doesn't clash with any other rules. So far -?\d+(\.\d+|e-?\d+)(e-?\d+)?\b seems to be working (#7), and most importantly does not break any of the other tests as far as I can see.


I've encountered this problem with some (not all) of the maps compiled with Qodot. But it looks like a problem that could happen with any ArrayMesh definition.

[sub_resource type="ArrayMesh" id=2]
// ... omitted
surfaces/2 = {
"aabb": AABB( -50, 0, -50, 100, 1e-05, 100 ),
"array_data": PoolByteArray( 0, 0, 0, 66, 0, 0, 
// ... omitted

Validate scenes

The documentation specifies some rules that a file has to respect in order to be valid, should be implemented

https://docs.godotengine.org/en/stable/development/file_formats/tscn.html

Examples

  • An external resource consists of a path, a type and an ID.
  • The first node in the file, which is also the scene root, must not have a parent=Path/To/Node entry in its heading. All scene files should have exactly one scene root. If it doesn't, Godot will fail to import the file.
  • Checking supported scene format version against the one in the file (we can only parse version 2)

Determine what is necessary to support Godot 4.0

Godot 4.0 will release at some point, should make sure its also supported. Optimally we can support both at once, worst case we'd have to split things off into a new major version.

  • #9 new format version with some changes
  • ... more?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.