add edit panel

This commit is contained in:
Fabien Freling 2020-06-01 18:24:39 +02:00
parent 47234f1bc1
commit 89518f6aa5
7 changed files with 328 additions and 90 deletions

View file

@ -18,9 +18,9 @@ const _state_transitions = {
}
const Piece = preload("res://src/Piece.tscn")
export var rows: int = 4
export var columns: int = 4
export var difficulty: int = 10
export var rows: int = NewGamePanel.normal_rows
export var columns: int = NewGamePanel.normal_columns
export var shuffle_iterations: int = NewGamePanel.normal_iterations
export(State) var current_state = State.MAIN
var board_size := Vector2.ZERO
@ -80,7 +80,7 @@ func _ready() -> void:
rng.randomize()
new_game("normal")
new_game(NewGamePanel.normal_columns, NewGamePanel.normal_rows, NewGamePanel.normal_iterations)
func _input(event):
if $AnimationPlayer.is_playing():
@ -404,33 +404,17 @@ func init(pieces_order: Array, hidden_piece: int) -> void:
pieces.append(pieces_row)
assert(missing_piece != null)
func new_game(difficulty_mode: String) -> void:
print_debug("difficulty mode: ", difficulty_mode)
match difficulty_mode:
"easy":
rows = 3
columns = 3
difficulty = 4
"normal":
rows = 4
columns = 4
difficulty = 10
"hard":
rows = 5
columns = 5
difficulty = 30
_:
assert("Invalid value")
rows = 4
columns = 4
difficulty = 10
func new_game(columns: int, rows: int, shuffle_iterations: int) -> void:
self.columns = columns
self.rows = rows
self.shuffle_iterations = shuffle_iterations
print_debug("%d x %d with %d shuffles" % [columns, rows, shuffle_iterations])
var pieces_order: Array = []
for order in range(1, rows * columns + 1):
pieces_order.append(order)
var hidden_piece = rows * columns # Last piece is hidden
init(pieces_order, hidden_piece)
shuffle(difficulty, 0.0)
shuffle(shuffle_iterations, 0.0)
#
# Hints
@ -469,7 +453,11 @@ func _on_AnimationPlayer_animation_finished(anim_name):
func _on_NewGamePanel_start_triggered(preferences):
var difficulty_mode = preferences.get_value("game", "difficulty", "normal")
new_game(difficulty_mode)
print_debug("difficulty mode: ", difficulty_mode)
var columns = preferences.get_value("game", "columns", NewGamePanel.normal_columns)
var rows = preferences.get_value("game", "rows", NewGamePanel.normal_rows)
var shuffle_iterations = preferences.get_value("game", "shuffle_iterations", NewGamePanel.normal_iterations)
new_game(columns, rows, shuffle_iterations)
func _on_Hints_button_down():