Tools.java 3.19 KB
Newer Older
Melledy's avatar
Melledy committed
1
2
package emu.grasscutter.tools;

3
import java.io.FileInputStream;
4
import java.io.FileOutputStream;
Melledy's avatar
Melledy committed
5
6
import java.io.FileReader;
import java.io.FileWriter;
7
import java.io.InputStreamReader;
8
import java.io.OutputStreamWriter;
Melledy's avatar
Melledy committed
9
import java.io.PrintWriter;
10
import java.nio.charset.StandardCharsets;
Melledy's avatar
Melledy committed
11
12
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
KingRainbow44's avatar
KingRainbow44 committed
13
import java.util.ArrayList;
Melledy's avatar
Melledy committed
14
15
16
17
18
19
20
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.google.gson.reflect.TypeToken;

21
import emu.grasscutter.GameConstants;
Melledy's avatar
Melledy committed
22
import emu.grasscutter.Grasscutter;
23
import emu.grasscutter.data.GameData;
Melledy's avatar
Melledy committed
24
25
26
27
import emu.grasscutter.data.ResourceLoader;
import emu.grasscutter.data.def.AvatarData;
import emu.grasscutter.data.def.ItemData;
import emu.grasscutter.data.def.MonsterData;
28
import emu.grasscutter.data.def.SceneData;
29
import emu.grasscutter.utils.Utils;
Melledy's avatar
Melledy committed
30

KingRainbow44's avatar
KingRainbow44 committed
31
public final class Tools {
Melledy's avatar
Melledy committed
32
33
34
35
36
37
	
	@SuppressWarnings("deprecation")
	public static void createGmHandbook() throws Exception {
		ResourceLoader.loadResources();
		
		Map<Long, String> map;
38
		try (InputStreamReader fileReader = new InputStreamReader(new FileInputStream(Utils.toFilePath(Grasscutter.getConfig().RESOURCE_FOLDER + "TextMap/TextMapEN.json")), StandardCharsets.UTF_8)) {
Melledy's avatar
Melledy committed
39
40
41
42
43
			map = Grasscutter.getGsonFactory().fromJson(fileReader, new TypeToken<Map<Long, String>>() {}.getType());
		}
		
		List<Integer> list;
		String fileName = "./GM Handbook.txt";
44
		try (PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(fileName), StandardCharsets.UTF_8), false)) {
Melledy's avatar
Melledy committed
45
46
47
			DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");  
			LocalDateTime now = LocalDateTime.now();
			   
48
			writer.println("// Grasscutter " + GameConstants.VERSION + " GM Handbook");
Melledy's avatar
Melledy committed
49
50
			writer.println("// Created " + dtf.format(now) + System.lineSeparator() + System.lineSeparator());
			
51
			list = new ArrayList<>(GameData.getAvatarDataMap().keySet());
Melledy's avatar
Melledy committed
52
53
54
55
			Collections.sort(list); 
			 
			writer.println("// Avatars");
			for (Integer id : list) {
56
				AvatarData data = GameData.getAvatarDataMap().get(id);
Melledy's avatar
Melledy committed
57
58
59
60
61
				writer.println(data.getId() + " : " + map.get(data.getNameTextMapHash()));
			}
			
			writer.println();
			
62
			list = new ArrayList<>(GameData.getItemDataMap().keySet());
Melledy's avatar
Melledy committed
63
64
65
66
			Collections.sort(list); 
			
			writer.println("// Items");
			for (Integer id : list) {
67
				ItemData data = GameData.getItemDataMap().get(id);
Melledy's avatar
Melledy committed
68
69
70
71
72
				writer.println(data.getId() + " : " + map.get(data.getNameTextMapHash()));
			}
			
			writer.println();
			
73
			writer.println("// Scenes");
74
			list = new ArrayList<>(GameData.getSceneDataMap().keySet());
75
76
77
			Collections.sort(list); 
			
			for (Integer id : list) {
78
				SceneData data = GameData.getSceneDataMap().get(id);
79
80
81
82
83
				writer.println(data.getId() + " : " + data.getScriptData());
			}
			
			writer.println();
			
Melledy's avatar
Melledy committed
84
			writer.println("// Monsters");
85
			list = new ArrayList<>(GameData.getMonsterDataMap().keySet());
Melledy's avatar
Melledy committed
86
87
88
			Collections.sort(list); 
			
			for (Integer id : list) {
89
				MonsterData data = GameData.getMonsterDataMap().get(id);
Melledy's avatar
Melledy committed
90
91
92
93
94
95
96
				writer.println(data.getId() + " : " + map.get(data.getNameTextMapHash()));
			}
		}
		
		Grasscutter.getLogger().info("GM Handbook generated!");
	}
}