2 class_name DialogicCharacterPrefixSuffixSection
3 extends DialogicCharacterEditorMainSection
4 ## Character Editor Section for setting the prefix and suffix of a character.
6 ## loads and sets the prefix and suffix of a character.
7 ## Provides [const PREFIX_CUSTOM_KEY] and [const SUFFIX_CUSTOM_KEY] to
8 ## access the `custom_info` dictionary of the [class DialogicCharacter].
10 @export var prefix_input: LineEdit
11 @export var suffix_input: LineEdit
13 ## We won't force any prefixes or suffixes onto the player,
14 ## to ensure their games are working as previously when updating.
15 const DEFAULT_PREFIX = ""
16 const DEFAULT_SUFFIX = ""
18 ## `custom_info` dictionary keys for the prefix.
19 const PREFIX_CUSTOM_KEY = "prefix"
21 ## `custom_info` dictionary keys for the prefix.
22 const SUFFIX_CUSTOM_KEY = "suffix"
28 func _ready() -> void:
29 suffix_input.text_changed.connect(_suffix_changed)
30 prefix_input.text_changed.connect(_prefix_changed)
33 func _suffix_changed(text: String) -> void:
37 func _prefix_changed(text: String) -> void:
41 func _get_title() -> String:
42 return "Character Prefix & Suffix"
45 func _show_title() -> bool:
49 func _start_opened() -> bool:
53 func _load_portrait_data(portrait_data: Dictionary) -> void:
54 _load_prefix_data(portrait_data)
57 ## We load the prefix and suffix from the character's `custom_info` dictionary.
58 func _load_character(resource: DialogicCharacter) -> void:
59 _load_prefix_data(resource.custom_info)
62 func _load_prefix_data(data: Dictionary) -> void:
63 suffix = data.get(SUFFIX_CUSTOM_KEY, DEFAULT_SUFFIX)
64 prefix = data.get(PREFIX_CUSTOM_KEY, DEFAULT_PREFIX)
66 suffix_input.text = suffix
67 prefix_input.text = prefix
70 ## Whenever the user makes a save to the character, we save the prefix and suffix.
71 func _save_changes(character: DialogicCharacter) -> DialogicCharacter:
72 if not character.custom_info:
73 printerr("[Dialogic] Unable to save Prefix and Suffix, the character is missing.")
76 character.custom_info[PREFIX_CUSTOM_KEY] = prefix
77 character.custom_info[SUFFIX_CUSTOM_KEY] = suffix