From 73411a44f3091ce55ace1624a23c3c58347c326a Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Wed, 3 Dec 2025 22:24:08 +0100 Subject: [PATCH] more godot 4.5 transition --- src/DepthButton.gd | 8 ++++---- src/FileList.gd | 5 +++-- src/Main.gd | 6 +++--- src/Main.tscn | 1 - src/NewGamePanel.gd | 15 ++++++--------- src/Taquin.gd | 12 ++++++------ src/Utils.gd | 5 +---- 7 files changed, 23 insertions(+), 29 deletions(-) diff --git a/src/DepthButton.gd b/src/DepthButton.gd index 2bbbf74..b00183b 100644 --- a/src/DepthButton.gd +++ b/src/DepthButton.gd @@ -14,7 +14,7 @@ signal toggled() @export var toggle_mode := false @export var group: ButtonGroup -var pressed : get = is_pressed, set = set_pressed +var pressed_state : get = is_pressed, set = set_pressed var _pressed_depth := 4 var _toggled := false @@ -29,13 +29,13 @@ func _ready(): button.text = text button.offset_bottom = -depth button.toggle_mode = toggle_mode - button.group = group + #button.group = group button.size.y = size.y - depth # # Styles # - var background_style := Styles.get_stylebox_flat(background.get_stylebox("panel", "panel"), "button_background", corner_type) + var background_style := Styles.get_stylebox_flat(background.get_theme_stylebox("panel", "panel"), "button_background", corner_type) background_style.set_bg_color(Color(0.73, 0.35, 0.13)) background.set('theme_override_styles/panel', background_style) match corner_type: @@ -54,7 +54,7 @@ func _ready(): for style_name in ["normal", "hover", "focus", "pressed"]: - var original_style = button.get_stylebox(style_name) + var original_style = button.get_theme_stylebox(style_name) # print_debug("style for ", style_name, ": ", original_style) var stylebox := Styles.get_stylebox_flat(original_style, style_name, corner_type) button.set("custom_styles/%s" % style_name, stylebox) diff --git a/src/FileList.gd b/src/FileList.gd index 83f40f3..cca839c 100644 --- a/src/FileList.gd +++ b/src/FileList.gd @@ -5,7 +5,7 @@ signal texture_selected(texture) var _parent_display_name := "" var _sep := "/" -var _dir := DirAccess.new() +var _dir : DirAccess @export var root_dir: String @export var walkable := false @@ -21,7 +21,8 @@ func populate(dir: String) -> void: print_debug("populate ", dir) clear() - if _dir.change_dir(dir) != OK: + _dir = DirAccess.open(dir) + if !_dir: print_debug("Cannot open path ", dir) assert(false) return diff --git a/src/Main.gd b/src/Main.gd index 0fde734..a4eea36 100644 --- a/src/Main.gd +++ b/src/Main.gd @@ -35,7 +35,7 @@ func layout_reflow(): # https://docs.godotengine.org/en/stable/tutorials/io/saving_games.html func save_game(): - var save_game = FileAccess.open("user://savegame.save", FileAccess.WRITE) + var save_file = FileAccess.open("user://savegame.save", FileAccess.WRITE) var save_nodes = get_tree().get_nodes_in_group("Persist") for node in save_nodes: # Check the node has a save function @@ -50,8 +50,8 @@ func save_game(): node_data["path"] = node.get_path() # Store the save dictionary as a new line in the save file - save_game.store_line(JSON.new().stringify(node_data)) - save_game.close() + save_file.store_line(JSON.stringify(node_data)) + save_file.close() func load_game(): if not FileAccess.file_exists("user://savegame.save"): diff --git a/src/Main.tscn b/src/Main.tscn index 2e85e2c..f04a4a7 100644 --- a/src/Main.tscn +++ b/src/Main.tscn @@ -57,7 +57,6 @@ layout_mode = 2 text = "Hints" [node name="NewGamePanel" parent="." instance=ExtResource("3")] -pivot_offset = Vector2(4, 4) [connection signal="about_to_popup" from="NewGamePanel" to="." method="_on_NewGamePanel_about_to_show"] [connection signal="popup_hide" from="NewGamePanel" to="." method="_on_NewGamePanel_popup_hide"] diff --git a/src/NewGamePanel.gd b/src/NewGamePanel.gd index f1455d7..0b26af9 100644 --- a/src/NewGamePanel.gd +++ b/src/NewGamePanel.gd @@ -48,12 +48,12 @@ func _init(): var err = preferences.load(pref_path) func _ready(): - pivot_offset = size / 2 + #pivot_offset = size / 2 assert(popup.theme != null) - var popup_style : = popup.get_stylebox("panel", "PopupPanel") as StyleBoxFlat + var popup_style : = popup.get_theme_stylebox("panel", "PopupPanel") as StyleBoxFlat assert(popup_style != null) - var panel_style := panel.get_stylebox("panel", "Panel") as StyleBoxFlat + var panel_style := panel.get_theme_stylebox("panel", "Panel") as StyleBoxFlat assert(panel_style != null) var modified_panel_style = panel_style.duplicate() modified_panel_style.corner_radius_bottom_left = popup_style.corner_radius_bottom_left @@ -67,7 +67,7 @@ func _ready(): edit_panel.hide() var button_max_width: int = $EditPanel/VBoxContainer.size.x / 3.5 - var button_width := min(200, button_max_width) + var button_width: int = min(200, button_max_width) print_debug("button max width = ", button_max_width) easy_button.custom_minimum_size.x = button_width normal_button.custom_minimum_size.x = button_width @@ -131,7 +131,7 @@ func _update_description(): # $Panel/Description.text = "Dimension: %d x %d\nIterations: %d" % [columns, rows, iterations] desc.clear() - desc.push_align(RichTextLabel.ALIGNMENT_CENTER) + desc.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER desc.add_text("Board: ") desc.push_bold() @@ -155,11 +155,8 @@ func _update_description(): func _set_artwork(tex: Texture2D) -> void: preview.texture = tex - var file = File.new() - if file.open(cached_artwork_path, File.WRITE) != OK: - assert(false) + var file = FileAccess.open(cached_artwork_path, FileAccess.WRITE) file.store_var(tex.get_data(), true) - file.close() # # Signals diff --git a/src/Taquin.gd b/src/Taquin.gd index e9ba82a..f56d3f3 100644 --- a/src/Taquin.gd +++ b/src/Taquin.gd @@ -87,7 +87,7 @@ func _ready() -> void: if autoload_fresh_game: start_fresh() if artwork_texture == null: - artwork_texture = NewGamePanel.default_artwork_texture + artwork_texture = $NewGamePanel.default_artwork_texture new_game(NewGamePanel.normal_columns, NewGamePanel.normal_rows, NewGamePanel.normal_iterations, artwork_texture) func _unhandled_input(event): @@ -98,7 +98,7 @@ func _gui_input(event): if $AnimationPlayer.is_playing(): # Disable input during animation return - if hint_active or hint_tween.is_active(): + if hint_active or hint_tween: return match current_state: @@ -238,7 +238,7 @@ func move_piece(direction, speed: float) -> bool: assert(moving_piece_animation != null) assert(moving_piece_animation.get_track_count() > 0) - var moving_piece_track_index: int = moving_piece_animation.find_track(current_animation_path) + var moving_piece_track_index: int = moving_piece_animation.find_track(current_animation_path, Animation.TYPE_ANIMATION) assert(moving_piece_track_index != -1) @@ -273,7 +273,7 @@ func commit_slide(audio: bool, check_solved: bool): ensure_validity() reset_slide() - update() + #update() if check_solved: check_solved() @@ -447,8 +447,8 @@ func new_game(columns: int, rows: int, shuffle_iterations: int, artwork_texture: func start_fresh(): if artwork_texture == null: - print_debug("Load texture from: ", NewGamePanel.default_artwork_path) - artwork_texture = Utils.load_texture_from_path(NewGamePanel.default_artwork_path) + print_debug("Load texture from: ", $NewGamePanel.default_artwork_path) + artwork_texture = Utils.load_texture_from_path($NewGamePanel.default_artwork_path) new_game(NewGamePanel.normal_columns, NewGamePanel.normal_rows, NewGamePanel.normal_iterations, artwork_texture) diff --git a/src/Utils.gd b/src/Utils.gd index 35796f8..3f9cf9a 100644 --- a/src/Utils.gd +++ b/src/Utils.gd @@ -8,11 +8,8 @@ static func load_texture_from_path(path: String) -> Texture2D: return texture static func deserialize_texture(path: String) -> Texture2D: - var file := File.new() - if file.open(path, File.READ) != OK: - return null + var file := FileAccess.open(path, FileAccess.READ) var img: Image = file.get_var(true) - file.close() var img_tex = ImageTexture.new() img_tex.create_from_image(img) return img_tex