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,4 +1,4 @@
tool
@tool
class_name Taquin
extends Control
@ -19,12 +19,12 @@ const _state_transitions = {
const Piece = preload("res://src/Piece.tscn")
const Utils = preload("res://src/Utils.gd")
export var rows: int = NewGamePanel.normal_rows
export var columns: int = NewGamePanel.normal_columns
export var shuffle_iterations: int = NewGamePanel.normal_iterations
export var artwork_texture: Texture
export(State) var current_state = State.MAIN
export var autoload_fresh_game := true
@export var rows: int = NewGamePanel.normal_rows
@export var columns: int = NewGamePanel.normal_columns
@export var shuffle_iterations: int = NewGamePanel.normal_iterations
@export var artwork_texture: Texture2D
@export var current_state: State = State.MAIN
@export var autoload_fresh_game := true
var board_size := Vector2.ZERO
var interpiece := 4
@ -50,11 +50,11 @@ var current_touch_slide := Vector2.ZERO
var local_min_position := Vector2.ZERO
var local_max_position := Vector2.ZERO
var hint_active := false setget set_hint_active, get_hint_active
var hint_active := false: get = get_hint_active, set = set_hint_active
#var _artwork_path := NewGamePanel.default_artwork_path
onready var hint_tween = $HintTween
@onready var hint_tween = $HintTween
func position_for_index(index: Vector2, size: int) -> Vector2:
return padding + Vector2(index.x * (size + interpiece), index.y * (size + interpiece))
@ -73,13 +73,13 @@ func compute_padding(piece_size: int) -> Vector2:
func _ready() -> void:
$AnimationPlayer/MockPiece.visible = false
$Particles2D.emitting = false
$GPUParticles2D.emitting = false
board_size.x = min(rect_size.x, rect_size.y)
board_size.x = min(size.x, size.y)
board_size.y = board_size.x
$Background.rect_size = board_size
$Background.rect_position = (rect_size - $Background.rect_size) / 2
$Background.size = board_size
$Background.position = (size - $Background.size) / 2
$Background.set_anchors_preset(Control.PRESET_CENTER)
rng.randomize()
@ -347,11 +347,11 @@ func transition_to(state):
current_state = state
match current_state:
State.WINNING:
$Particles2D.emitting = true
$GPUParticles2D.emitting = true
set_pieces_reflection(true)
$Timer.start(-1)
State.GAME_OVER:
$Particles2D.emitting = false
$GPUParticles2D.emitting = false
$Timer.stop()
emit_signal("state_changed", previous_state, current_state)
@ -388,7 +388,7 @@ func load(saved_state) -> bool:
init(saved_state["pieces"], saved_state["hidden_piece"], artwork_texture)
return true
func init(pieces_order: Array, hidden_piece: int, artwork: Texture) -> void:
func init(pieces_order: Array, hidden_piece: int, artwork: Texture2D) -> void:
var piece_size: int = compute_piece_size()
padding = compute_padding(piece_size)
print("piece size: ", piece_size)
@ -403,7 +403,7 @@ func init(pieces_order: Array, hidden_piece: int, artwork: Texture) -> void:
for c in range(columns):
var pieces_row: Array = []
for r in range(rows):
var piece = Piece.instance()
var piece = Piece.instantiate()
# Uniforms
piece.size = piece_size
@ -433,7 +433,7 @@ func init(pieces_order: Array, hidden_piece: int, artwork: Texture) -> void:
pieces.append(pieces_row)
assert(missing_piece != null)
func new_game(columns: int, rows: int, shuffle_iterations: int, artwork_texture: Texture) -> void:
func new_game(columns: int, rows: int, shuffle_iterations: int, artwork_texture: Texture2D) -> void:
self.columns = columns
self.rows = rows
self.shuffle_iterations = shuffle_iterations