]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Editor/CharacterEditor/character_prefix_suffix.gd
Updated export config options
[wolf-seeking-sheep.git] / addons / dialogic / Editor / CharacterEditor / character_prefix_suffix.gd
1 @tool
2 class_name DialogicCharacterPrefixSuffixSection
3 extends DialogicCharacterEditorMainSection
4 ## Character Editor Section for setting the prefix and suffix of a character.
5 ##
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].
9
10 @export var prefix_input: LineEdit
11 @export var suffix_input: LineEdit
12
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 = ""
17
18 ## `custom_info` dictionary keys for the prefix.
19 const PREFIX_CUSTOM_KEY = "prefix"
20
21 ## `custom_info` dictionary keys for the prefix.
22 const SUFFIX_CUSTOM_KEY = "suffix"
23
24 var suffix := ""
25 var prefix := ""
26
27
28 func _ready() -> void:
29         suffix_input.text_changed.connect(_suffix_changed)
30         prefix_input.text_changed.connect(_prefix_changed)
31
32
33 func _suffix_changed(text: String) -> void:
34         suffix = text
35
36
37 func _prefix_changed(text: String) -> void:
38         prefix = text
39
40
41 func _get_title() -> String:
42         return "Character Prefix & Suffix"
43
44
45 func _show_title() -> bool:
46         return true
47
48
49 func _start_opened() -> bool:
50         return false
51
52
53 func _load_portrait_data(portrait_data: Dictionary) -> void:
54         _load_prefix_data(portrait_data)
55
56
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)
60
61
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)
65
66         suffix_input.text = suffix
67         prefix_input.text = prefix
68
69
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.")
74                 return character
75
76         character.custom_info[PREFIX_CUSTOM_KEY] = prefix
77         character.custom_info[SUFFIX_CUSTOM_KEY] = suffix
78
79         return character