extends Control @export var TitleScreen: PackedScene @export var ScreeningDesk: PackedScene @export var TextScreens: PackedScene var balloon: Node # Called when the node enters the scene tree for the first time. func _ready() -> void: #Adding Scenes var title_screen = TitleScreen.instantiate() var screening_desk = ScreeningDesk.instantiate() var text_screens = TextScreens.instantiate() add_child(title_screen) add_child(screening_desk) add_child(text_screens) #Naming Scenes title_screen.name = "TitleScreen" screening_desk.name = "ScreeningDesk" text_screens.name = "TextScreens" #Showing TitleScreen title_screen.show() #Connecting Signals title_screen.new_game_pressed.connect(self._on_new_game_pressed) UI.save_slot_pressed.connect(self.save_game) UI.load_slot_pressed.connect(self.load_game) UI.main_menu_pressed.connect(self._on_main_menu_pressed) UI.text_value_changed.connect(self._on_text_value_changed) UI.auto_value_changed.connect(self._on_auto_value_changed) UI.game_over.back_to_menu.pressed.connect(self._on_main_menu_pressed) UI.game_over.reload_checkpoint.pressed.connect(self.load_game.bind(0)) Globals.character_label_color_change.connect(self._on_character_label_color_change) Globals.start_balloon.connect(self.start_balloon) #Updating Save/Load Slots Information based on Existing Saves update_slots() #Sorting patients by floor Patient.sort_patients() # Starts a new game func _on_new_game_pressed(): #Setting/Resetting game parameters Globals.floor_count = -5 Globals.patient_count = 0 Globals.accurate_diagnoses = 0 Globals.diagnoses_quota = 2 Globals.misdiagnoses_allowed = 2 Globals.daily_patient_limit = 6 Globals.event_index = "interfloor" for i in range(len(Patient.patient_list)): Patient.patient_list[i] = Patient.og_patient_list[i] Patient.its_list = Patient.og_its_list Patient.patients_seen.clear() Patient.its_seen.clear() Patient.spy.order = false Patient.spy.count = 0 # DISABLED FOR NOW SINCE THERE'S NO INTRO ANYMORE #Offering to skip the introduction #var choice_text = "Do you wish to skip the introduction ?" #UI.ask_confirmation(start_day, play_intro, choice_text) start_day() #Plays the entire introduction func play_intro(): #WORK IN PROGRESS #Starting the day start_day() #Starts the day func start_day(): #Transitioning to day screen $TextScreens/Day.text = "[center]FLOOR " + str(Globals.floor_count) + "[/center]" var scenes_to_hide: Array[Node] = [$TitleScreen, $ScreeningDesk, UI.pause_menu.menu_button, UI.game_over] var scenes_to_show: Array[Node] = [$TextScreens, $TextScreens/Day] UI.masks.transition(scenes_to_hide, scenes_to_show) await UI.masks.transition_finished await get_tree().create_timer(1.0).timeout #Setting up new patient for scene in [$ScreeningDesk, UI.game_over]: #Resetting scenes scene.reset() #Transitioning to the screening desk scenes_to_hide = scenes_to_show scenes_to_show = [$ScreeningDesk, UI.pause_menu.menu_button] UI.masks.transition(scenes_to_hide, scenes_to_show) await UI.masks.transition_finished $ScreeningDesk.event_manager() #Saves game state on the selected save slot func save_game(save_slot_number:int): #Setting up save data var save_data = { "floor_count": Globals.floor_count, "event_index": Globals.event_index, "supervisor_index": Globals.supervisor_index, "patient_count": Globals.patient_count, "accurate_diagnoses": Globals.accurate_diagnoses, "diagnoses_quota": Globals.diagnoses_quota, "misdiagnoses_allowed": Globals.misdiagnoses_allowed, "daily_patient_limit": Globals.daily_patient_limit, "patient_list": Patient.patient_list, "its_list": Patient.its_list, "ite_list": Patient.ite_list, "patients_seen": Patient.patients_seen, "its_seen": Patient.its_seen, "ite_seen": Patient.ite_seen, "spy_order": Patient.spy.order, "spy_count": Patient.spy.count, "journal_entities": $ScreeningDesk.journal_layer.journal.entities_page.text, "save_date": Globals.get_save_date() } #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("Saved data : " + str(json_string)) file.store_string(json_string) file.close() print("Game saved successfully!") else: print("Failed to open file for saving.") #Updating save/load slots information var save_slot = UI.pause_menu.save.save_slot[save_slot_number] var load_slot = UI.pause_menu.load.load_slot[save_slot_number] save_slot.text = "FLOOR " + str(int(save_data["floor_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): #Clearing balloon clear_balloon() #Hiding loading menus and masks UI.masks.mask.hide() UI.pause_menu.reset() #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 is Dictionary: #Checks if loaded data is a Dictionary print("Loaded save: " + str(load_data)) Globals.floor_count = load_data["floor_count"] Globals.event_index = load_data["event_index"] Globals.supervisor_index = load_data["supervisor_index"] Globals.patient_count = load_data["patient_count"] Globals.accurate_diagnoses = load_data["accurate_diagnoses"] Globals.diagnoses_quota = load_data["diagnoses_quota"] Globals.misdiagnoses_allowed = load_data["misdiagnoses_allowed"] Globals.daily_patient_limit = load_data["daily_patient_limit"] Patient.patient_list.clear() Patient.patient_list.append_array(load_data["patient_list"]) print (Patient.patient_list) Patient.its_list = load_data["its_list"] Patient.ite_list = load_data["ite_list"] Patient.patients_seen = load_data["patients_seen"] Patient.its_seen = load_data["its_seen"] Patient.ite_seen = load_data["ite_seen"] Patient.spy.order = load_data["spy_order"] Patient.spy.count = load_data["spy_count"] $ScreeningDesk.journal_layer.journal.entities_page.text = load_data["journal_entities"] else: print("Failed to parse Loading Data.") #Starting day start_day() func _on_main_menu_pressed(): #Hiding loading menu and mask UI.masks.mask.hide() UI.pause_menu.reset() #Clearing balloon clear_balloon() #Going back to main menu var scenes_to_hide = [$ScreeningDesk, $TextScreens, $TextScreens/Day, UI.game_over, UI.pause_menu.menu_button] var scenes_to_show = [$TitleScreen] UI.masks.transition(scenes_to_hide, scenes_to_show) await UI.masks.transition_finished #Resetting scenes for scene in [$ScreeningDesk, UI.game_over]: scene.reset() #Updates Save/Load Slots based on Existing Saves func update_slots(): #Loops over the 4 save/load slots + the autosaveslot for save_number in range(Globals.save_slot_count + 1): #Retrieves save and load slots var save_slot = UI.pause_menu.save.save_slot[save_number] var load_slot = UI.pause_menu.load.load_slot[save_number] #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("Initializing save slot #" + str(save_number) + " : " + str(load_data)) save_slot.text = "FLOOR " + str(int(load_data["floor_count"])) + "\nSAVE DATE : " + str(load_data["save_date"]) load_slot.text = save_slot.text else: print("Failed to parse Loading Data.") #Starts a balloon dialogue func start_balloon(balloon_type:String, patient_type:String, dialogue_resource: Resource, start_title: String): #Clearing previous balloon clear_balloon() #Instantiating a custom balloon var Balloon: Resource = load("res://Dialogues/balloon_" + balloon_type + ".tscn") balloon = Balloon.instantiate() get_tree().current_scene.add_child(balloon) #Connects emotion signals if needed match patient_type: "patient": DialogueManager.got_dialogue.connect($ScreeningDesk.patient._change_emotion) DialogueManager.got_dialogue.connect($ScreeningDesk.computer._recording_text) "supervisor": DialogueManager.got_dialogue.connect($ScreeningDesk.supervisor._change_emotion) #Applies text settings to the balloon balloon.dialogue_label.seconds_per_step = UI.pause_menu.settings.text_speed #balloon.dialogue_line.time = UI.auto_speed #Starts dialogue balloon.start(dialogue_resource, start_title) #Clearing balloon func clear_balloon(): #Clearing Previous Balloon if is_instance_valid(balloon): balloon.queue_free() #Disconnecting emotion signals for function in [$ScreeningDesk.patient._change_emotion, $ScreeningDesk.computer._recording_text, $ScreeningDesk.supervisor._change_emotion]: if DialogueManager.is_connected("got_dialogue", function): DialogueManager.disconnect("got_dialogue", function) #Changes text_speed value func _on_text_value_changed(): if is_instance_valid(balloon): balloon.dialogue_label.seconds_per_step = UI.pause_menu.settings.text_speed #Changes auto_speed value func _on_auto_value_changed(): if is_instance_valid(balloon): #balloon.dialogue_line.time = UI.pause_menu.settings.auto_speed pass #Changes CharacterLabel color func _on_character_label_color_change(color: Color): var label = balloon.get_node("Balloon/Panel/Dialogue/VBoxContainer/CharacterLabel") label.add_theme_color_override("default_color", color)