Tools.java 2.97 KB
Newer Older
Melledy's avatar
Melledy committed
1
2
3
4
5
6
7
package emu.grasscutter.tools;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
KingRainbow44's avatar
KingRainbow44 committed
8
import java.util.ArrayList;
Melledy's avatar
Melledy committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.google.gson.reflect.TypeToken;

import emu.grasscutter.GenshinConstants;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GenshinData;
import emu.grasscutter.data.ResourceLoader;
import emu.grasscutter.data.def.AvatarData;
import emu.grasscutter.data.def.ItemData;
import emu.grasscutter.data.def.MonsterData;
23
import emu.grasscutter.data.def.SceneData;
24
import emu.grasscutter.utils.Utils;
Melledy's avatar
Melledy committed
25

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