Skip to main content

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 TypeMethod
voidsave_file(header: Array, data: Array, file_path: String)
Arrayload_file(file_path: String)
voidupdate_row(file_path: String, header: Array, row: Array)
Stringnew_csv_template_file(name: String)
voidsave_dialogs_on_csv(dialogs: Dictionary, path: String)
Dictionaryload_dialogs_from_csv(path: String)
voidsave_character_names_on_csv(key_name: String, name_data: Dictionary)
Dictionaryload_character_names_from_csv(key_name: String)

Method Descriptions

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.


func load_file(file_path: String) -> Array

Load data from a CSV file. Returns an array with the CSV data.


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.


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.


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.


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",
...
},
...
}

func save_character_names_on_csv(key_name: String, name_data: Dictionary) -> void

Save character name translations on the CSV file.


func load_character_names_from_csv(key_name: 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",
...
}