Skip to content

Commit 76bac21

Browse files
committed
Add console method to extract dialogs readable file.
1 parent 56eff7d commit 76bac21

File tree

2 files changed

+105
-11
lines changed

2 files changed

+105
-11
lines changed

adventure-editor/src/main/java/com/bladecoder/engineeditor/common/EditorCommandExecutor.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ public void printUnusedSounds() {
4444
ModelTools.printUnusedSounds();
4545
EditorLogger.msg("PROCCESS FINISHED.");
4646
}
47-
47+
4848
public void checkI18N() {
4949
try {
5050
EditorLogger.msg("Check for MODEL missing keys in default translation file for current chapter.");
5151
ModelTools.checkI18NMissingKeys();
52-
52+
5353
EditorLogger.msg("Compare translation files with the base file:");
5454
String[] files = new File(Ctx.project.getAssetPath() + Project.MODEL_PATH).list(new FilenameFilter() {
5555
@Override
@@ -61,14 +61,13 @@ public boolean accept(File arg0, String arg1) {
6161
return false;
6262
}
6363
});
64-
65-
for(String f: files) {
64+
65+
for (String f : files) {
6666
int idx = f.indexOf('_');
6767
String base = f.substring(0, idx);
6868
String lang = f.substring(idx + 1, idx + 3);
6969
EditorLogger.msg("Checking " + base + " LANG: " + lang);
70-
I18NUtils.compare(Ctx.project.getAssetPath() + Project.MODEL_PATH, base, null,
71-
lang);
70+
I18NUtils.compare(Ctx.project.getAssetPath() + Project.MODEL_PATH, base, null, lang);
7271
}
7372
} catch (Exception e) {
7473
EditorLogger.printStackTrace(e);
@@ -89,13 +88,23 @@ public void extractInkTexts(String story, String lang) {
8988

9089
public void importInkTSV(String tsvFile, String storyName) {
9190
try {
92-
I18NUtils.importTSV(Ctx.project.getAssetPath() + Project.MODEL_PATH, tsvFile,
93-
storyName + "-ink", "default");
91+
I18NUtils.importTSV(Ctx.project.getAssetPath() + Project.MODEL_PATH, tsvFile, storyName + "-ink",
92+
"default");
9493

95-
EditorLogger.msg( tsvFile + " imported sucessfully.");
94+
EditorLogger.msg(tsvFile + " imported sucessfully.");
9695

9796
} catch (IOException e) {
98-
EditorLogger.error( "There was a problem importing the .tsv file.");
97+
EditorLogger.error("There was a problem importing the .tsv file.");
98+
EditorLogger.printStackTrace(e);
99+
}
100+
101+
EditorLogger.msg("PROCCESS FINISHED.");
102+
}
103+
104+
public void readableInkDialogs(String story, String lang) {
105+
try {
106+
ModelTools.readableInkDialogs(story, lang);
107+
} catch (Exception e) {
99108
EditorLogger.printStackTrace(e);
100109
}
101110

adventure-editor/src/main/java/com/bladecoder/engineeditor/common/ModelTools.java

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ private static void extractInkTextsInternal(JsonValue v, StringBuilder sbTSV, St
497497
sbMD.append('\n');
498498
else if (v.parent.parent.parent.parent == null)
499499
sbMD.append("\n==== " + v.name + " ====\n");
500-
else if(v.name.equals("s"))
500+
else if (v.name.equals("s"))
501501
sbMD.append(" * ");
502502
// else
503503
// sbMD.append("\n-- " + v.name + " --\n");
@@ -553,4 +553,89 @@ else if(v.name.equals("s"))
553553
}
554554
}
555555

556+
public static void readableInkDialogs(String story, String lang) throws IOException {
557+
String file = Ctx.project.getModelPath() + "/" + story + EngineAssetManager.INK_EXT;
558+
559+
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
560+
StringBuilder sb = new StringBuilder();
561+
562+
try {
563+
String line = br.readLine();
564+
565+
// Replace the BOM mark
566+
if (line != null)
567+
line = line.replace('\uFEFF', ' ');
568+
569+
while (line != null) {
570+
sb.append(line);
571+
sb.append("\n");
572+
line = br.readLine();
573+
}
574+
575+
} finally {
576+
br.close();
577+
}
578+
579+
JsonValue root = new JsonReader().parse(sb.toString());
580+
581+
// TODO: Add lang and check if default
582+
File propFile = new File(Ctx.project.getModelPath() + "/" + story + "-ink.properties");
583+
OrderedProperties langProp = new OrderedPropertiesBuilder().withSuppressDateInComment(true).withOrdering()
584+
.build();
585+
586+
langProp.load(new InputStreamReader(new FileInputStream(propFile), I18N.ENCODING));
587+
588+
// .md generation to have a better readable document of texts
589+
StringBuilder mdString = new StringBuilder();
590+
591+
readableInkDialogsInternal(root, mdString, langProp);
592+
FileUtils.writeStringToFile(new File(Ctx.project.getModelPath() + "/" + story + "-DIALOGS.txt"),
593+
mdString.toString());
594+
}
595+
596+
private static void readableInkDialogsInternal(JsonValue v, StringBuilder sbMD, OrderedProperties prop) {
597+
if (v.isArray() || v.isObject()) {
598+
if (v.name != null && v.isArray() && v.parent != null && v.parent.parent != null
599+
&& v.parent.parent.parent != null) {
600+
if (v.name.contains("-"))
601+
sbMD.append('\n');
602+
else if (v.parent.parent.parent.parent == null)
603+
sbMD.append("\n==== " + v.name + " ====\n");
604+
else if (v.name.equals("s"))
605+
sbMD.append(" * ");
606+
// else
607+
// sbMD.append("\n-- " + v.name + " --\n");
608+
}
609+
610+
for (int i = 0; i < v.size; i++) {
611+
JsonValue aValue = v.get(i);
612+
613+
readableInkDialogsInternal(aValue, sbMD, prop);
614+
}
615+
616+
} else if (v.isString() && v.asString().charAt(0) == '^') {
617+
String key = v.asString().substring(1).trim();
618+
619+
if (key.length() == 0 || key.charAt(0) == '>')
620+
return;
621+
622+
int idx = key.indexOf('>');
623+
String charName = "";
624+
625+
if (idx != -1) {
626+
charName = key.substring(0, idx).trim();
627+
key = key.substring(idx + 1).trim();
628+
629+
if (key.length() <= 1)
630+
return;
631+
}
632+
633+
key = key.substring(1);
634+
635+
String value = prop.getProperty(key);
636+
637+
sbMD.append(charName + (charName.isEmpty() ? "" : ": ") + value + " (" + key + ")\n");
638+
}
639+
}
640+
556641
}

0 commit comments

Comments
 (0)