update to godot v4

This commit is contained in:
Fabien Freling 2024-09-02 13:13:14 +02:00
parent 95c7976f14
commit 67e71181f6
35 changed files with 795 additions and 494 deletions

View file

@ -1,12 +1,12 @@
extends Control
onready var container = $GridContainer
onready var taquin = $GridContainer/Taquin
@onready var container = $GridContainer
@onready var taquin = $GridContainer/Taquin
var _first_popup_call := true
func _ready():
taquin.rect_min_size = get_viewport().get_visible_rect().size * (2.0 / 3.0)
taquin.custom_minimum_size = get_viewport().get_visible_rect().size * (2.0 / 3.0)
layout_reflow()
if not load_game():
start_fresh()
@ -25,7 +25,7 @@ func layout_reflow():
if container == null:
return
if container.rect_size.x < container.rect_size.y:
if container.size.x < container.size.y:
# portrait
container.columns = 1
else:
@ -51,7 +51,7 @@ 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(to_json(node_data))
save_game.store_line(JSON.new().stringify(node_data))
save_game.close()
func load_game():
@ -62,9 +62,11 @@ func load_game():
# Load the file line by line and process that dictionary to restore
# the object it represents.
save_game.open("user://savegame.save", File.READ)
while save_game.get_position() < save_game.get_len():
while save_game.get_position() < save_game.get_length():
# Get the saved dictionary from the next line in the save file
var node_data = parse_json(save_game.get_line())
var test_json_conv = JSON.new()
test_json_conv.parse(save_game.get_line())
var node_data = test_json_conv.get_data()
# Call the node's save function
var node = get_node(node_data["path"])
@ -92,7 +94,7 @@ func _on_Taquin_state_changed(previous, new):
pass
func _on_New_game_pressed():
$NewGamePanel.rect_position = Vector2.ZERO
$NewGamePanel.position = Vector2.ZERO
if _first_popup_call:
# We only call popup_centered() once, otherwise the popup shifts to the
# bottom right after each call.