Skip to content

Commit

Permalink
refs #373: Progress on migration script to update the SimpleClick GUI.
Browse files Browse the repository at this point in the history
The script is executed only if the project is using the SimpleClick
template, and it removes the InventoryBar, SettingsBar,
TextSettingsPopup and SoundSettingsPopup components.
  • Loading branch information
mapedorr committed Jan 11, 2025
1 parent a26e53f commit d474937
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
8 changes: 7 additions & 1 deletion addons/popochiu/migration/migration/popochiu_migration.gd
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func _init() -> void:
#endregion

#region Virtual ####################################################################################
func _is_migration_needed() -> bool:
return true


func _do_migration() -> bool:
return false

Expand Down Expand Up @@ -60,7 +64,9 @@ func get_migration_name() -> String:
## Returns [true] if the current Popochiu migration version is newer than the user's migration
## version, which means a migration is needed.
func is_migration_needed() -> bool:
return _version > PopochiuMigrationHelper.get_user_migration_version()
return (
_version > PopochiuMigrationHelper.get_user_migration_version() and _is_migration_needed()
)


## A helper function to display an error message in the [b]Output[/b] if there is an error doing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const STEPS = [
]



#region Virtual ####################################################################################
## This is code specific for this migration. This should return [code]true[/code] if the migration
## is successful. This is called from [method do_migration] which checks to make sure the migration
Expand All @@ -36,4 +35,5 @@ func _is_reload_required() -> bool:
#func _step1() -> Completion:
#return Completion.DONE


#endregion
71 changes: 71 additions & 0 deletions addons/popochiu/migration/migrations/popochiu_migration_4.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
@tool
class_name PopochiuMigration4
extends PopochiuMigration

# Update constant values to be correct for your migration
const VERSION = 4
const DESCRIPTION = "short description of migration goes here"
const STEPS = [
"Remove InventoryBar, SettingsBar, TextSettingsPopup and SoundSettingsPopup.",
"Add SimpleClickBar and SimpleClickSettingsPopup.",
"Update SaveAndLoadPopup.",
]



#region Virtual ####################################################################################
func _is_migration_needed() -> bool:
return PopochiuResources.get_data_value("ui", "template", "") == "SimpleClick"


func _do_migration() -> bool:
return await PopochiuMigrationHelper.execute_migration_steps(
self,
[
# Include the function names for each step here
_remove_non_used_components,
_step2,
_step3,
]
)


func _is_reload_required() -> bool:
return false


#endregion

#region Private ####################################################################################
func _remove_non_used_components() -> Completion:
var gui_scene := (ResourceLoader.load(
PopochiuResources.GUI_GAME_SCENE, "", ResourceLoader.CACHE_MODE_IGNORE
) as PackedScene).instantiate()
var nodes_to_remove: Array[Control] = []
for node_name: String in [
"InventoryBar", "SettingsBar", "TextSettingsPopup", "SoundSettingsPopup"
]:
var node: Node = gui_scene.find_child(node_name)
if is_instance_valid(node) and node is Control:
nodes_to_remove.append(node)
for node: Control in nodes_to_remove:
node.owner = null
node.queue_free()
await PopochiuEditorHelper.frame_processed()

var gui_packed_scene := PackedScene.new()
gui_packed_scene.pack(gui_scene)
ResourceSaver.save(gui_packed_scene, PopochiuResources.GUI_GAME_SCENE)

return Completion.DONE


func _step2() -> Completion:
return Completion.DONE


func _step3() -> Completion:
return Completion.DONE


#endregion

0 comments on commit d474937

Please sign in to comment.