aboutsummaryrefslogtreecommitdiff
path: root/game/src/Credits/Credits.gd
diff options
context:
space:
mode:
author Brendan Griffiths <96725360+Orwellian-225@users.noreply.github.com>2023-03-01 17:00:24 +0100
committer GitHub <noreply@github.com>2023-03-01 17:00:24 +0100
commit4e099cf1d3f5fa37e9aa520d90aaf505fee3ce23 (patch)
tree5355285405336b55eeab21ca5ecc24c8e9ecf1d8 /game/src/Credits/Credits.gd
parent2062aaf394ee6581161add4bcb23076475e236ac (diff)
add: credits.csv - req: FS4 (#16)
Requirements met by this PR: SS-17 SS-29 [1] UI-32 UI-34 UIFUN-36 UI-35 UI-38 UIFUN-37 FS-4
Diffstat (limited to 'game/src/Credits/Credits.gd')
-rw-r--r--game/src/Credits/Credits.gd116
1 files changed, 116 insertions, 0 deletions
diff --git a/game/src/Credits/Credits.gd b/game/src/Credits/Credits.gd
new file mode 100644
index 0000000..902207b
--- /dev/null
+++ b/game/src/Credits/Credits.gd
@@ -0,0 +1,116 @@
+extends Control
+
+signal back_button_pressed
+
+###############
+# Credits CSV format
+# The project title row is the only requirement within the csv file, however
+# it can be on any row, so long as it exists.
+# ----------------------
+# title,project-title
+# role-name,person-name
+# role-name,person-name
+# role-name,person-name
+# ...
+###############
+
+@export_file("*.csv")
+var core_credits_path : String
+
+# TODO: implement for theme instead
+# waiting for https://github.com/OpenVic2Project/OpenVic2/pull/48
+@export_group("Label Settings", "label_settings_")
+@export
+var label_settings_project : LabelSettings
+
+@export
+var label_settings_role : LabelSettings
+
+@export
+var label_settings_personel : LabelSettings
+
+@export
+var credits_list: VBoxContainer
+
+# REQUIREMENTS:
+# * 1.5 Credits Menu
+# * SS-17
+
+# REQUIREMENTS
+# * FS-4
+func load_credit_file(path):
+ var roles = {}
+ var core_credits = FileAccess.open(path, FileAccess.READ)
+
+ while not core_credits.eof_reached():
+ var line = core_credits.get_csv_line()
+
+ # If the line does not have an identifiable role or is empty then skip it
+ if line[0].is_empty():
+ continue
+
+ var role := line[0].to_upper()
+ var person : String = line[1] # Cannot infer with := as line[1] does not have a set type
+
+ if role not in roles.keys():
+ roles[role] = []
+ roles[role].push_back(person)
+ else:
+ roles[role].push_back(person)
+
+ return roles
+
+# REQUIREMENTS:
+# * UI-34, UI-35
+func make_project_credits(project):
+ var project_credits_list = VBoxContainer.new()
+ var project_credits_label = Label.new()
+
+
+ # Spartan has some suggestions here but for now its good enough. Refer
+ # to PR 16 resolved comments for further details
+ project_credits_list.name = 'Credits' + project['TITLE'][0]
+ project_credits_label.name = 'Label' + project['TITLE'][0]
+ project_credits_label.text = project['TITLE'][0]
+ project_credits_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
+ project_credits_label.label_settings = label_settings_project
+
+ for role in project.keys():
+ if role == 'TITLE':
+ continue
+
+ var role_parent = VBoxContainer.new()
+ var role_label = Label.new()
+
+ role_parent.name = 'Role' + role
+ role_label.name = 'Label' + role
+ role_label.text = role
+ role_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
+ role_label.label_settings = label_settings_role
+
+ for person in project[role]:
+ var person_label = Label.new()
+
+ person_label.name = 'Label' + person
+ person_label.text = person
+ person_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
+ person_label.label_settings = label_settings_personel
+ role_parent.add_child(person_label)
+
+ project_credits_list.add_child(role_label)
+ project_credits_list.add_child(role_parent)
+ project_credits_list.add_child(HSeparator.new())
+
+ credits_list.add_child(project_credits_list)
+
+# REQUIREMENTS:
+# * SS-17
+func _ready():
+ var core_credits = load_credit_file(core_credits_path)
+ make_project_credits(core_credits)
+
+# REQUIREMENTS:
+# * UI-38
+# * UIFUN-37
+func _on_back_button_pressed():
+ back_button_pressed.emit()