Skip to content

Latest commit

 

History

History
64 lines (54 loc) · 2.85 KB

README_TEMPLATE.md

File metadata and controls

64 lines (54 loc) · 2.85 KB

GdScript2All

A tool for converting Godot's GdScript to other languages (currently C# and c++) with features like type inference. Requires Python installed (tested with 3.12.5).

Editor addon

Available from the Asset Lib tab in editor or alternatively download as zip and extract into your project.
Enable in Project Settings->Plugins then you're set.
To use, drag&drop files and folders from the FileSystem dock then click convert.

From the command line

call the main script using your favorite command line utility (add -t Cpp for c++) :

python addons/gd2all/converter/main.py <file_or_folder_path> -o <output_file_or_folder_path>

Example

script input :

__test.gd__

C# output :

__test.cs__

c++ output (header) :

__test.hpp__

c++ output (implementation) :

__test.cpp__

Limitations

  • generated code might need corrections !
  • pattern matching - a complicated form of the match case statement - is not supported
  • when the parser encounters something unexpected it will drop the current line and resume at the next (panic mode). this might result in mangled output.
  • read TODO.md for missing features
  • C# : godot won't build C# scripts until you have created at least one C# script manually in the editor
  • c++ : generated code does a best guess on what whould be pointers/references
  • c++ : accessing/modifying parent class properties does not use getters/setters (this is a conscious choice)

Updating the API definition

  • download the offical godot repo
  • copy it's doc/classes folder and paste it into our classData folder
  • install untangle (xml parsing library) if you don't have it (pip install untangle)
  • run py ./addons/gdscript2all/converter/src/godot_types.py to generate the pickle class db
  • profit.

Adding new languages

If you want to transpile to an unsupported language, rename a copy of the C# transpiler backend, modify it as needed, then to use it you just have to pass its name with the -t flag (example below with c++ transpiler):

python ./addons/gdscript2all/converter/main.py -t Cpp <file_or_folder_path>

Explaining the GPL-3.0 license

The code this tool generates from your GDScipt is yours. However, any improvment made to this tool's source has to be contributed back. I think that's fair.

Buy Me A Coffee