SproutyDialogsCSVFileManager
Inherits: RefCounted
Description
This class handles CSV files operations for saving and loading translations. It provides methods to handle dialogs and character names translations with CSV files.
Methods
| Return Type | Method |
|---|---|
| void | save_file(header: Array, data: Array, file_path: String) |
| Array | load_file(file_path: String) |
| void | update_row(file_path: String, header: Array, row: Array) |
| String | new_csv_template_file(name: String) |
| void | save_dialogs_on_csv(dialogs: Dictionary, path: String) |
| Dictionary | load_dialogs_from_csv(path: String) |
| void | save_character_names_on_csv(csv_name_key: String, name_data: Dictionary) |
| Dictionary | load_character_names_from_csv(csv_name_key: String) |
| void | rename_character_key(old_name_key: String, new_name_key: String) |
Method Descriptions
static func save_file(header: Array, data: Array, file_path: String) -> void
Save data to a CSV file. The data is provided as an array of arrays, where each inner array represents a row in the CSV file. The header is an array representing the first row of the CSV file.
static func load_file(file_path: String) -> Array
Load data from a CSV file. Returns an array with the CSV data.
static func update_row(file_path: String, header: Array, row: Array) -> void
Add or update a row in a CSV file. If the row with the same key exists, it will be updated. If not, it will be added to the end of the file.
static func new_csv_template_file(name: String) -> String
Create a new CSV template file. Returns the path of the created file or an empty string if an error occurred.
static func save_dialogs_on_csv(dialogs: Dictionary, path: String) -> void
Save all dialogs from a dictionary to a CSV file. Update existing rows or add new ones if the dialog key does not exist and save the file with all the dialogs without removing any existing data.
static func load_dialogs_from_csv(path: String) -> Dictionary
Load all dialogs from a CSV file to a dictionary. Returns a dictionary with the dialogue data as:
{
"dialogue_id_1": {
"locale_code_1": "Translated text in locale 1",
"locale_code_2": "Translated text in locale 2",
...
},
...
}
static func save_character_names_on_csv(csv_name_key: String, name_data: Dictionary) -> void
Save character name translations on the CSV file.
static func load_character_names_from_csv(csv_name_key: String) -> Dictionary
Load character name translations from a CSV file to a dictionary. Returns a dictionary with the character names as:
{
"locale_code_1": "Translated name in locale 1",
"locale_code_2": "Translated name in locale 2",
...
}
static func rename_character_key(old_name_key: String, new_name_key: String) -> void
Rename the translation key of a character name row on the CSV file, keeping all its translations. Used when a character key name is renamed, so the character translations are preserved on the new key.