use custom .data instead of raw csv file in dialogue db
This commit is contained in:
parent
f1c9f8a752
commit
ddce06585f
|
@ -88,4 +88,4 @@ config.txt
|
||||||
|
|
||||||
# Generated dialogue files
|
# Generated dialogue files
|
||||||
[Aa]ssets/Data/Dialogue/token*
|
[Aa]ssets/Data/Dialogue/token*
|
||||||
[Aa]ssets/Data/Dialogue/dialogue.csv*
|
[Aa]ssets/Data/Dialogue/dialogue.data*
|
||||||
|
|
|
@ -16,6 +16,7 @@ using UnityEditor;
|
||||||
|
|
||||||
public static partial class DialogueDatabase
|
public static partial class DialogueDatabase
|
||||||
{
|
{
|
||||||
|
|
||||||
public static string EDITOR_DialogueFile =>
|
public static string EDITOR_DialogueFile =>
|
||||||
Path.Combine(Application.dataPath, "Data", "Dialogue", DIALOGUE_FILENAME);
|
Path.Combine(Application.dataPath, "Data", "Dialogue", DIALOGUE_FILENAME);
|
||||||
|
|
||||||
|
@ -62,18 +63,16 @@ public static partial class DialogueDatabase
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Log($":: importing dialogue");
|
Debug.Log($":: importing dialogue");
|
||||||
var sbFile = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
var sbLog = new StringBuilder();
|
|
||||||
var lines = 0;
|
var lines = 0;
|
||||||
foreach (var row in values)
|
foreach (var row in values)
|
||||||
{
|
{
|
||||||
sbLog.AppendLine($"{row[0]} {row[1]}");
|
sb.AppendLine($"{row[0]}{SPLIT_CHAR}{row[1]}");
|
||||||
sbFile.AppendLine($"{row[0]},{row[1]},");
|
|
||||||
lines++;
|
lines++;
|
||||||
}
|
}
|
||||||
Debug.Log($":: imported {lines} lines of dialogue\n{sbLog}");
|
Debug.Log($":: imported {lines} lines of dialogue\n{sb}");
|
||||||
|
|
||||||
File.WriteAllText(EDITOR_DialogueFile, sbFile.ToString());
|
File.WriteAllText(EDITOR_DialogueFile, sb.ToString());
|
||||||
if (!File.Exists(EDITOR_DialogueFile))
|
if (!File.Exists(EDITOR_DialogueFile))
|
||||||
{
|
{
|
||||||
Debug.LogError($":: import failed: file doesn't exist: {EDITOR_DialogueFile}");
|
Debug.LogError($":: import failed: file doesn't exist: {EDITOR_DialogueFile}");
|
||||||
|
@ -95,7 +94,9 @@ public static partial class DialogueDatabase
|
||||||
|
|
||||||
public static partial class DialogueDatabase
|
public static partial class DialogueDatabase
|
||||||
{
|
{
|
||||||
public const string DIALOGUE_FILENAME = "dialogue.csv";
|
private const char SPLIT_CHAR = '|';
|
||||||
|
|
||||||
|
public const string DIALOGUE_FILENAME = "dialogue.data";
|
||||||
|
|
||||||
public static string DialogueFile
|
public static string DialogueFile
|
||||||
{
|
{
|
||||||
|
@ -119,7 +120,7 @@ public static partial class DialogueDatabase
|
||||||
int count = 0;
|
int count = 0;
|
||||||
foreach (var line in File.ReadLines(DialogueFile))
|
foreach (var line in File.ReadLines(DialogueFile))
|
||||||
{
|
{
|
||||||
var parts = line.Split(',');
|
var parts = line.Split(SPLIT_CHAR);
|
||||||
|
|
||||||
var key = parts[0];
|
var key = parts[0];
|
||||||
var text = parts[1];
|
var text = parts[1];
|
||||||
|
@ -144,5 +145,4 @@ public static partial class DialogueDatabase
|
||||||
? _dict[key]
|
? _dict[key]
|
||||||
: $"<color=\"red\">MISSING[{key}]</color>";
|
: $"<color=\"red\">MISSING[{key}]</color>";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue