Skip to content

Commit

Permalink
refs #373: Update migration script to add new components and update t…
Browse files Browse the repository at this point in the history
…he SaveAndLoadPopup.

The new Simple Click GUI uses the SimpleClickBar and the
SimpleClickPopup components. Instead of adding a new migration step, the
SaveAndLoadPopup is also removed in the first step and then added in the
second one.

- **upd** Remove the `@onready` vars in the Simple Click GUI to access
  the SaveAndLoadPopup, HistoryPopup, and QuitPopup since it is no
  longer used to open those popups.
  • Loading branch information
mapedorr committed Jan 17, 2025
1 parent 5d177dc commit 49c4e3a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ extends PopochiuGraphicInterface
## inventory bar is in the top left corner of the screen, and the settings bar is in the top right
## corner of the screen.

@onready var save_and_load_popup: Control = %SaveAndLoadPopup
@onready var history_popup: Control = %HistoryPopup
@onready var quit_popup: Control = %QuitPopup


#region Godot ######################################################################################
func _ready() -> void:
Expand Down
84 changes: 63 additions & 21 deletions addons/popochiu/migration/migrations/popochiu_migration_4.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,42 @@ extends PopochiuMigration
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.",
"Remove InventoryBar, SettingsBar, TextSettingsPopup, SoundSettingsPopup, and SaveAndLoadPopup",
"Add SimpleClickBar, SimpleClickSettingsPopup, and SaveAndLoadPopup (updated).",
]

const ADDON_SIMPLE_CLICK_BAR = (
PopochiuResources.GUI_TEMPLATES_FOLDER +
"simple_click/components/simple_click_bar/simple_click_bar.tscn"
)
const ADDON_SIMPLE_CLICK_POPUP = (
PopochiuResources.GUI_TEMPLATES_FOLDER +
"simple_click/components/simple_click_settings_popup/simple_click_settings_popup.tscn"
)
const ADDON_SAVE_AND_LOAD_POPUP = (
PopochiuResources.GUI_ADDON_FOLDER +
"components/popups/save_and_load_popup/save_and_load_popup.tscn"
)

var _gui_templates_helper := preload(
"res://addons/popochiu/editor/helpers/popochiu_gui_templates_helper.gd"
)
var _gui_scene: PopochiuGraphicInterface = null


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

_gui_scene = (ResourceLoader.load(
PopochiuResources.GUI_GAME_SCENE, "", ResourceLoader.CACHE_MODE_IGNORE
) as PackedScene).instantiate()

# If the GUI already has the SimpleClickBar component, then the migration is not needed
if is_instance_valid(_gui_scene.find_child("SimpleClickBar")):
return false

return true


func _do_migration() -> bool:
Expand All @@ -24,8 +50,7 @@ func _do_migration() -> bool:
[
# Include the function names for each step here
_remove_non_used_components,
_step2,
_step3,
_add_new_components,
]
)

Expand All @@ -38,33 +63,50 @@ func _is_reload_required() -> bool:

#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 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"
"InventoryBar", "SettingsBar", "TextSettingsPopup", "SoundSettingsPopup", "SaveAndLoadPopup"
]:
var node: Node = gui_scene.find_child(node_name)
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:
func _add_new_components() -> Completion:
# Copy the SimpleClickBar component to the game's GUI
var component_path := await _gui_templates_helper.copy_component(ADDON_SIMPLE_CLICK_BAR)
var component_scene: Control = (load(component_path) as PackedScene).instantiate()
_gui_scene.add_child(component_scene)
component_scene.owner = _gui_scene
_gui_scene.move_child(component_scene, 1)

# Copy the SimpleClickPopup component to the game's GUI
component_path = await _gui_templates_helper.copy_component(ADDON_SIMPLE_CLICK_POPUP)
component_scene = (load(component_path) as PackedScene).instantiate()
_gui_scene.get_node("Popups").add_child(component_scene)
component_scene.owner = _gui_scene
_gui_scene.get_node("Popups").move_child(component_scene, 0)

# Copy the SaveAndLoadPopup component to the game's GUI
component_path = await _gui_templates_helper.copy_component(ADDON_SAVE_AND_LOAD_POPUP)
component_scene = (load(component_path) as PackedScene).instantiate()
_gui_scene.get_node("Popups").add_child(component_scene)
component_scene.owner = _gui_scene
_gui_scene.get_node("Popups").move_child(component_scene, 1)

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

return Completion.DONE


Expand Down

0 comments on commit 49c4e3a

Please sign in to comment.