ImporterCSV: add delimiter options , ; or \t
This commit is contained in:
parent
bd282ff43f
commit
4e0d1c8f1c
1 changed files with 12 additions and 3 deletions
|
@ -73,16 +73,25 @@ String ResourceImporterCSVTranslation::get_preset_name(int p_idx) const {
|
|||
void ResourceImporterCSVTranslation::get_import_options(List<ImportOption> *r_options, int p_preset) const {
|
||||
|
||||
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "compress"), true));
|
||||
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "delimiter", PROPERTY_HINT_ENUM, "Comma,Semicolon,Tab"), 0));
|
||||
}
|
||||
|
||||
Error ResourceImporterCSVTranslation::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files) {
|
||||
|
||||
bool compress = p_options["compress"];
|
||||
|
||||
String delimiter;
|
||||
switch ((int)p_options["delimiter"]) {
|
||||
case 0: delimiter = ","; break;
|
||||
case 1: delimiter = ";"; break;
|
||||
case 2: delimiter = "\t"; break;
|
||||
}
|
||||
|
||||
FileAccessRef f = FileAccess::open(p_source_file, FileAccess::READ);
|
||||
|
||||
ERR_FAIL_COND_V(!f, ERR_INVALID_PARAMETER);
|
||||
|
||||
Vector<String> line = f->get_csv_line();
|
||||
Vector<String> line = f->get_csv_line(delimiter);
|
||||
ERR_FAIL_COND_V(line.size() <= 1, ERR_PARSE_ERROR);
|
||||
|
||||
Vector<String> locales;
|
||||
|
@ -101,7 +110,7 @@ Error ResourceImporterCSVTranslation::import(const String &p_source_file, const
|
|||
translations.push_back(translation);
|
||||
}
|
||||
|
||||
line = f->get_csv_line();
|
||||
line = f->get_csv_line(delimiter);
|
||||
|
||||
while (line.size() == locales.size() + 1) {
|
||||
|
||||
|
@ -113,7 +122,7 @@ Error ResourceImporterCSVTranslation::import(const String &p_source_file, const
|
|||
}
|
||||
}
|
||||
|
||||
line = f->get_csv_line();
|
||||
line = f->get_csv_line(delimiter);
|
||||
}
|
||||
|
||||
for (int i = 0; i < translations.size(); i++) {
|
||||
|
|
Loading…
Reference in a new issue