@@ -497,7 +497,7 @@ private static void extractInkTextsInternal(JsonValue v, StringBuilder sbTSV, St
497
497
sbMD .append ('\n' );
498
498
else if (v .parent .parent .parent .parent == null )
499
499
sbMD .append ("\n ==== " + v .name + " ====\n " );
500
- else if (v .name .equals ("s" ))
500
+ else if (v .name .equals ("s" ))
501
501
sbMD .append (" * " );
502
502
// else
503
503
// sbMD.append("\n-- " + v.name + " --\n");
@@ -553,4 +553,89 @@ else if(v.name.equals("s"))
553
553
}
554
554
}
555
555
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
+
556
641
}
0 commit comments