godot-properties-parser

Crates.iogodot-properties-parser
lib.rsgodot-properties-parser
version0.4.0
created_at2025-11-23 15:06:45.145088+00
updated_at2025-11-25 20:12:28.495899+00
descriptionA parser for Godot Engine property files (.tscn scenes and .godot projects)
homepage
repositoryhttps://github.com/sven-teigler/godot-properties-parser
max_upload_size
id1946655
size150,661
Sven Teigler (greenpixels)

documentation

README

Godot Properties Parser

A Rust parser for Godot Engine files.

Note: All properties are parsed as key-value pairs of strings. More specific typing needs to be implemented by the user.

Installation

cargo add godot-properties-parser

Usage

parse_scene_file

use godot_properties_parser::parse_scene_file;
use std::fs;

let scene_content = fs::read_to_string("path/to/scene.tscn")
    .expect("Failed to read scene file");

match parse_scene_file(&scene_content) {
    Ok((remaining, scene)) => {
        println!("Header: {:?}", scene.header);
        println!("Number of ext_resources: {}", scene.ext_resources.len());
        println!("Number of sub_resources: {}", scene.sub_resources.len());
        println!("Number of nodes: {}", scene.nodes.len());
        println!("Number of connections: {}", scene.connections.len());
        
        // Access specific sections
        for node in &scene.nodes {
            println!("Node type: {}", node.header_type);
            for prop in &node.properties {
                println!("  {}: {}", prop.key, prop.value);
            }
        }
    }
    Err(e) => eprintln!("Parse error: {:?}", e),
}

Returns SceneFile with:

  • header, ext_resources, sub_resources, nodes, connections, editables - Categorized sections
  • all_sections - All sections in original order, including any unrecognized types

parse_project_file

use godot_properties_parser::parse_project_file;
use std::fs;

let project_content = fs::read_to_string("project.godot")
    .expect("Failed to read project file");

match parse_project_file(&project_content) {
    Ok((remaining, project)) => {
        // Access categorized sections
        if let Some(app) = project.application {
            println!("Application section found");
            for prop in &app.properties {
                println!("  {}: {}", prop.key, prop.value);
            }
        }
        
        if let Some(autoload) = project.autoload {
            println!("Autoloads:");
            for prop in &autoload.properties {
                println!("  {}: {}", prop.key, prop.value);
            }
        }
        
        println!("Total sections: {}", project.all_sections.len());
    }
    Err(e) => eprintln!("Parse error: {:?}", e),
}

Returns ProjectFile with categorized sections:

  • application, audio, autoload, debug, display, editor_plugins, input, input_devices, internationalization, layer_names, physics, rendering - Known section types
  • all_sections - All sections in original order, including any custom or unrecognized sections

parse_property_file

Low-level parser that returns generic key-value pairs instead of a specific struct. Useful for any Godot property file format.

use godot_properties_parser::parse_property_file;
use std::fs;

let content = fs::read_to_string("path/to/file.tscn")
    .expect("Failed to read file");

match parse_property_file(&content) {
    Ok((remaining, property_file)) => {
        for section in &property_file.sections {
            println!("Section type: {}", section.header_type);
            for prop in &section.properties {
                println!("  {}: {}", prop.key, prop.value);
            }
        }
    }
    Err(e) => eprintln!("Parse error: {:?}", e),
}

Returns PropertyFile with sections: Vec<Section>.

Each Section has header_type: String and properties: Vec<UntypedProperty>.

Each UntypedProperty has key: String and value: String.

Commit count: 0

cargo fmt