LunaChat v3-k2 : Added event mocks. (WIP)
このコミットが含まれているのは:
1 親
7abc57f9ac
コミット
75fe8a98ec
40ファイル変更
+3127
-2031
検索条件に一致するファイルはありません
@@ -5,8 +5,14 @@
|
||||
*/
|
||||
package com.github.ucchyocean.lc3.tool;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -18,11 +24,62 @@ import com.github.ucchyocean.lc3.YamlConfig;
|
||||
*/
|
||||
public class MessageParser {
|
||||
|
||||
private static final String FILE_PATH = "src/main/resources/messages_ja.yml";
|
||||
private static final String INPUT_FILE_PATH = "src/main/resources/messages_ja.yml";
|
||||
private static final String OUTPUT_FILE_PATH = "src/main/java/com/github/ucchyocean/lc3/Messages.java";
|
||||
|
||||
private static final String START_MARKER = " // === Auto-generated methods area start. ===";
|
||||
private static final String END_MARKER = " // === Auto-generated methods area end. ===";
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
YamlConfig yaml = YamlConfig.load(new File(FILE_PATH));
|
||||
// 自動生成メソッドを作成する
|
||||
List<String> methods = makeAutoGeneratedMethods();
|
||||
|
||||
// 出力ファイルを全行読み取る
|
||||
File file = new File(OUTPUT_FILE_PATH);
|
||||
List<String> contents = readAllLines(file);
|
||||
|
||||
// START_MARKERが出てくるまで読み進める
|
||||
List<String> result = new ArrayList<>();
|
||||
int index = 0;
|
||||
while ( !contents.get(index).equals(START_MARKER) ) {
|
||||
result.add(contents.get(index));
|
||||
index++;
|
||||
if ( contents.size() <= index ) {
|
||||
System.err.println("ERROR! : START_MARKER not found.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
result.add(contents.get(index));
|
||||
index++;
|
||||
|
||||
// 自動生成メソッドを挿入する
|
||||
result.addAll(methods);
|
||||
|
||||
// END_MARKERが出てくるまで読み捨てる
|
||||
while ( !contents.get(index).equals(END_MARKER) ) {
|
||||
index++;
|
||||
if ( contents.size() <= index ) {
|
||||
System.err.println("ERROR! : END_MARKER not found.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 残りをそのまま読み込む
|
||||
while ( contents.size() > index ) {
|
||||
result.add(contents.get(index));
|
||||
index++;
|
||||
}
|
||||
|
||||
// ファイルへ出力
|
||||
writeAllLines(file, result);
|
||||
}
|
||||
|
||||
private static List<String> makeAutoGeneratedMethods() {
|
||||
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
YamlConfig yaml = YamlConfig.load(new File(INPUT_FILE_PATH));
|
||||
for ( String key : yaml.getKeys(false) ) {
|
||||
String value = yaml.getString(key);
|
||||
|
||||
@@ -42,29 +99,55 @@ public class MessageParser {
|
||||
}
|
||||
|
||||
// 出力
|
||||
System.out.println();
|
||||
System.out.println(" /**");
|
||||
System.out.println(" * " + value);
|
||||
System.out.println(" */");
|
||||
System.out.println(String.format(
|
||||
result.add("");
|
||||
result.add(" /**");
|
||||
result.add(" * " + value);
|
||||
result.add(" */");
|
||||
result.add(String.format(
|
||||
" public static String %s(%s) {", key, arguments));
|
||||
System.out.println(String.format(
|
||||
result.add(String.format(
|
||||
" String msg = resources.getString(\"%s\");", key));
|
||||
System.out.println(String.format(
|
||||
result.add(String.format(
|
||||
" if ( msg == null ) return \"\";", key));
|
||||
|
||||
for ( String keyword : keywords ) {
|
||||
System.out.println(String.format(
|
||||
result.add(String.format(
|
||||
" msg = msg.replace(\"%%%s%%\", %s.toString());", keyword, keyword));
|
||||
}
|
||||
if ( key.startsWith("errmsg") ) {
|
||||
System.out.println(" return Utility.replaceColorCode(resources.getString(\"errorPrefix\", \"\") + msg);");
|
||||
result.add(" return Utility.replaceColorCode(resources.getString(\"errorPrefix\", \"\") + msg);");
|
||||
} else if ( key.startsWith("cmdmsg") ) {
|
||||
System.out.println(" return Utility.replaceColorCode(resources.getString(\"infoPrefix\", \"\") + msg);");
|
||||
result.add(" return Utility.replaceColorCode(resources.getString(\"infoPrefix\", \"\") + msg);");
|
||||
} else {
|
||||
System.out.println(" return Utility.replaceColorCode(msg);");
|
||||
result.add(" return Utility.replaceColorCode(msg);");
|
||||
}
|
||||
System.out.println(" }");
|
||||
result.add(" }");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<String> readAllLines(File file) {
|
||||
List<String> lines = new ArrayList<>();
|
||||
try ( BufferedReader reader = new BufferedReader(new FileReader(file)) ) {
|
||||
String line;
|
||||
while ( (line = reader.readLine()) != null ) {
|
||||
lines.add(line);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
private static void writeAllLines(File file, List<String> lines) {
|
||||
try ( BufferedWriter writer = new BufferedWriter(new FileWriter(file)) ) {
|
||||
for ( String line : lines ) {
|
||||
writer.write(line);
|
||||
writer.newLine();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする