Save/Load System done
This commit is contained in:
+125
-66
@@ -35,11 +35,13 @@ func _ready() -> void:
|
||||
|
||||
#Connecting Signals
|
||||
title_screen.connect("new_game_pressed", self._on_new_game_pressed)
|
||||
title_screen.connect("load_pressed", self._on_load_pressed)
|
||||
title_screen.connect("settings_pressed", self._on_settings_pressed)
|
||||
UI.connect("save_slot_pressed", self._on_save_slot_pressed)
|
||||
UI.connect("load_slot_pressed", self._on_load_slot_pressed)
|
||||
UI.connect("main_menu_pressed", self._on_main_menu_pressed)
|
||||
screening_desk.connect("recovery_pressed", self._on_recovery_pressed)
|
||||
|
||||
pass
|
||||
#Updating Save/Load Slots Information based on Existing Saves
|
||||
update_slots()
|
||||
|
||||
|
||||
|
||||
@@ -51,35 +53,17 @@ func _process(delta: float) -> void:
|
||||
|
||||
# Starts a new game
|
||||
func _on_new_game_pressed():
|
||||
|
||||
#Offering to skip Introduction
|
||||
UI.confirmation_text.text = "[center]Do you wish to skip the introduction ?[/center]"
|
||||
UI.confirmation_yes.pressed.connect(skip_intro, CONNECT_ONE_SHOT)
|
||||
UI.confirmation_no.pressed.connect(play_intro, CONNECT_ONE_SHOT)
|
||||
UI.confirmation_dialog.show()
|
||||
TransitionScreen.mask.visible = true
|
||||
|
||||
|
||||
|
||||
#Skips the introduction
|
||||
func skip_intro():
|
||||
|
||||
#Disconnecting the other Signal from the Confirmation Dialogue
|
||||
UI.confirmation_no.disconnect("pressed", play_intro)
|
||||
|
||||
#Starting Day Loop
|
||||
start_day_loop()
|
||||
Globals.day_count = 1
|
||||
#Offering to skip the introduction
|
||||
var choice_text = "[center]Do you wish to skip the introduction ?[/center]"
|
||||
UI.ask_confirmation(start_day, play_intro, choice_text)
|
||||
|
||||
|
||||
|
||||
#Plays the entire introduction
|
||||
func play_intro():
|
||||
|
||||
#Disconnecting the other Signal from the Confirmation Dialogue
|
||||
UI.confirmation_yes.disconnect("pressed", skip_intro)
|
||||
|
||||
#Playing the Intro
|
||||
#Text Slides
|
||||
#Text Slides
|
||||
var text_container = $TextScreens/MarginContainer/IntroBoxContainer/TextContainer
|
||||
|
||||
TransitionScreen.transition("big", [$TitleScreen], [$TextScreens, $TextScreens/MarginContainer/IntroBoxContainer/Header, text_container.get_child(0), UI, UI.get_node("UI/SkipContainer")])
|
||||
@@ -88,74 +72,71 @@ func play_intro():
|
||||
TransitionScreen.transition("small", [text_container.get_child(i)], [text_container.get_child(i+1)])
|
||||
await UI.next_slide
|
||||
|
||||
#Meeting Room Dialogue
|
||||
#Meeting room dialogue
|
||||
TransitionScreen.transition("big", [$TextScreens, $TextScreens/MarginContainer, text_container.get_child(4), UI, UI.get_node("UI/SkipContainer")], [$DialogueScreens])
|
||||
await TransitionScreen.transition_finished
|
||||
|
||||
DialogueManager.show_dialogue_balloon(Globals.dialogue_intro, "start")
|
||||
await DialogueManager.dialogue_ended
|
||||
|
||||
#Starting Day Loop
|
||||
start_day_loop()
|
||||
#Starting the day
|
||||
start_day()
|
||||
|
||||
|
||||
|
||||
#Starts the Day Loop
|
||||
func start_day_loop():
|
||||
#Starts the day
|
||||
func start_day():
|
||||
|
||||
#Transitioning to Day Screen
|
||||
#Transitioning to day screen
|
||||
$TextScreens/Day.text = "[center]DAY " + str(Globals.day_count) + "[/center]"
|
||||
TransitionScreen.transition("big", [$DialogueScreens, $TitleScreen], [$TextScreens, $TextScreens/Day])
|
||||
|
||||
var scenes_to_hide: Array[Node] = [$DialogueScreens, $TitleScreen, $Bedroom]
|
||||
var scenes_to_show: Array[Node] = [$TextScreens, $TextScreens/Day]
|
||||
TransitionScreen.transition("big", scenes_to_hide, scenes_to_show)
|
||||
await TransitionScreen.transition_finished
|
||||
await get_tree().create_timer(3.0).timeout
|
||||
|
||||
#Transitioning to the Screening Desk
|
||||
#Transitioning to the screening desk
|
||||
TransitionScreen.transition("big", [$TextScreens, $TextScreens/Day], [$ScreeningDesk, $ScreeningDesk.alone_controls, UI, UI.get_node("UI/UpperContainer")])
|
||||
await TransitionScreen.transition_finished
|
||||
|
||||
#Finally starting the Game Loop
|
||||
#Setting up new patient
|
||||
$ScreeningDesk.new_patient(Globals.patient_id)
|
||||
|
||||
|
||||
|
||||
#Ends the day and starts the next one
|
||||
func _on_recovery_pressed():
|
||||
|
||||
var scenes_to_hide = [$ScreeningDesk.end_of_day_controls, $ScreeningDesk]
|
||||
var scenes_to_show:Array[Node] = [$Bedroom]
|
||||
#Transitioning to the bedroom
|
||||
var scenes_to_hide: Array[Node] = [$ScreeningDesk.end_of_day_controls, $ScreeningDesk]
|
||||
var scenes_to_show: Array[Node] = [$Bedroom]
|
||||
TransitionScreen.transition("big", scenes_to_hide, scenes_to_show)
|
||||
await TransitionScreen.transition_finished
|
||||
|
||||
#End of day dialogue
|
||||
DialogueManager.show_dialogue_balloon(Globals.dialogue_recovery, "end_of_day_" + str(Globals.day_count))
|
||||
await DialogueManager.dialogue_ended
|
||||
|
||||
#Start of the next day
|
||||
Globals.day_count += 1
|
||||
|
||||
#Transitioning to Day Screen
|
||||
$TextScreens/Day.text = "[center]DAY " + str(Globals.day_count) + "[/center]"
|
||||
scenes_to_hide = [$Bedroom]
|
||||
scenes_to_show = [$TextScreens, $TextScreens/Day]
|
||||
TransitionScreen.transition("big", scenes_to_hide, scenes_to_show)
|
||||
await TransitionScreen.transition_finished
|
||||
await get_tree().create_timer(3.0).timeout
|
||||
|
||||
#Transitioning to Screening Desk
|
||||
scenes_to_hide = scenes_to_show
|
||||
scenes_to_show = [$ScreeningDesk, $ScreeningDesk.alone_controls]
|
||||
TransitionScreen.transition("big", scenes_to_hide, scenes_to_show)
|
||||
await TransitionScreen.transition_finished
|
||||
$ScreeningDesk.new_patient(Globals.patient_id)
|
||||
start_day()
|
||||
|
||||
|
||||
|
||||
func save_game(save_slot:String):
|
||||
#Saves game state on the selected save slot
|
||||
func save_game(save_slot_number:int):
|
||||
|
||||
#Setting up save data
|
||||
var save_data = {
|
||||
"day_count": Globals.day_count,
|
||||
"patient_count": Globals.patient_count,
|
||||
"patient_id": Globals.patient_id
|
||||
"patient_id": Globals.patient_id,
|
||||
"save_date": Globals.get_save_date()
|
||||
}
|
||||
|
||||
var file = FileAccess.open("res://Saves/save_" + save_slot + ".json", FileAccess.WRITE)
|
||||
|
||||
#Creating save file
|
||||
var file = FileAccess.open("res://Saves/save_" + str(save_slot_number) + ".json", FileAccess.WRITE)
|
||||
if file:
|
||||
var json_string = JSON.stringify(save_data)
|
||||
print(json_string)
|
||||
@@ -164,26 +145,104 @@ func save_game(save_slot:String):
|
||||
print("Game saved successfully!")
|
||||
else:
|
||||
print("Failed to open file for saving.")
|
||||
|
||||
|
||||
|
||||
func load_game(save_slot:String):
|
||||
|
||||
var file = FileAccess.open("res://Saves/save_" + save_slot + ".json", FileAccess.READ)
|
||||
#Updating save/load slots information
|
||||
var save_slot_path = "UI/Save/MarginContainer/VBoxContainer/SaveSlot" + str(save_slot_number)
|
||||
var load_slot_path = "UI/Load/MarginContainer/VBoxContainer/LoadSlot" + str(save_slot_number)
|
||||
var save_slot = UI.get_node(save_slot_path)
|
||||
var load_slot = UI.get_node(load_slot_path)
|
||||
|
||||
save_slot.text = "DAY " + str(save_data["day_count"]) + ", PATIENT " + str(save_data["patient_count"]) + "\nSAVE DATE : " + str(save_data["save_date"])
|
||||
load_slot.text = save_slot.text
|
||||
|
||||
|
||||
|
||||
#Loads save file from the selected load slot
|
||||
func load_game(load_slot_number:int):
|
||||
|
||||
#Hiding loading menus and masks
|
||||
TransitionScreen.mask.visible = false
|
||||
UI.get_node("UI/Load").hide()
|
||||
UI.get_node("UI/LoadTitle").hide()
|
||||
UI.get_node("UI/Menu").hide()
|
||||
|
||||
#Opening save file
|
||||
var file = FileAccess.open("res://Saves/save_" + str(load_slot_number) + ".json", FileAccess.READ)
|
||||
if file:
|
||||
var json_string = file.get_as_text()
|
||||
file.close()
|
||||
var load_data = JSON.parse_string(json_string)
|
||||
|
||||
if load_data == OK:
|
||||
if typeof(load_data) == 27: #Checks if loaded data is a Dictionary
|
||||
print(load_data)
|
||||
Globals.day_count = load_data["day_count"]
|
||||
Globals.patient_count = load_data["patient_count"]
|
||||
Globals.patient_id = load_data["patient_id"]
|
||||
else:
|
||||
print("Failed to parse Loading Data.")
|
||||
|
||||
|
||||
|
||||
func _on_save_pressed():
|
||||
|
||||
#Transitioning to loaded Save
|
||||
var scenes_to_hide = [$TitleScreen, $Bedroom, $TextScreens, $TextScreens/Day, $ScreeningDesk.patient_controls, $ScreeningDesk.end_of_day_controls, $ScreeningDesk.patient_texture, $ScreeningDesk.panel_container, $ScreeningDesk.face_zoom] + $ScreeningDesk.margin_container.get_children()
|
||||
var scenes_to_show = [$ScreeningDesk, $ScreeningDesk.alone_controls, UI.get_node("UI/UpperContainer")]
|
||||
TransitionScreen.transition("big", scenes_to_hide, scenes_to_show)
|
||||
await TransitionScreen.transition_finished
|
||||
$ScreeningDesk.new_patient(Globals.patient_id)
|
||||
|
||||
|
||||
|
||||
func _on_save_slot_pressed(save_slot):
|
||||
save_game(save_slot)
|
||||
|
||||
|
||||
|
||||
func _on_load_slot_pressed(load_slot):
|
||||
load_game(load_slot)
|
||||
|
||||
|
||||
|
||||
func _on_main_menu_pressed():
|
||||
|
||||
#Hiding menu
|
||||
UI.get_node("UI/Menu").hide()
|
||||
UI.get_node("UI/UpperContainer").hide()
|
||||
TransitionScreen.mask.visible = false
|
||||
|
||||
#Going back to main menu
|
||||
var scenes_to_hide = [$ScreeningDesk, $Bedroom, $TextScreens, $TextScreens/Day, $ScreeningDesk.patient_controls, $ScreeningDesk.end_of_day_controls, $ScreeningDesk.patient_texture, $ScreeningDesk.panel_container, $ScreeningDesk.face_zoom] + $ScreeningDesk.margin_container.get_children()
|
||||
var scenes_to_show = [$TitleScreen]
|
||||
TransitionScreen.transition("big", scenes_to_hide, scenes_to_show)
|
||||
await TransitionScreen.transition_finished
|
||||
|
||||
|
||||
|
||||
#Updates Save/Load Slots based on Existing Saves
|
||||
func update_slots():
|
||||
|
||||
#Loops over the 4 save/load slots
|
||||
for save_number in range(1, 5):
|
||||
|
||||
#Retrieves save and load slots
|
||||
var save_slot_path = "UI/Save/MarginContainer/VBoxContainer/SaveSlot" + str(save_number)
|
||||
var load_slot_path = "UI/Load/MarginContainer/VBoxContainer/LoadSlot" + str(save_number)
|
||||
var load_title_slot_path = "UI/LoadTitle/MarginContainer/VBoxContainer/LoadSlot" + str(save_number)
|
||||
var save_slot = UI.get_node(save_slot_path)
|
||||
var load_slot = UI.get_node(load_slot_path)
|
||||
var load_title_slot = UI.get_node(load_title_slot_path)
|
||||
|
||||
#Retrieves save path
|
||||
var save_path = "res://Saves/save_" + str(save_number) + ".json"
|
||||
|
||||
|
||||
if FileAccess.file_exists(save_path):
|
||||
var file = FileAccess.open(save_path, FileAccess.READ) #Loads the save if it exists
|
||||
var json_string = file.get_as_text()
|
||||
file.close()
|
||||
var load_data = JSON.parse_string(json_string)
|
||||
if typeof(load_data) == 27: #Checks if loaded data is a Dictionary
|
||||
#Updates save and load slots texts
|
||||
print(load_data)
|
||||
save_slot.text = "DAY " + str(load_data["day_count"]) + ", PATIENT " + str(load_data["patient_count"]) + "\nSAVE DATE : " + str(load_data["save_date"])
|
||||
load_slot.text = save_slot.text
|
||||
load_title_slot.text = save_slot.text
|
||||
else:
|
||||
print("Failed to parse Loading Data.")
|
||||
|
||||
Reference in New Issue
Block a user