22
33import io .Items .LocalizableItem ;
44
5+ import java .io .File ;
56import java .io .IOException ;
67import java .nio .file .*;
78import java .nio .file .attribute .BasicFileAttributes ;
@@ -24,7 +25,7 @@ public FileVisitResult visitFileFailed(Path file, IOException exc) {
2425 }
2526
2627 public static LinkedList <LocalizableItem > visit (Path path ) throws IOException {
27- logger .setLevel (Level .OFF );
28+ logger .setLevel (Level .INFO );
2829 if (visitor == null ) {
2930 visitor = new BATFileVisitor ();
3031 }
@@ -34,15 +35,26 @@ public static LinkedList<LocalizableItem> visit(Path path) throws IOException {
3435 return visitor .itemList ;
3536 }
3637
37- private void fillList (List <String > info , String type , List <String > keys ) {
38+ private List <String > findOtherLang (Path path ) throws IOException {
39+ Path infoFile = path .subpath (path .getNameCount () - 2 , path .getNameCount () - 1 );
40+ File [] files = path .toFile ().getParentFile ().listFiles (((dir , name ) -> name .endsWith (".dat" ) && !name .endsWith ("English.dat" ) && !name .endsWith (infoFile + ".dat" )));
41+ if (files != null && files .length != 0 ) {
42+ logger .info ("Found Other Language File:" + files [0 ]);
43+ return Files .readAllLines (files [0 ].toPath ());
44+ }
45+ else
46+ return new ArrayList <>();
47+ }
48+
49+ private HashMap <String , String > toMap (List <String > list ) {
3850 HashMap <String , String > infoMap = new HashMap <>();
39- info .forEach (x -> {
51+ list .forEach (x -> {
4052 //只分割一次
4153 String [] result = x .split (" " , 2 );
4254 if (result .length == 2 )
4355 infoMap .put (result [0 ], result [1 ]);
4456 });
45- itemList . add ( new LocalizableItem ( type , keys , infoMap )) ;
57+ return infoMap ;
4658 }
4759
4860 @ Override
@@ -61,7 +73,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
6173 List <String > info = new ArrayList <>();
6274 String path = file .toString ();
6375 info .add ("Path" + " " + path );
64- logger .info ("Found Language File:" + file );
76+ logger .info ("Found English Language File:" + file );
6577 //语言文件位于的文件夹名称
6678 Path pathname = file .subpath (file .getNameCount () - 2 , file .getNameCount () - 1 );
6779 //用于一般描述的描述文件判断——物品、物体、载具等等
@@ -72,16 +84,16 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
7284 info .addAll (Files .readAllLines (file ));
7385 //物品
7486 if (path .contains ("Item" )) {
75- fillList ( info , Item .getName (), Item .getAttrs ());
87+ itemList . add ( new LocalizableItem ( Item .getName (), Item .getAttrs (), toMap ( info ), toMap ( findOtherLang ( file )) ));
7688 }//物体
7789 else if (path .contains ("Objects" ) || path .contains ("Tree" )) {
78- fillList ( info , Objects .getName (), Objects .getAttrs ());
90+ itemList . add ( new LocalizableItem ( Objects .getName (), Objects .getAttrs (), toMap ( info ), toMap ( findOtherLang ( file )) ));
7991 }//载具
8092 else if (path .contains ("Vehicle" )) {
81- fillList ( info , Vehicle .getName (), Vehicle .getAttrs ());
93+ itemList . add ( new LocalizableItem ( Vehicle .getName (), Vehicle .getAttrs (), toMap ( info ), toMap ( findOtherLang ( file )) ));
8294 }//动物
8395 else if (path .contains ("Animals" )) {
84- fillList ( info , Animals .getName (), Animals .getAttrs ());
96+ itemList . add ( new LocalizableItem ( Vehicle .getName (), Vehicle .getAttrs (), toMap ( info ), toMap ( findOtherLang ( file )) ));
8597 }
8698 }
8799 /* //用于NPC文件的判断——任务、NPC、对话、商店
0 commit comments