Make Export All button dynamic based on selected tool

The button label and export presets now change depending on the
dropdown selection. Game exports to Autobuild/Kalulu_Game/<version>,
Prof Tool exports to Autobuild/Prof_Tool/<version>. Shows an alert
and aborts if the version folder already exists.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Adrien Ufferte
2026-03-16 15:56:16 +01:00
parent b3566bdab4
commit 58fe768457
@@ -8,17 +8,38 @@ const TOOL_CONFIGS: Dictionary = {
"name": "Kalulu",
"main_scene": "res://sources/menus/splash_screen/splash_screen.tscn",
"icon": "res://assets/kalulu_icon.png",
"export_folder": "Kalulu_Game",
"button_label": "Export All (Kalulu Game)",
"presets": {
"Android Kalulu AAB": "/Android/Kalulu.aab",
"Android Kalulu APK": "/Android/Kalulu.apk",
"Android Kalulu APK 32 bits": "/Android/Kalulu_32.apk",
"Windows Kalulu": "/Windows/Kalulu-Windows.zip",
"Linux Kalulu": "/Linux/Kalulu-Linux.zip",
# Apple in last because it's always the most complicated
#"iOS Kalulu": "/iOS/Kalulu.ipa",
#"macOS Kalulu": "/macOS/Kalulu-macOS.dmg",
},
},
"prof_tool": {
"name": "Prof_Tool",
"main_scene": "res://sources/language_tool/prof_tool_menu.tscn",
"icon": "res://assets/prof_tool_icon.png",
"export_folder": "Prof_Tool",
"button_label": "Export All (Prof Tool)",
"presets": {
"Windows ProfTool": "/Windows/Prof_Tool-Windows.zip",
"Linux ProfTool": "/Linux/Prof_Tool-Linux.zip",
# Apple in last because it's always the most complicated
#"macOS ProfTool": "/macOS/Prof_Tool-macOS.dmg",
},
}
}
var tool_selector: OptionButton
var exporter_plugin: EditorExportPlugin
var export_button: Button
var current_tool: String = "game"
func _enter_tree() -> void:
# Tool Selector UI
@@ -30,16 +51,16 @@ func _enter_tree() -> void:
add_control_to_container(EditorPlugin.CONTAINER_TOOLBAR, tool_selector)
var settings: EditorSettings = get_editor_interface().get_editor_settings()
var current: Variant = settings.get_setting("export_tool_manager/current_tool")
var current_tool: String = "game"
var saved: Variant = settings.get_setting("export_tool_manager/current_tool")
if typeof(current) == TYPE_STRING and current.strip_edges() != "":
current_tool = current.strip_edges()
if typeof(saved) == TYPE_STRING and saved.strip_edges() != "":
current_tool = saved.strip_edges()
match current_tool:
"prof_tool":
tool_selector.select(1)
"game", _:
current_tool = "game"
tool_selector.select(0)
_apply_tool_config(current_tool)
@@ -50,8 +71,8 @@ func _enter_tree() -> void:
# Export All Button
export_button = Button.new()
export_button.text = "Export All (Game)"
export_button.pressed.connect(_on_export_all_game_pressed)
export_button.text = TOOL_CONFIGS[current_tool]["button_label"]
export_button.pressed.connect(_on_export_all_pressed)
add_control_to_container(EditorPlugin.CONTAINER_TOOLBAR, export_button)
func _exit_tree() -> void:
@@ -64,16 +85,15 @@ func _exit_tree() -> void:
remove_export_plugin(exporter_plugin)
func _on_tool_selected(index: int) -> void:
var tool: String = "game"
match index:
1:
tool = "prof_tool"
current_tool = "prof_tool"
0, _:
tool = "game"
current_tool = "game"
var settings: EditorSettings = get_editor_interface().get_editor_settings()
settings.set_setting("export_tool_manager/current_tool", tool)
_apply_tool_config(tool)
settings.set_setting("export_tool_manager/current_tool", current_tool)
_apply_tool_config(current_tool)
func _apply_tool_config(tool: String) -> void:
@@ -86,29 +106,38 @@ func _apply_tool_config(tool: String) -> void:
ProjectSettings.set_setting("application/run/main_scene", config["main_scene"])
ProjectSettings.set_setting("application/config/icon", config["icon"])
ProjectSettings.save()
if export_button:
export_button.text = config["button_label"]
print("ExportToolManager: Switched to '%s' (scene: %s)" % [config["name"], config["main_scene"]])
func _on_export_all_game_pressed() -> void:
export_all_game_presets()
func _on_export_all_pressed() -> void:
export_all_presets()
func export_all_presets() -> void:
var config: Dictionary = TOOL_CONFIGS[current_tool]
var base_folder: String = "../Export/Autobuild/%s/" % config["export_folder"]
var version_folder: String = base_folder + get_application_version_with_code()
# Check if the version folder already exists
if DirAccess.dir_exists_absolute(version_folder):
var dialog: AcceptDialog = AcceptDialog.new()
dialog.title = "Export aborted"
dialog.dialog_text = "The export folder already exists:\n%s\n\nDelete it manually before re-exporting." % version_folder
get_editor_interface().get_base_control().add_child(dialog)
dialog.popup_centered()
dialog.confirmed.connect(dialog.queue_free)
dialog.canceled.connect(dialog.queue_free)
return
func export_all_game_presets() -> void:
var godot_path: String = OS.get_executable_path()
var exportFolder: String = "../Export/autobuilds/"
var presets: Dictionary[String, String]= {
"Android Kalulu AAB": "/Android/kalulu_app.aab",
"Android Kalulu APK": "/Android/kalulu_app.apk",
"Android Kalulu APK 32 bits": "/Android/kalulu_app_32.apk",
"Windows Kalulu": "/Windows/Kalulu-Windows.zip",
"Linux Kalulu": "/Linux/Kalulu-Linux.zip",
# Apple in last because it's always the most complicated
#"iOS Kalulu": "/iOS/KaluluApp.ipa",
#"macOS Kalulu": "/macOS/Kalulu-macOS.dmg"
}
var presets: Dictionary = config["presets"]
for preset_name in presets.keys():
await get_tree().create_timer(1).timeout
var output_path: String = exportFolder + get_application_version_with_code() + presets[preset_name]
var output_path: String = version_folder + presets[preset_name]
print("Start exporting " + preset_name)
DirAccess.make_dir_recursive_absolute(output_path.get_base_dir())