Skip to content

Commit 6a1037f

Browse files
committed
Updated readme, re-added file saving
1 parent cd96735 commit 6a1037f

File tree

4 files changed

+36
-42
lines changed

4 files changed

+36
-42
lines changed

README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
### USE THIS AT YOUR (CODE'S) OWN RISK!!!
44

5-
Helper tool for making engine modules in Godot 4 (and 3, technically).
5+
Helper tool for making engine modules in Godot 4 and 3.
66

77

88

@@ -18,7 +18,7 @@ This is a little thingamabob I initially made in an evening to automate all the
1818

1919
## Usage
2020

21-
To use the variable code generator, list your variables, seperating them by commas.
21+
To use the variable code generator, list your variables, separating them by commas.
2222

2323
* Any spaces will be deleted (ex: "My var 1, my var 2" will translate to `Myvar1` and `myvar2`)
2424

@@ -30,16 +30,12 @@ To use the variable code generator, list your variables, seperating them by comm
3030

3131

3232

33-
When the files are generated, they will be stored in the data's user directory. The UI has a button that will automatically open this folder in your computer's file explorer.
34-
33+
When the C++ code is generated, it will show up in the preview windows on the right side. Here, you can make any necessary edits that you may see fit to do. If you want to export that text to a file, click the save button. Then, press the button for opening the output folder, and the folder where the saved files are written to will be opened in your file explorer, defaulting to the user directory of Godot.
3534

3635

3736
## Issues
3837

3938
##### Note: I may or *may not* address these
4039

41-
* The `ADD_PROPERTY` does not product valid code; the type will have to be manually corrected.
42-
43-
* Godot 3 support was not exactly intended: It moreso works because they happened to not change the `ClassDB` API between 3 and 4 much. That being said, the above `ADD_PROPERTY` issue is also going to be present for Godot 3.
44-
40+
* No dedicated function binding generator.
4541
* The GDScript to C++ converter is currently not done. Even when it eventually is, what it will output will probably have to be manually tweaked/added to before it is proper, usable code.

project.godot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ config_version=5
1212

1313
config/name="Module Coding Assistant"
1414
config/description="A little tool that aids in writing C++ engine modules."
15+
config/version="2.0.0"
1516
config/tags=PackedStringArray("gui_tools")
1617
run/main_scene="res://scenes/gui.tscn"
1718
config/features=PackedStringArray("4.3", "GL Compatibility")
19+
run/low_processor_mode=true
20+
boot_splash/bg_color=Color(0.179441, 0.405469, 0.978013, 1)
1821
config/icon="res://icon.svg"
1922

2023
[rendering]

scenes/gui.gd

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,21 @@ extends Control
22

33
class_name AppRoot
44

5-
6-
class VariableData:
7-
extends Resource
8-
##The name of the variable
9-
var var_name:String
10-
#The numeric Variant.Type enum value
11-
var type:int
12-
##The type of the variable, eg. "int", "Node3D", etc.
13-
var type_string:String
14-
15-
var type_enum_string:String
16-
17-
var hint_type:int
18-
19-
var hint_string:String
20-
21-
var usage_bitfield:int
22-
23-
func _init(info:Dictionary = {}) -> void:
24-
type = info.get("type", 0)
25-
26-
pass
27-
285
#literally 4 spaces
296
const a_tab:String = " "
307

318
#Class things
32-
const class_filename:String = "{class_name_}.cpp"
339
const class_declaration:String = "class {class_name_}: public {inherits}{"
3410
const class_var_get:String = " {var_type} get_{var_name}();\n"
3511
const class_var_set:String = " void set_{var_name}({var_type} new_{var_name}); \n"
3612

3713
#Variable setgets
38-
const var_setget_filename:String = "{class_name_}_set_gets.cpp"
3914
const var_setget_get:String = "{var_type} {class_name_}::get_{var_name}(){\n return {var_name};\n}\n"
4015
const var_setget_set:String = "void {class_name_}::set_{var_name}({var_type} new_{var_name}){\n {var_name} = new_{var_name};\n}\n"
4116

4217
#Variable bindings
4318
const var_bind_get:String = " ClassDB::bind_method(D_METHOD(\"get_{var_name}\"), &{class_name_}::get_{var_name});\n"
4419
const var_bind_set:String = " ClassDB::bind_method(D_METHOD(\"set_{var_name}\", \"{var_name}\"), &{class_name_}::set_{var_name});\n"
45-
const var_bind_filename:String = "{class_name_}_bindings.cpp"
4620

4721
#Functions
4822
const func_declaration:String = " {var_type} {func_name}({func_params});\n"
@@ -103,7 +77,15 @@ func _on_load_input_pressed() -> void:
10377
input_load_context.call()
10478

10579
func _on_save_output_pressed() -> void:
106-
pass # Replace with function body.
80+
var format_dict:Dictionary = {
81+
"class_name": current_class_name.to_snake_case()
82+
}
83+
84+
write_to_file("{class_name}.hpp".format(format_dict), cpp_header.text)
85+
write_to_file("{class_name}.cpp".format(format_dict), cpp_code.text)
86+
write_to_file("{class_name}_set_gets.cpp".format(format_dict), cpp_setgets.text)
87+
write_to_file("{class_name}_bindings.cpp".format(format_dict), cpp_binding.text)
88+
10789

10890
func _on_open_output_pressed() -> void:
10991
OS.shell_open(settings.output_directory)
@@ -120,6 +102,12 @@ func clear_data() -> void:
120102
process_context = Callable()
121103
input_load_context = Callable()
122104

105+
func write_to_file(file_name:String, data:String) -> void:
106+
var file:FileAccess = FileAccess.open(settings.output_directory.path_join(file_name), FileAccess.WRITE)
107+
if FileAccess.get_open_error() == OK and not data.is_empty():
108+
file.store_string(data)
109+
file.close()
110+
123111
func generate_version_specific_var_enums() -> void:
124112
if settings.godot_3_mode:
125113
pass

scripts/templates/var_type.gd

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,26 @@ static var num_increment:int = 0
55

66
const var_default:String = "{var_type}_{num}"
77

8-
##The variable type of a function/variable
8+
#The numeric Variant.Type enum value
99
var var_type:String
1010
##The name of the variable
1111
var var_name:String = var_default
1212
##The data the variable is assigned at initialization, if any
1313
var init_value:String
1414
##If this variable will be public (bound to GDScript)
1515
var is_export:bool = false
16-
#If this variable is on_ready
16+
##If this variable is on_ready
1717
var is_onready:bool = false #Does this apply to C++???
18+
##The type of the variable, eg. "int", "Node3D", etc.
19+
var type_string:String
1820

19-
func _init(name:String = "", value:String = ""):
20-
if not name.is_empty():
21-
var_name = name
22-
if not value.is_empty():
23-
init_value = value
21+
var type_enum_string:String
22+
23+
var hint_type:int
24+
25+
var hint_string:String
26+
27+
var usage_bitfield:int
28+
29+
func _init(info:Dictionary = {}) -> void:
30+
var_type = info.get("type", 0)

0 commit comments

Comments
 (0)