All Projects → stevearc → godot_parser

stevearc / godot_parser

Licence: MIT License
Python library for parsing Godot scene files

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to godot parser

godot-editor-theme-explorer
Godot Editor plugin to browse various items of Editor Theme, such as icons, colors and fonts.
Stars: ✭ 61 (+125.93%)
Mutual labels:  godot
broken seals
An open source third person action RPG with multiplayer support.
Stars: ✭ 223 (+725.93%)
Mutual labels:  godot
BrainfuckIDE
A Brainfuck IDE/debugger designed to be intuitive, featureful and visually appealing
Stars: ✭ 77 (+185.19%)
Mutual labels:  godot
godot-FLMusicLib
GDNative library that plays mp3, chiptune and tracker music files using Game Music Emu, Minimp3 and openmpt
Stars: ✭ 38 (+40.74%)
Mutual labels:  godot
line-renderer
A GDScript implementation of a line renderer in Godot.
Stars: ✭ 25 (-7.41%)
Mutual labels:  godot
GodotDiscordSDK
A Discord Game SDK wrapper for Godot, written in C.
Stars: ✭ 40 (+48.15%)
Mutual labels:  godot
godot-lod-demo
Demonstration project for the Level of Detail (LOD) Godot 3.x add-on
Stars: ✭ 34 (+25.93%)
Mutual labels:  godot
godot-twicil
Godot TwiCIL – Godot Twitch Chat Interaction Layer
Stars: ✭ 57 (+111.11%)
Mutual labels:  godot
Godot-Share
Simple share text and/or image module for Godot Engine (Android & iOS)
Stars: ✭ 58 (+114.81%)
Mutual labels:  godot
discord.gd
Discord Bot API wrapper for Godot. Make bots in GDScript.
Stars: ✭ 69 (+155.56%)
Mutual labels:  godot
triple-triad-godot
Re-implementation of Triple Triad from Final Fantasy VIII. Made with Godot 3
Stars: ✭ 61 (+125.93%)
Mutual labels:  godot
BitKnight
BitKnight is a side-scroller adventure game in the style of Nokia 3310 games
Stars: ✭ 23 (-14.81%)
Mutual labels:  godot
godot-tester
A Github Action to handle testing Godot applications with GUT
Stars: ✭ 15 (-44.44%)
Mutual labels:  godot
OpMon-Godot
An open source Pokemon-inspired game, now with Godot
Stars: ✭ 50 (+85.19%)
Mutual labels:  godot
godot-polygon2d-fracture
A simple script for fracturing polygons. Also adds nice helper functions for polygons like calculateArea, triangulate, getRandomPointsInPolygon, getBoundingRect)
Stars: ✭ 148 (+448.15%)
Mutual labels:  godot
surfacer
AI and pathfinding for 2D-platformers in Godot.
Stars: ✭ 56 (+107.41%)
Mutual labels:  godot
Fake-Interior-Shader-for-GodotEngine
Interior Mapping shader for the Godot Game Engine 3.x that works with both GLES3 and GLES2.
Stars: ✭ 40 (+48.15%)
Mutual labels:  godot
GodotRecorder
A simple addon to record frames of in-game footage.
Stars: ✭ 47 (+74.07%)
Mutual labels:  godot
godot card tools
Framework for making card-games in Godot
Stars: ✭ 30 (+11.11%)
Mutual labels:  godot
gd-YAFSM
Yet Another Finite State Machine for godot
Stars: ✭ 158 (+485.19%)
Mutual labels:  godot

Godot Parser

Build Status Coverage Status Downloads

This is a python library for parsing Godot scene (.tscn) and resource (.tres) files. It's intended to make it easier to automate certain aspects of editing scene files or resources in Godot.

High-level API

godot_parser has roughly two levels of API. The low-level API has no Godot-specific logic and is just a dumb wrapper for the file format.

The high-level API has a bit of application logic on top to mirror Godot functionality and make it easier to perform certain tasks. Let's look at an example by creating a new scene file for a Player:

  from godot_parser import GDScene, Node

  scene = GDScene()
  res = scene.add_ext_resource("res://PlayerSprite.png", "PackedScene")
  with scene.use_tree() as tree:
      tree.root = Node("Player", type="KinematicBody2D")
      tree.root.add_child(
          Node(
              "Sprite",
              type="Sprite",
              properties={"texture": res.reference},
          )
      )
  scene.write("Player.tscn")

It's much easier to use the high-level API when it's available, but it doesn't cover everything. Note that use_tree() does support inherited scenes, and will generally function as expected (e.g. nodes on the parent scene will be available, and making edits will properly override fields in the child scene). There is no support yet for changing the inheritence of a scene.

Low-level API

Let's look at creating that same Player scene with the low-level API:

  from godot_parser import GDFile, ExtResource, GDSection, GDSectionHeader

  scene = GDFile(
      GDSection(GDSectionHeader("gd_scene", load_steps=2, format=2))
  )
  scene.add_section(
      GDSection(GDSectionHeader("ext_resource", path="res://PlayerSprite.png", type="PackedScene", id=1))
  )
  scene.add_section(
      GDSection(GDSectionHeader("node", name="Player", type="KinematicBody2D"))
  )
  scene.add_section(
      GDSection(
          GDSectionHeader("node", name="Sprite", type="Sprite", parent="."),
          texture=ExtResource(1)
      )
  )
  scene.write("Player.tscn")

You can see that this requires you to manage more of the application logic yourself, such as resource IDs and node structure, but it can be used to create any kind of TSCN file.

More Examples

Here are some more examples of how you can use this library.

Find all scenes in your project with a "Sensor" node and change the collision_layer:

  import os
  import sys
  from godot_parser import load

  def main(project):
      for root, _dirs, files in os.walk(project):
          for file in files:
              if os.path.splitext(file)[1] == '.tscn':
                  update_collision_layer(os.path.join(root, file))

  def update_collision_layer(filepath):
      scene = load(filepath)
      updated = False
      with scene.use_tree() as tree:
          sensor = tree.get_node('Sensor')
          if sensor is not None:
              sensor['collision_layer'] = 5
              updated = True

      if updated:
          scene.write(filepath)

  main(sys.argv[1])

Caveats

This was written with the help of the Godot TSCN docs, but it's still mostly based on visual inspection of the Godot files I'm working on. If you find a situation godot_parser doesn't handle or a feature it doesn't support, file an issue with the scene file and an explanation of the desired behavior. If you want to dig in and submit a pull request, so much the better!

If you want to run a quick sanity check for this tool, you can use the test_parse_files.py script. Pass in your root Godot directory and it will verify that it can correctly parse and re-serialize all scene and resource files in your project.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].