322 lines
9.6 KiB
GDScript
322 lines
9.6 KiB
GDScript
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.connect("new_game_pressed", self._on_new_game_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)
|
|
|
|
UI.connect("text_value_changed", self._on_text_value_changed)
|
|
UI.connect("auto_value_changed", self._on_auto_value_changed)
|
|
|
|
UI.its_game_over.back_to_menu.pressed.connect(self._on_main_menu_pressed)
|
|
|
|
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.day_count = 1
|
|
Globals.floor_count = -1
|
|
Globals.patient_count = 0
|
|
Globals.diagnoses_quota = 1
|
|
Globals.daily_patient_limit = 6
|
|
Globals.patients_seen.clear()
|
|
$ScreeningDesk.journal_layer.update_journal(-1)
|
|
# 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():
|
|
|
|
#PART IN PROGRESS
|
|
|
|
#Starting the day
|
|
start_day()
|
|
|
|
|
|
|
|
#Starts the day
|
|
func start_day():
|
|
|
|
#Hiding Menu for cinematic impact
|
|
UI.get_node("UI/UpperContainer").hide()
|
|
|
|
#Transitioning to day screen
|
|
$TextScreens/Day.text = "[center]DAY " + str(Globals.day_count) + "[/center]"
|
|
|
|
var scenes_to_hide: Array[Node] = [$TitleScreen, $TextScreens, $TextScreens/Day, $ScreeningDesk]
|
|
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
|
|
$ScreeningDesk.accurate_diagnoses = 0 #Resetting accurate_diagnoses value at the day's beginning
|
|
$ScreeningDesk.middle_screen.update(Globals.day_count, Globals.floor_count, $ScreeningDesk.accurate_diagnoses, Globals.diagnoses_quota)
|
|
|
|
#Resetting scenes
|
|
for scene in [$ScreeningDesk, UI.its_game_over]:
|
|
scene.reset()
|
|
|
|
#Transitioning to the screening desk
|
|
scenes_to_hide = scenes_to_show
|
|
scenes_to_show = [$ScreeningDesk, UI, UI.get_node("UI/UpperContainer")]
|
|
UI.masks.transition(scenes_to_hide, scenes_to_show)
|
|
await UI.masks.transition_finished
|
|
|
|
#Supervisor Dialogue
|
|
#$ScreeningDesk.supervisor.dialogue("interfloor_" + str(-Globals.floor_count-1))
|
|
#await $ScreeningDesk.supervisor.dialogue_finished
|
|
|
|
#Setting up UI
|
|
$ScreeningDesk.console_screen.display(Globals.directives)
|
|
$ScreeningDesk.computer.next_patient_button.show()
|
|
|
|
|
|
#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,
|
|
"floor_count": Globals.floor_count,
|
|
"patient_count": Globals.patient_count,
|
|
"diagnoses_quota": Globals.diagnoses_quota,
|
|
"daily_patient_limit": Globals.daily_patient_limit,
|
|
"patient_list": Globals.patient_list,
|
|
"patient_id": Globals.patient_id,
|
|
"patients_seen": Globals.patients_seen,
|
|
"its_patients_seen": Globals.its_patients_seen,
|
|
"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_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"]) + ", FLOOR " + str(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.visible = false
|
|
UI.get_node("UI/Menu").hide()
|
|
UI.get_node("UI/UpperContainer").hide()
|
|
UI.get_node("UI/Load").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 typeof(load_data) == 27: #Checks if loaded data is a Dictionary
|
|
print("Loaded save: " + str(load_data))
|
|
Globals.day_count = load_data["day_count"]
|
|
Globals.floor_count = load_data["floor_count"]
|
|
Globals.patient_count = load_data["patient_count"]
|
|
Globals.diagnoses_quota = load_data["diagnoses_quota"]
|
|
Globals.daily_patient_limit = load_data["daily_patient_limit"]
|
|
Globals.patient_list = load_data["patient_list"]
|
|
Globals.patient_id = load_data["patient_id"]
|
|
Globals.patients_seen = load_data["patients_seen"]
|
|
Globals.its_patients_seen = load_data["its_patients_seen"]
|
|
Patient.update_patient_list()
|
|
else:
|
|
print("Failed to parse Loading Data.")
|
|
|
|
#Starting day
|
|
start_day()
|
|
|
|
|
|
|
|
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():
|
|
|
|
#Removing mask
|
|
UI.masks.mask.visible = false
|
|
|
|
#Clearing balloon
|
|
clear_balloon()
|
|
|
|
#Hiding menus
|
|
UI.get_node("UI/Menu").hide()
|
|
UI.get_node("UI/UpperContainer").hide()
|
|
|
|
#Going back to main menu
|
|
var scenes_to_hide = [$ScreeningDesk, $TextScreens, $TextScreens/Day, UI.its_game_over]
|
|
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.its_game_over]:
|
|
scene.reset()
|
|
|
|
|
|
|
|
#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 save_slot = UI.get_node(save_slot_path)
|
|
var load_slot = UI.get_node(load_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("Initializing save slot #" + str(save_number) + " : " + str(load_data))
|
|
save_slot.text = "DAY " + str(load_data["day_count"]) + ", FLOOR " + str(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.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.text_speed
|
|
|
|
|
|
#Changes auto_speed value
|
|
func _on_auto_value_changed():
|
|
if is_instance_valid(balloon):
|
|
#balloon.dialogue_line.time = UI.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)
|