Code reorganizing
This commit is contained in:
@@ -0,0 +1,213 @@
|
||||
extends Node
|
||||
|
||||
#Dialogue variables
|
||||
var dialog_tree: Dictionary
|
||||
var marker: Array[int]
|
||||
var dialogue_resource: Resource
|
||||
|
||||
#Patient attributes
|
||||
var texture := TextureRect.new()
|
||||
var image : Texture2D
|
||||
var original_color: Color
|
||||
var emotions : Dictionary
|
||||
var abnormal: bool
|
||||
|
||||
#Patient file
|
||||
var file_text : String
|
||||
|
||||
#Patient symptoms ordered from floor to floor
|
||||
var symptoms_arrays: Array[Array] = [
|
||||
["SUICIDAL IDEATIONS", "PERSECUTORY DELUSIONS", "UNNATURAL BEHAVIOUR", "AUDITORY HALLUCINATIONS"],
|
||||
["SOMATIC HALLUCINATIONS", "MEGALOMANIAC DELUSIONS"],
|
||||
["MYSTICAL DELUSIONS", "MANIA"],
|
||||
["CHEMOSENSORY HALLUCINATIONS", "SELF-MUTILATION"],
|
||||
["VISUAL HALLUCINATIONS", "HETERO-AGRESSIVE BEHAVIOUR"]
|
||||
]
|
||||
#Lists of possible patients sorted by floor
|
||||
var patient_list : Array[Dictionary]
|
||||
|
||||
#Supervisor file path
|
||||
var supervisor_name = "loeveth"
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
|
||||
#Setting up dialogue marker
|
||||
marker.resize(100)
|
||||
marker.fill(0)
|
||||
|
||||
#Setting up patient list
|
||||
patient_list.resize(len(symptoms_arrays))
|
||||
|
||||
original_color = texture.modulate #Saving original modulation color to reset it after modification
|
||||
|
||||
|
||||
func build_dialog_tree(tree_model: Array[int]) -> Dictionary: #Builds the dialog tree for each dialogue
|
||||
|
||||
var branch : Dictionary
|
||||
var tree : Dictionary
|
||||
|
||||
for branch_id in tree_model:
|
||||
branch = {branch_id: "not_asked"}
|
||||
tree.merge(branch)
|
||||
|
||||
return tree
|
||||
|
||||
|
||||
func new_patient(patient_id):
|
||||
|
||||
var file_path: String
|
||||
|
||||
#Loading Patient Files
|
||||
var config := ConfigFile.new()
|
||||
file_path = "res://Dialogues/Patients/patient_" + patient_id + "_file.cfg"
|
||||
config.load(file_path)
|
||||
|
||||
#Setting up Patient File
|
||||
var patient_name = config.get_value("", "name")
|
||||
var age = config.get_value("", "age")
|
||||
var profession = config.get_value("", "profession")
|
||||
var psychiatric_assessment = config.get_value("", "psychiatric_assessment")
|
||||
|
||||
file_text = "NAME: " + patient_name + "\nAGE: " + age + "\n\nPROFESSION: " + profession + "\n\nPRE-SCREENING PSYCHIATRIC ASSESSMENT:\n\n" + "[color=orange_red]" + psychiatric_assessment + "[/color]"
|
||||
|
||||
file_path = "res://Art/Patients/patient_" + patient_id + "/patient_" + patient_id + "_"
|
||||
load_emotions(config, file_path)
|
||||
|
||||
#Loading Dialogue Resource
|
||||
file_path = "res://Dialogues/Patients/patient_" + patient_id + ".dialogue"
|
||||
dialogue_resource = load(file_path)
|
||||
|
||||
#Randomizing abnormal status if required
|
||||
var status = config.get_value("", "status")
|
||||
match status:
|
||||
"random":
|
||||
abnormal = randf() < 0.5 #50/50 abnormal/normal
|
||||
print("Abnormal value: " + str(abnormal))
|
||||
"normal":
|
||||
abnormal = false
|
||||
"abnormal":
|
||||
abnormal = true
|
||||
|
||||
|
||||
func load_emotions(config, patient_path):
|
||||
|
||||
#Loading Patient Initial Face
|
||||
var initial_emotion = config.get_value("", "initial_emotion")
|
||||
var file_path = patient_path + initial_emotion + ".png"
|
||||
image = load(file_path)
|
||||
|
||||
#Loading Face Emotions
|
||||
var face: Resource
|
||||
var emotion_branch: Dictionary
|
||||
var emotion_list = ["neutral", "peaceful", "praying", "puzzled", "suspicious",
|
||||
"sadsmiling", "crazysmiling", "shockedcrying", "smiling",
|
||||
"laughing", "happy", "elated", "maniac", "ecstatic",
|
||||
"irritated", "angry",
|
||||
"sad", "depressed", "crying", "surprised",
|
||||
"worried", "scared", "shocked", "panicked", "terrified",
|
||||
"abnormal", "abnormal1", "abnormal2", "abnormal3", "special"]
|
||||
|
||||
emotions.clear() #Clearing previous patient emotions
|
||||
for emotion in emotion_list:
|
||||
file_path = patient_path + emotion + ".png"
|
||||
face = load(file_path)
|
||||
if face != null:
|
||||
emotion_branch = {emotion: face}
|
||||
emotions.merge(emotion_branch)
|
||||
|
||||
|
||||
#Sorts the patients to determine who can appear on what floor depending on the symptoms unlocked
|
||||
func sort_patients():
|
||||
|
||||
var config := ConfigFile.new()
|
||||
var file_path : String
|
||||
var patient_symptoms: Array
|
||||
var symptom_matched : bool
|
||||
var symptom_list: Array
|
||||
|
||||
for patient_id in Globals.patient_list:
|
||||
|
||||
#Loads symptoms for each patient
|
||||
patient_symptoms.clear()
|
||||
file_path = "res://Dialogues/Patients/patient_" + patient_id + "_file.cfg"
|
||||
config.load(file_path)
|
||||
symptom_list = config.get_value("", "psychiatric_assessment").split("\n", false)
|
||||
patient_symptoms = symptom_list
|
||||
symptom_list = config.get_value("", "abnormal_symptoms").split("\n", false)
|
||||
patient_symptoms.append_array(symptom_list)
|
||||
print("Patient #" + patient_id + " symptom list: " + str(patient_symptoms))
|
||||
|
||||
#Goes through the symptoms_arrays from the last to the first,
|
||||
#If a symptom matches with the patient symptoms,
|
||||
#Add that patient to the floors from that floor to the last one
|
||||
|
||||
for j in range(len(symptoms_arrays)-1, -1, -1):
|
||||
for symptom in patient_symptoms:
|
||||
if symptoms_arrays[j].has(symptom):
|
||||
symptom_matched = true
|
||||
print("Symptom matched: " + str(symptoms_arrays[j]) + " and " + str(symptom))
|
||||
break
|
||||
if symptom_matched:
|
||||
for k in range(j, symptoms_arrays.size()):
|
||||
patient_list[k].merge({patient_id: j+1}) # Adds the patient to every floor compatible
|
||||
symptom_matched = false
|
||||
break
|
||||
|
||||
for i in range(len(patient_list)):
|
||||
print("Floor " + str(i) + " possible patients: " + str(patient_list[i]))
|
||||
|
||||
|
||||
#Weighted random selection from an Array
|
||||
func weighted_random(patients: Dictionary):
|
||||
|
||||
#Calculating total weight
|
||||
var total_weight : int
|
||||
for weight in patients.values():
|
||||
total_weight += weight
|
||||
print("Total weight: " + str(total_weight))
|
||||
|
||||
var r = randf() * total_weight
|
||||
print("r :" + str(r))
|
||||
|
||||
var weight_sum : int
|
||||
for patient_id in patients:
|
||||
weight_sum += patients[patient_id]
|
||||
if weight_sum >= r:
|
||||
print("Patient selected: " + patient_id + ", Weight: " + str(patients[patient_id]))
|
||||
return patient_id
|
||||
return null
|
||||
|
||||
|
||||
func generate_patient_id() -> String: #Generates a patient ID
|
||||
|
||||
#Generating patient_id
|
||||
var floor_index = -Globals.floor_count -1
|
||||
print("Floor Index: " + str(floor_index))
|
||||
var patient_id = weighted_random(patient_list[floor_index]) #Picks a random patient depending on floor, with weighted odds
|
||||
|
||||
for j in range(len(patient_list)):
|
||||
if len(patient_list[j]) > 1:
|
||||
patient_list[j].erase(patient_id) #Removes picked patient from unseen patients list
|
||||
print("Updated Floor " + str(j) + " list: " + str(patient_list[j]))
|
||||
|
||||
|
||||
return patient_id
|
||||
|
||||
|
||||
func next_patient() -> String: #Decides next patient ID
|
||||
|
||||
var next_patient_id: String
|
||||
|
||||
match Globals.floor_count:
|
||||
-2:
|
||||
if Globals.patient_count == 0:
|
||||
next_patient_id = "it_that_smiles"
|
||||
else:
|
||||
next_patient_id = generate_patient_id()
|
||||
_:
|
||||
next_patient_id = generate_patient_id()
|
||||
|
||||
|
||||
return next_patient_id
|
||||
|
||||
Reference in New Issue
Block a user