public static List <Dictionary <string, string> > FromString(string file_contents) { DictionaryCSVReader reader = new DictionaryCSVReader(); reader.LoadFromString(file_contents); return(reader.lines); }
private void ReadImportFile() { if (importFileRead) { return; } importFileRead = true; int line_idx = 0; characterSyntheses = new List <CharacterSynthesis>(); string importFileContent = null; switch (importMethod) { case ImportMethod.UnityAssets: importFileContent = importAsset.text; break; case ImportMethod.CSV: StreamReader reader = new StreamReader(importPath); importFileContent = reader.ReadToEnd(); reader.Close(); break; } foreach (Dictionary <string, string> line in DictionaryCSVReader.FromString(importFileContent)) { line_idx++; // checks if (line_idx == 1) { if (!line.ContainsKey("text")) { Debug.LogError("Column \"text\" not found in file"); importFileErrors.Add("Column \"text\" not found in file"); } if (!line.ContainsKey("character_id")) { Debug.LogError("Column \"character_id\" not found in file"); importFileErrors.Add("Column \"character_id\" not found in file"); } if (!line.ContainsKey("slug")) { Debug.LogError("Column \"slug\" not found in file"); importFileErrors.Add("Column \"slug\" not found in file"); } if (!line.ContainsKey("modifier")) { Debug.LogError("Column \"modifier\" not found in file"); importFileErrors.Add("Column \"modifier\" not found in file"); } if (importFileErrors.Count > 0) { return; } } // find character Character character = FindCharacter(line["character_id"]); if (character == null) { string error = $"Unknown character with ID or name {line["character_id"]} on line {line_idx}"; Debug.LogError(error); importFileErrors.Add(error); return; } // synthesis line CharacterSynthesis characterSynthesis = new CharacterSynthesis(); characterSynthesis.synthesis_text = line["text"]; characterSynthesis.synthesis_modifier = line["modifier"]; characterSynthesis.character_id = character.id; characterSynthesis.text_slug = line["slug"]; characterSynthesis.SetImportFileLine(line_idx); characterSyntheses.Add(characterSynthesis); } }