Skip to content

Commit

Permalink
close issue #22
Browse files Browse the repository at this point in the history
  • Loading branch information
Lincoln-Ab committed Nov 19, 2024
1 parent 3c61540 commit 10258c9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
13 changes: 10 additions & 3 deletions scripts/scene_2d/level_builder.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const BUILDER_SAVE = preload("res://packed_scene/user_interface/BuilderSave.tscn
const PANEL = preload("res://assets/resources/themes/panel.tres")
const BUILDER_SELECTION = preload("res://packed_scene/user_interface/BuilderSelection.tscn")

var _level_name: String
var _level_data: LevelData
var _cell_collection: Dictionary
var _slider_collection: Dictionary
Expand Down Expand Up @@ -48,6 +49,9 @@ func _on_state_change(new_state: GlobalConst.GameState) -> void:
get_tree().root.add_child.call_deferred(builder_save)
builder_save.on_query_close.connect(_on_save_query_received)
GameManager.builder_save = builder_save
if _level_name != "":
var moves := String.num_int64(_level_data.moves_left)
GameManager.builder_save.initialize_info.call_deferred(_level_name,moves)

GlobalConst.GameState.BUILDER_RESIZE:
self.visible = true
Expand Down Expand Up @@ -97,9 +101,11 @@ func _on_state_change(new_state: GlobalConst.GameState) -> void:
self.visible = false


func construct_level(level_data: LevelData = null) -> void:
func construct_level(level_data: LevelData = null, level_name := "") -> void:
if level_data != null:
_level_data = level_data
if level_name != "":
_level_name = level_name

var half_grid := Vector2(_level_data.width, _level_data.height) * GlobalConst.CELL_SIZE / 2
var half_cell := Vector2.ONE * GlobalConst.CELL_SIZE / 2
Expand Down Expand Up @@ -248,10 +254,11 @@ func _on_slider_change(ref: BuilderSlider, data: SliderData) -> void:

func _on_save_query_received(is_persistent_level: bool, level_name: String, level_moves: int):
_level_data.moves_left = level_moves
_level_name = level_name
if is_persistent_level:
GameManager.save_persistent_level(level_name, _level_data)
GameManager.save_persistent_level(_level_name, _level_data)
else:
GameManager.save_custom_level(level_name, _level_data)
GameManager.save_custom_level(_level_name, _level_data)
_reset_builder_grid.call_deferred()


Expand Down
10 changes: 10 additions & 0 deletions scripts/user_interface/builder_save.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ func _ready():
_check_valid_info()


func initialize_info(old_name: String, old_moves: String) -> void:
level_name.text = old_name
moves.text = old_moves
level_name.caret_column = old_name.length()
moves.caret_column = old_moves.length()
_invalid_moves = false
_invalid_name = false
_check_valid_info()


func _on_state_change(new_state: GlobalConst.GameState) -> void:
match new_state:
GlobalConst.GameState.MAIN_MENU:
Expand Down
2 changes: 1 addition & 1 deletion scripts/user_interface/custom_level_inspect.gd
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func _on_build_btn_pressed() -> void:

GameManager.set_levels_context(GlobalConst.LevelGroup.CUSTOM)
var level_data: LevelData = GameManager.get_active_level(_level_name)
level_builder.construct_level.call_deferred(level_data.duplicate())
level_builder.construct_level.call_deferred(level_data.duplicate(), _level_name)

GameManager.change_state.call_deferred(GlobalConst.GameState.BUILDER_IDLE)

Expand Down
2 changes: 1 addition & 1 deletion scripts/user_interface/level_inspect.gd
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func _on_build_btn_pressed() -> void:

GameManager.set_levels_context(GlobalConst.LevelGroup.MAIN)
var level_data: LevelData = GameManager.get_active_level(_level_name)
level_builder.construct_level.call_deferred(level_data.duplicate())
level_builder.construct_level.call_deferred(level_data.duplicate(), _level_name)

GameManager.change_state.call_deferred(GlobalConst.GameState.BUILDER_IDLE)

Expand Down

0 comments on commit 10258c9

Please sign in to comment.