|
| 1 | +tool |
| 2 | +extends EditorPlugin |
| 3 | + |
| 4 | +class Exporter extends EditorExportPlugin: |
| 5 | + var build_path: String |
| 6 | + var build_dir: String |
| 7 | + |
| 8 | + var macos_build: bool |
| 9 | + |
| 10 | + func _export_begin(features, is_debug, path, flags): |
| 11 | + if OS.has_feature("Windows"): |
| 12 | + printerr("[Extras Exporter] Running on Windows; export of additional files disabled") |
| 13 | + return |
| 14 | + |
| 15 | + build_path = path |
| 16 | + build_dir = path.get_base_dir() + "/" |
| 17 | + macos_build = "OSX" in features |
| 18 | + |
| 19 | + func _export_end() -> void: |
| 20 | + if OS.has_feature("Windows"): |
| 21 | + return |
| 22 | + |
| 23 | + var include_files: PoolStringArray = ProjectSettings.get_setting( |
| 24 | + "extras_exporter/files_to_include") |
| 25 | + |
| 26 | + print("[Extras Exporter] Build directory: ", build_dir) |
| 27 | + |
| 28 | + var output = [] |
| 29 | + |
| 30 | + OS.execute("pwd", [], true, output) |
| 31 | + print("[Extras Exporter] Working directory: ", output[0]) |
| 32 | + |
| 33 | + for file in include_files: |
| 34 | + if macos_build: |
| 35 | + print("[Extras Exporter] Adding %s to macOS archive" % file) |
| 36 | + OS.execute("zip", ["-rq", build_path, file], true, output, true) |
| 37 | + else: |
| 38 | + print("[Extras Exporter] Copying %s to build directory" % file) |
| 39 | + OS.execute("cp", ["-fR", file, build_dir], true, output, true) |
| 40 | + for s in output: |
| 41 | + if !s.empty(): |
| 42 | + printerr("[Extras Exporter] ", s) |
| 43 | + |
| 44 | + print("[Extras Exporter] Finished") |
| 45 | + |
| 46 | +var exporter = Exporter.new() |
| 47 | + |
| 48 | +func _enter_tree(): |
| 49 | + add_export_plugin(exporter) |
| 50 | + if !ProjectSettings.has_setting("extras_exporter/files_to_include"): |
| 51 | + ProjectSettings.set_setting( |
| 52 | + "extras_exporter/files_to_include", |
| 53 | + PoolStringArray()) |
| 54 | + ProjectSettings.set_initial_value( |
| 55 | + "extras_exporter/files_to_include", |
| 56 | + PoolStringArray()) |
| 57 | + |
| 58 | +func _exit_tree(): |
| 59 | + remove_export_plugin(exporter) |
0 commit comments