fix: typo in size for screenshots, was 261, must be 216 height.
This commit is contained in:
parent
21bb98db8d
commit
5f610241e0
|
|
@ -87,8 +87,8 @@ func read_save_file():
|
||||||
|
|
||||||
if FileAccess.file_exists(filepath):
|
if FileAccess.file_exists(filepath):
|
||||||
print("Opening existing Savegame: %s" % filepath)
|
print("Opening existing Savegame: %s" % filepath)
|
||||||
var file = FileAccess.open(filepath, FileAccess.READ)
|
var file := FileAccess.open(filepath, FileAccess.READ)
|
||||||
var raw_json = FileAccess.get_file_as_string(filepath)
|
var raw_json := FileAccess.get_file_as_string(filepath)
|
||||||
file.close()
|
file.close()
|
||||||
var parsed: Dictionary = JSON.parse_string(raw_json)
|
var parsed: Dictionary = JSON.parse_string(raw_json)
|
||||||
|
|
||||||
|
|
@ -97,7 +97,7 @@ func read_save_file():
|
||||||
if FileAccess.file_exists("%s/thumbnails/%s.png" % [filepath.get_base_dir(), unique_save_name]):
|
if FileAccess.file_exists("%s/thumbnails/%s.png" % [filepath.get_base_dir(), unique_save_name]):
|
||||||
tmp_img = Image.load_from_file("%s/thumbnails/%s.png" % [filepath.get_base_dir(), unique_save_name])
|
tmp_img = Image.load_from_file("%s/thumbnails/%s.png" % [filepath.get_base_dir(), unique_save_name])
|
||||||
|
|
||||||
var are_types_valid = (
|
var are_types_valid := (
|
||||||
parsed["unique_save_name"] is String and
|
parsed["unique_save_name"] is String and
|
||||||
parsed["current_room"] is float and
|
parsed["current_room"] is float and
|
||||||
parsed["mementos_complete"] is float and
|
parsed["mementos_complete"] is float and
|
||||||
|
|
@ -162,7 +162,7 @@ func _get_save_dict() -> Dictionary:
|
||||||
"is_demo": is_demo
|
"is_demo": is_demo
|
||||||
}
|
}
|
||||||
|
|
||||||
func save_to_file(current_screen: Texture):
|
func save_to_file(screen_shot: Texture) -> void:
|
||||||
if filepath == "DEBUG":
|
if filepath == "DEBUG":
|
||||||
push_warning("Saving DEBUG save skipped. This is intentional.")
|
push_warning("Saving DEBUG save skipped. This is intentional.")
|
||||||
return
|
return
|
||||||
|
|
@ -171,21 +171,21 @@ func save_to_file(current_screen: Texture):
|
||||||
print("Not saving empty savegame.")
|
print("Not saving empty savegame.")
|
||||||
return
|
return
|
||||||
|
|
||||||
last_saved = Time.get_unix_time_from_system()
|
last_saved = int(Time.get_unix_time_from_system())
|
||||||
var thumbnail_image: Image = current_screen.get_image()
|
var thumbnail_image: Image = screen_shot.get_image()
|
||||||
thumbnail_image.convert(Image.Format.FORMAT_RGB8)
|
thumbnail_image.convert(Image.Format.FORMAT_RGB8)
|
||||||
thumbnail_image.linear_to_srgb()
|
thumbnail_image.linear_to_srgb()
|
||||||
thumbnail_image.resize(384, 261, Image.INTERPOLATE_LANCZOS) # nonexistent call in ViewportTexturew
|
thumbnail_image.resize(384, 216, Image.INTERPOLATE_LANCZOS) # nonexistent call in ViewportTexture
|
||||||
|
thumbnail_image.crop(384, 216)
|
||||||
|
|
||||||
var thumbnail_path: String = "%s/thumbnails/%s.png" % [filepath.get_base_dir(), unique_save_name]
|
var save_dir := DirAccess.open(filepath.get_base_dir())
|
||||||
var save_dir = DirAccess.open(filepath.get_base_dir())
|
|
||||||
if not save_dir.dir_exists("thumbnails"):
|
if not save_dir.dir_exists("thumbnails"):
|
||||||
save_dir.make_dir("thumbnails")
|
save_dir.make_dir("thumbnails")
|
||||||
|
|
||||||
thumbnail_image.save_png("%s/thumbnails/%s.png" % [filepath.get_base_dir(), unique_save_name])
|
var thumbnail_path: String = "%s/thumbnails/%s.png" % [filepath.get_base_dir(), unique_save_name]
|
||||||
#thumbnail_image.save_png("%s/test.png" % State.user_saves_path)
|
thumbnail_image.save_png(thumbnail_path)
|
||||||
print(filepath.get_base_dir())
|
print(filepath.get_base_dir())
|
||||||
var file = FileAccess.open(filepath, FileAccess.WRITE)
|
var file := FileAccess.open(filepath, FileAccess.WRITE)
|
||||||
file.store_string(JSON.stringify(_get_save_dict()))
|
file.store_string(JSON.stringify(_get_save_dict()))
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
|
|
@ -219,5 +219,5 @@ func validate_board_state() -> bool:
|
||||||
return false
|
return false
|
||||||
|
|
||||||
func parse_vec_from_string(string: String) -> Vector2:
|
func parse_vec_from_string(string: String) -> Vector2:
|
||||||
var string_array = string.replace("(", "").replace(")", "").split(", ")
|
var string_array := string.replace("(", "").replace(")", "").split(", ")
|
||||||
return Vector2(float(string_array[0]), float(string_array[1]))
|
return Vector2(float(string_array[0]), float(string_array[1]))
|
||||||
|
|
|
||||||
|
|
@ -45,16 +45,24 @@ func _ready() -> void:
|
||||||
print("main_menu.gd: ready()")
|
print("main_menu.gd: ready()")
|
||||||
_deactivate()
|
_deactivate()
|
||||||
|
|
||||||
save_game_handle.picked.connect(_on_save_picked)
|
|
||||||
|
|
||||||
continue_button.pressed.connect(_choose.bind("continue"))
|
continue_button.pressed.connect(_choose.bind("continue"))
|
||||||
new_game_button.pressed.connect(func(): save_game_handle.pick_save_slot(true))
|
new_game_button.pressed.connect(_start_new_game)
|
||||||
load_game_button.pressed.connect(func(): save_game_handle.pick_save_slot(false))
|
load_game_button.pressed.connect(_load_save_game)
|
||||||
load_game_button.disabled = not save_game_handle.has_existing_saves()
|
load_game_button.disabled = not save_game_handle.has_existing_saves()
|
||||||
settings_button.pressed.connect(settings_popup.show_settings)
|
settings_button.pressed.connect(settings_popup.show_settings)
|
||||||
credits_button.pressed.connect(_choose.bind("credits"))
|
credits_button.pressed.connect(_choose.bind("credits"))
|
||||||
quit_button.pressed.connect(get_tree().quit)
|
quit_button.pressed.connect(get_tree().quit)
|
||||||
|
|
||||||
|
func _start_new_game() -> void:
|
||||||
|
print("main_menu.gd: start_new_game()")
|
||||||
|
State.active_save_game = SaveGame.new()
|
||||||
|
_user_choice.emit("start_game")
|
||||||
|
|
||||||
|
func _load_save_game() -> void:
|
||||||
|
print("main_menu.gd: _load_save_game()")
|
||||||
|
var save: SaveGame = await save_game_handle.pick_save_slot()
|
||||||
|
_on_save_picked(save)
|
||||||
|
|
||||||
func _choose(choice: String) -> void:
|
func _choose(choice: String) -> void:
|
||||||
print("main_menu.gd: _choose(", choice, ")")
|
print("main_menu.gd: _choose(", choice, ")")
|
||||||
_user_choice.emit(choice)
|
_user_choice.emit(choice)
|
||||||
|
|
@ -77,5 +85,6 @@ func _deactivate() -> void:
|
||||||
|
|
||||||
func _on_save_picked(save: SaveGame):
|
func _on_save_picked(save: SaveGame):
|
||||||
print("main_menu.gd: _on_save_picked(", save, ")")
|
print("main_menu.gd: _on_save_picked(", save, ")")
|
||||||
State.active_save_game = save
|
if (save != null):
|
||||||
_user_choice.emit("start_game")
|
State.active_save_game = save
|
||||||
|
_user_choice.emit("start_game")
|
||||||
|
|
|
||||||
|
|
@ -435,22 +435,25 @@ visible = false
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
metadata/_tab_index = 4
|
metadata/_tab_index = 4
|
||||||
|
|
||||||
[node name="SaveGameList" type="CenterContainer" parent="."]
|
[node name="ColorRect" type="ColorRect" parent="."]
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
color = Color(0, 0, 0, 0.2509804)
|
||||||
|
|
||||||
|
[node name="SaveGameList" type="CenterContainer" parent="ColorRect"]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 15
|
anchors_preset = 15
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
offset_left = 40.0
|
|
||||||
offset_top = -45.0
|
|
||||||
offset_right = 40.0
|
|
||||||
offset_bottom = -45.0
|
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
mouse_filter = 2
|
mouse_filter = 2
|
||||||
script = ExtResource("8_o0cpj")
|
script = ExtResource("8_o0cpj")
|
||||||
saves = null
|
|
||||||
update_display = null
|
|
||||||
metadata/_custom_type_script = "uid://dugfwcvp7i01k"
|
metadata/_custom_type_script = "uid://dugfwcvp7i01k"
|
||||||
|
|
||||||
[node name="CenterContainer" type="CenterContainer" parent="."]
|
[node name="CenterContainer" type="CenterContainer" parent="."]
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,24 @@
|
||||||
class_name SaveGameList extends CenterContainer
|
class_name SaveGameList extends CenterContainer
|
||||||
|
|
||||||
signal picked(save_game: SaveGame)
|
signal _picked(save_game: SaveGame)
|
||||||
|
|
||||||
var has_stage: bool = false:
|
|
||||||
set(stage):
|
|
||||||
has_stage = stage
|
|
||||||
visible = stage
|
|
||||||
save_buttons[0].grab_focus()
|
|
||||||
|
|
||||||
@export var saves: Array[SaveGame]
|
@export var saves: Array[SaveGame]
|
||||||
var save_buttons: Array[SaveGameDisplay]
|
var save_buttons: Array[SaveGameDisplay]
|
||||||
@export var update_display: bool:
|
@export var update_display: bool:
|
||||||
set(value):
|
set(value):
|
||||||
load_games()
|
_load_games()
|
||||||
var scroll_container: ScrollContainer
|
var scroll_container: ScrollContainer
|
||||||
|
|
||||||
var override_save_slot: bool = false
|
|
||||||
|
|
||||||
func _validate_property(property: Dictionary) -> void:
|
func _validate_property(property: Dictionary) -> void:
|
||||||
if property.name == "saves":
|
if property.name == "saves":
|
||||||
property.usage = PROPERTY_USAGE_READ_ONLY + PROPERTY_USAGE_SCRIPT_VARIABLE + PROPERTY_USAGE_EDITOR
|
property.usage = PROPERTY_USAGE_READ_ONLY + PROPERTY_USAGE_SCRIPT_VARIABLE + PROPERTY_USAGE_EDITOR
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
get_parent_control().visible = false
|
||||||
|
_load_games()
|
||||||
|
|
||||||
|
func _ensure_directory() -> void:
|
||||||
var dir := DirAccess.open(State.user_saves_path)
|
var dir := DirAccess.open(State.user_saves_path)
|
||||||
|
|
||||||
# Create dir if needed.
|
# Create dir if needed.
|
||||||
|
|
@ -33,12 +29,9 @@ func _ready() -> void:
|
||||||
if DirAccess.get_open_error() != OK:
|
if DirAccess.get_open_error() != OK:
|
||||||
printerr("Error while opening User Save Directory: %s" % error_string(DirAccess.get_open_error()))
|
printerr("Error while opening User Save Directory: %s" % error_string(DirAccess.get_open_error()))
|
||||||
|
|
||||||
load_games()
|
|
||||||
|
|
||||||
for i in range(save_buttons.size()):
|
func _load_games():
|
||||||
save_buttons[i].pressed.connect(func(): picked.emit(saves[i]))
|
_ensure_directory()
|
||||||
|
|
||||||
func load_games():
|
|
||||||
saves = []
|
saves = []
|
||||||
var save_game_dir := DirAccess.open(State.user_saves_path)
|
var save_game_dir := DirAccess.open(State.user_saves_path)
|
||||||
var filepaths: PackedStringArray = save_game_dir.get_files()
|
var filepaths: PackedStringArray = save_game_dir.get_files()
|
||||||
|
|
@ -49,7 +42,21 @@ func load_games():
|
||||||
|
|
||||||
saves.append(SaveGame.new())
|
saves.append(SaveGame.new())
|
||||||
|
|
||||||
#purging the current state
|
_sort_saves()
|
||||||
|
_rebuild_buttons()
|
||||||
|
|
||||||
|
|
||||||
|
func _sort_saves() -> void:
|
||||||
|
saves.sort_custom(func(a: SaveGame, b: SaveGame) -> int:
|
||||||
|
if a.last_saved > b.last_saved:
|
||||||
|
return -1
|
||||||
|
elif a.last_saved < b.last_saved:
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
)
|
||||||
|
|
||||||
|
func _rebuild_buttons() -> void:
|
||||||
save_buttons = []
|
save_buttons = []
|
||||||
if scroll_container != null:
|
if scroll_container != null:
|
||||||
scroll_container.queue_free()
|
scroll_container.queue_free()
|
||||||
|
|
@ -70,38 +77,33 @@ func load_games():
|
||||||
save_buttons.append(new_button)
|
save_buttons.append(new_button)
|
||||||
new_button.pressed.connect(func(): _on_game_picked(i))
|
new_button.pressed.connect(func(): _on_game_picked(i))
|
||||||
|
|
||||||
func _on_game_picked(id: int):
|
|
||||||
if override_save_slot:
|
|
||||||
if saves[id].current_room == 0:
|
|
||||||
picked.emit(id)
|
|
||||||
else:
|
|
||||||
pass
|
|
||||||
#picked.emit(id)
|
|
||||||
#$Popup.show() #FIXME: This popup is missing
|
|
||||||
else:
|
|
||||||
picked.emit(id)
|
|
||||||
|
|
||||||
# This function is called when the user us supposed to choose a slot to load or create a new game.
|
func _on_game_picked(id: int) -> void:
|
||||||
func pick_save_slot(create_new_game: bool):
|
_picked.emit(saves[id] if id >= 0 && id < saves.size() else SaveGame.new())
|
||||||
if saves.size() == 1:
|
|
||||||
picked.emit(saves[0])
|
|
||||||
else:
|
|
||||||
State.take_stage(self)
|
|
||||||
self.override_save_slot = create_new_game
|
|
||||||
|
|
||||||
func get_most_recent_save() -> SaveGame:
|
func get_most_recent_save() -> SaveGame:
|
||||||
var most_recent_time := 0.0
|
_sort_saves()
|
||||||
var most_recent_index:int = 0
|
return saves[0] if saves.size() > 0 else SaveGame.new()
|
||||||
for i in range(saves.size()):
|
|
||||||
if saves[i].last_saved > most_recent_time and not saves[i].current_room == 0:
|
|
||||||
most_recent_index = i
|
|
||||||
most_recent_time = saves[i].last_saved
|
|
||||||
|
|
||||||
return saves[most_recent_index] if most_recent_time > 0 else SaveGame.new()
|
|
||||||
|
|
||||||
func has_existing_saves() -> bool:
|
func has_existing_saves() -> bool:
|
||||||
return saves.size() > 1
|
return saves.size() > 1
|
||||||
|
|
||||||
func _input(event: InputEvent) -> void:
|
func _input(event: InputEvent) -> void:
|
||||||
if event.is_action_pressed("ui_cancel"):
|
if event.is_action_pressed("ui_cancel"):
|
||||||
State.leave_stage(self)
|
cancel()
|
||||||
|
|
||||||
|
func cancel()->void:
|
||||||
|
get_parent_control().visible = false
|
||||||
|
visible = false
|
||||||
|
_on_game_picked(-1)
|
||||||
|
|
||||||
|
# This function is called when the user us supposed to choose a slot to load or create a new game.
|
||||||
|
func pick_save_slot() -> SaveGame:
|
||||||
|
get_parent_control().visible = true
|
||||||
|
visible = true
|
||||||
|
save_buttons[0].grab_focus()
|
||||||
|
var result = await _picked
|
||||||
|
get_parent_control().visible = false
|
||||||
|
visible = false
|
||||||
|
return result
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue