Skip to content

Commit 50db3cc

Browse files
committed
Update plugin for Godot 4.3
1 parent 461016c commit 50db3cc

File tree

7 files changed

+37
-21
lines changed

7 files changed

+37
-21
lines changed

README.md

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

33
An export plugin for stripping comments and "conditional compilation" of GDScript.
44

5-
Compatible with Godot **4.2.x**. Ready for production use. Please report if you find any bugs.
5+
Compatible with Godot **4.3.x**. Ready for production use. Please report if you find any bugs.
66

77
## How to use
88

@@ -14,6 +14,16 @@ The original scripts will not be changed, but in PCK/ZIP the scripts will be cha
1414
Use ZIP to check to check the result. If any errors occurred during the export,
1515
you will see them in the Output Log.
1616

17+
> [!TIP]
18+
> Since 4.3, Godot supports exporting GDScript in binary mode out of the box. If your goal
19+
> is just to strip comments from the exported project, you may not need to use this plugin.
20+
21+
> [!IMPORTANT]
22+
> If you are interested in features like conditional compilation and therefore want to use
23+
> this plugin, please note that it exports GDScript as text, regardless of the selected
24+
> export mode. But you should not lose much from this, the binary mode does not provide
25+
> significant obfuscation.
26+
1727
## Settings
1828

1929
You can change the settings in the Options tab of the Export dialog:
@@ -25,14 +35,12 @@ You can change the settings in the Options tab of the Export dialog:
2535

2636
</details>
2737

28-
## Important note
29-
30-
Each supported platform has certain standard feature tags (plus any custom tags you specify
31-
in the export preset). However, there are some standard tags that are not known in advance.
32-
See [godotengine/godot#76990](https://github.com/godotengine/godot/issues/76990) and
33-
[godotengine/godot#76996](https://github.com/godotengine/godot/pull/76996) for details.
34-
35-
You can specify a list of feature tags that will be treated as dynamic in the export options.
38+
> [!NOTE]
39+
> Each supported platform has certain standard feature tags (plus any custom tags you specify
40+
> in the export preset). However, there are some standard tags that are not known in advance.
41+
> See [godotengine/godot#76990](https://github.com/godotengine/godot/issues/76990) and
42+
> [godotengine/godot#76996](https://github.com/godotengine/godot/pull/76996) for details.
43+
> You can specify a list of feature tags that will be treated as dynamic in the export options.
3644
3745
## Features
3846

addons/gdscript_preprocessor/export_plugin.gd

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
extends EditorExportPlugin
22

33

4-
@warning_ignore("inferred_declaration")
54
const _Preprocessor = preload("./preprocessor.gd")
65

76
var _preprocessor: _Preprocessor = _Preprocessor.new()
7+
var _addon_folder: String
8+
9+
10+
func _init() -> void:
11+
var script: Script = get_script()
12+
_addon_folder = script.resource_path.get_base_dir() + "/"
813

914

1015
func _get_name() -> String:
11-
return "gdscript_preprocessor"
16+
# Docs: "The plugins are sorted by name before exporting".
17+
# See https://github.com/godotengine/godot/issues/93487.
18+
return "AAA_gdscript_preprocessor"
1219

1320

1421
func _get_export_options(_platform: EditorExportPlatform) -> Array[Dictionary]:
@@ -72,7 +79,9 @@ func _export_file(path: String, type: String, _features: PackedStringArray) -> v
7279
if type != "GDScript":
7380
return
7481

75-
if _preprocessor.preprocess(FileAccess.get_file_as_string(path)):
82+
if path.begins_with(_addon_folder):
83+
skip()
84+
elif _preprocessor.preprocess(FileAccess.get_file_as_string(path)):
7685
skip()
7786
add_file(path, _preprocessor.result.to_utf8_buffer(), false)
7887
else:

addons/gdscript_preprocessor/plugin.gd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
extends EditorPlugin
33

44

5-
@warning_ignore("inferred_declaration")
65
const _ExportPlugin = preload("./export_plugin.gd")
76

87
var _export_plugin: _ExportPlugin = _ExportPlugin.new()

addons/gdscript_preprocessor/preprocessor.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ const _VARIANT_DEFAULTS: Dictionary = {
8484
"PackedVector2Array": "PackedVector2Array()",
8585
"PackedVector3Array": "PackedVector3Array()",
8686
"PackedColorArray": "PackedColorArray()",
87+
"PackedVector4Array": "PackedVector4Array()",
8788
}
8889

8990
const _PARENS: Dictionary = {

project.godot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ config_version=5
1111
[application]
1212

1313
config/name="gdscript-preprocessor"
14-
config/features=PackedStringArray("4.2", "Forward Plus")
14+
config/features=PackedStringArray("4.3", "Forward Plus")
1515
config/icon="res://icon.png"
1616

1717
[debug]

tests/features/directives.gd

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ var a2: int
1111
var a3: int
1212
#~endif # non_existent
1313

14-
#~if OS.has_feature("linux")
14+
#~if OS.has_feature("pc")
1515
var a4: int
16-
#~endif # linux
16+
#~endif # pc
1717

1818
#~endif # debug
1919

@@ -26,13 +26,13 @@ var a7: int
2626
#~endif # debug
2727
#~endif # non_existent
2828

29-
#~if OS.has_feature("non_existent") or OS.has_feature("linux")
29+
#~if OS.has_feature("non_existent") or OS.has_feature("pc")
3030
var a8: int
31-
#~endif # non_existent or linux
31+
#~endif # non_existent or pc
3232

33-
#~if OS.has_feature("non_existent") and OS.has_feature("linux")
33+
#~if OS.has_feature("non_existent") and OS.has_feature("pc")
3434
var a9: int
35-
#~endif # non_existent and linux
35+
#~endif # non_existent and pc
3636

3737
#~if OS.is_debug_build()
3838
var a10: int

tests/runner.gd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
extends SceneTree
22

33

4-
@warning_ignore("inferred_declaration")
54
const _Preprocessor = preload("../addons/gdscript_preprocessor/preprocessor.gd")
65

76
var _preprocessor: _Preprocessor = _Preprocessor.new()

0 commit comments

Comments
 (0)