Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.

Commit f57e22b

Browse files
committed
clean
1 parent f2e7b5b commit f57e22b

5 files changed

Lines changed: 202 additions & 207 deletions

File tree

build.gradle

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,9 @@ architectury {
1010
subprojects {
1111
apply plugin: "dev.architectury.loom"
1212

13-
loom {
14-
silentMojangMappingsLicense()
15-
}
16-
1713
dependencies {
1814
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
19-
mappings loom.officialMojangMappings()
20-
// mappings "net.fabricmc:yarn:1.19.2+build.3:v2"
15+
mappings "net.fabricmc:yarn:1.20.1+build.10:v2"
2116
}
2217
}
2318

Lines changed: 199 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,224 @@
11
package org.localmc.tools.ftbqkeys;
22

3+
import com.google.common.collect.Lists;
34
import com.google.gson.Gson;
45
import com.google.gson.GsonBuilder;
6+
import com.mojang.brigadier.arguments.StringArgumentType;
7+
import com.mojang.brigadier.tree.ArgumentCommandNode;
8+
import com.mojang.brigadier.tree.LiteralCommandNode;
9+
import com.mojang.brigadier.tree.RootCommandNode;
510
import dev.architectury.event.events.common.CommandRegistrationEvent;
611
import dev.architectury.platform.Platform;
12+
import dev.ftb.mods.ftbquests.api.FTBQuestsAPI;
13+
import dev.ftb.mods.ftbquests.quest.*;
14+
import dev.ftb.mods.ftbquests.quest.loot.RewardTable;
15+
import dev.ftb.mods.ftbquests.quest.reward.Reward;
16+
import dev.ftb.mods.ftbquests.quest.task.Task;
17+
import net.minecraft.client.MinecraftClient;
18+
import net.minecraft.command.CommandSource;
19+
import net.minecraft.server.command.CommandManager;
20+
import net.minecraft.server.command.ServerCommandSource;
21+
import net.minecraft.text.Text;
722
import org.apache.commons.io.FileUtils;
8-
import org.localmc.tools.ftbqkeys.command.FTBQKeysCommand;
23+
import org.localmc.tools.ftbqkeys.mixin.BaseQuestFileAccessor;
24+
import org.localmc.tools.ftbqkeys.mixin.ChapterImageMixin;
925

1026
import java.io.File;
1127
import java.io.IOException;
1228
import java.nio.charset.StandardCharsets;
1329
import java.nio.file.Path;
14-
import java.util.Locale;
15-
import java.util.TreeMap;
30+
import java.util.*;
31+
import java.util.function.Function;
32+
import java.util.regex.Matcher;
33+
import java.util.regex.Pattern;
1634

1735
public class FTBQKeysMod {
1836
public static final String MODID = "ftbqkeys";
1937
public static final Path gameDir = Platform.getGameFolder();
2038
public static final Path configDir = Platform.getConfigFolder();
2139
public static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
2240

41+
// https://github.com/shedaniel/RoughlyEnoughItems/blob/21d144a7b605169578ba8e1dc1663d1ab042660d/api/src/main/java/me/shedaniel/rei/api/client/search/method/InputMethod.java#L60C42-L60C42
42+
private static List<String> getLocales() {
43+
return map(MinecraftClient.getInstance().getLanguageManager().getAllLanguages().entrySet(), Map.Entry::getKey);
44+
}
45+
46+
// https://github.com/shedaniel/RoughlyEnoughItems/blob/21d144a7b605169578ba8e1dc1663d1ab042660d/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java#L125
47+
private static <T, R> List<R> map(Collection<T> list, Function<T, R> function) {
48+
List<R> l = new ArrayList<>(list.size() + 1);
49+
for (T t : list) {
50+
l.add(function.apply(t));
51+
}
52+
return l;
53+
}
54+
2355
public static void saveLang(TreeMap<String, String> transKeys, String lang, File parent) throws IOException {
24-
File fe = new File(parent, lang.toLowerCase(Locale.ROOT) + ".json");
25-
FileUtils.write(fe, FTBQKeysMod.gson.toJson(transKeys), StandardCharsets.UTF_8);
56+
File langFile = new File(parent, lang.toLowerCase(Locale.ROOT) + ".json");
57+
FileUtils.write(langFile, FTBQKeysMod.gson.toJson(transKeys), StandardCharsets.UTF_8);
2658
}
2759

2860
public static void init() {
29-
CommandRegistrationEvent.EVENT.register(FTBQKeysCommand::serverRegisterCommandsEvent);
61+
CommandRegistrationEvent.EVENT.register((dispatcher, registry, selection) -> {
62+
RootCommandNode<ServerCommandSource> rootCommandNode = dispatcher.getRoot();
63+
LiteralCommandNode<ServerCommandSource> commandNode = CommandManager.literal("ftbqkey").executes(context -> 0).build();
64+
65+
ArgumentCommandNode<ServerCommandSource, String> argumentCommandNode = CommandManager.argument("lang", StringArgumentType.word()).suggests((commandContext, suggestionsBuilder) -> CommandSource.suggestMatching(getLocales().toArray(new String[0]), suggestionsBuilder)).executes(context -> {
66+
try {
67+
File parent = new File(FTBQKeysMod.gameDir.toFile(), "ftbqkeys");
68+
File transFiles = new File(parent, "export-lang/");
69+
File questsFolder = new File(FTBQKeysMod.configDir.toFile(), "ftbquests/");
70+
71+
if (questsFolder.exists()) {
72+
File backup = new File(parent, "backup/ftbquests");
73+
FileUtils.copyDirectory(questsFolder, backup);
74+
}
75+
76+
TreeMap<String, String> transKeys = new TreeMap<>();
77+
BaseQuestFile file = FTBQuestsAPI.api().getQuestFile(false);
78+
79+
for (int i = 0; i < file.getRewardTables().size(); i++) {
80+
RewardTable table = file.getRewardTables().get(i);
81+
82+
transKeys.put("loot_table." + (i + 1), table.getRawTitle());
83+
table.getRawTitle().compareTo("{" + "loot_table." + (i + 1) + "}");
84+
}
85+
86+
for (int i = 0; i < ((BaseQuestFileAccessor) file).getChapterGroups().size(); i++) {
87+
ChapterGroup chapterGroup = ((BaseQuestFileAccessor) file).getChapterGroups().get(i);
88+
89+
if (!chapterGroup.getRawTitle().isBlank()) {
90+
transKeys.put("category." + (i + 1), chapterGroup.getRawTitle());
91+
chapterGroup.getRawTitle().compareTo("{" + "category." + (i + 1) + "}");
92+
}
93+
}
94+
95+
for (int i = 0; i < file.getAllChapters().size(); i++) {
96+
Chapter chapter = file.getAllChapters().get(i);
97+
98+
String prefix = "chapter." + (i + 1);
99+
100+
if (!chapter.getRawTitle().isBlank()) {
101+
transKeys.put(prefix + ".title", chapter.getRawTitle());
102+
chapter.getRawTitle().compareTo("{" + prefix + ".title" + "}");
103+
}
104+
105+
if (chapter.getRawSubtitle().size() > 0) {
106+
transKeys.put(prefix + ".subtitle", String.join("\n", chapter.getRawTitle()));
107+
chapter.getRawSubtitle().clear();
108+
chapter.getRawSubtitle().add("{" + prefix + ".subtitle" + "}");
109+
}
110+
111+
112+
for (int i1 = 0; i1 < chapter.images().toList().size(); i1++) {
113+
ChapterImage chapterImage = chapter.images().toList().get(i1);
114+
List<String> hover = new ChapterImageMixin().getHovers();
115+
116+
if (!hover.isEmpty()) {
117+
transKeys.put(prefix + ".image." + (i1 + 1), String.join("\n", hover));
118+
hover.clear();
119+
hover.add("{" + prefix + ".image." + (i1 + 1) + "}");
120+
}
121+
}
122+
123+
for (int i1 = 0; i1 < chapter.getQuests().size(); i1++) {
124+
Quest quest = chapter.getQuests().get(i1);
125+
126+
if (!quest.getRawTitle().isBlank()) {
127+
transKeys.put(prefix + ".quest." + (i1 + 1) + ".title", quest.getRawTitle());
128+
quest.getRawTitle().compareTo("{" + prefix + ".quest." + (i1 + 1) + ".title}");
129+
}
130+
131+
if (!quest.getRawSubtitle().isBlank()) {
132+
transKeys.put(prefix + ".quest." + (i1 + 1) + ".subtitle", quest.getRawTitle());
133+
quest.getRawSubtitle().compareTo("{" + prefix + ".quest." + (i1 + 1) + ".subtitle" + "}");
134+
}
135+
136+
if (quest.getRawDescription().size() > 0) {
137+
List<String> descList = Lists.newArrayList();
138+
139+
StringJoiner joiner = new StringJoiner("\n");
140+
int num = 1;
141+
142+
for (int i2 = 0; i2 < quest.getRawDescription().size(); i2++) {
143+
String desc = quest.getRawDescription().get(i2);
144+
145+
final String regex = "\\{image:.*?}";
146+
147+
if (desc.contains("{image:")) {
148+
if (!joiner.toString().isBlank()) {
149+
transKeys.put(prefix + ".quest." + (i1 + 1) + ".description." + num, joiner.toString());
150+
descList.add("{" + prefix + ".quest." + (i1 + 1) + ".description." + num + "}");
151+
joiner = new StringJoiner("\n");
152+
num++;
153+
}
154+
155+
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
156+
final Matcher matcher = pattern.matcher(desc);
157+
158+
while (matcher.find()) {
159+
desc = desc.replace(matcher.group(0), "");
160+
descList.add(matcher.group(0));
161+
}
162+
} else {
163+
if (desc.isBlank()) {
164+
joiner.add("\n");
165+
} else {
166+
joiner.add(desc);
167+
}
168+
}
169+
}
170+
171+
if (!joiner.toString().isBlank()) {
172+
transKeys.put(prefix + ".quest." + (i1 + 1) + ".description." + num, joiner.toString());
173+
descList.add("{" + prefix + ".quest." + (i1 + 1) + ".description." + num + "}");
174+
}
175+
176+
quest.getRawDescription().clear();
177+
quest.getRawDescription().addAll(descList);
178+
}
179+
180+
for (int i2 = 0; i2 < quest.getTasks().size(); i2++) {
181+
Task task = quest.getQuestFile().getTask(i2);
182+
183+
if (!task.getRawTitle().isBlank()) {
184+
transKeys.put(prefix + ".quest." + (i1 + 1) + ".task." + (i2 + 1) + ".title", task.getRawTitle());
185+
task.getRawTitle().compareTo("{" + prefix + ".quest." + (i1 + 1) + ".task." + (i2 + 1) + ".title}");
186+
}
187+
}
188+
189+
for (int i2 = 0; i2 < quest.getRewards().size(); i2++) {
190+
Reward reward = quest.getQuestFile().getReward(i2);
191+
192+
if (!reward.getRawTitle().isBlank()) {
193+
transKeys.put(prefix + ".quest." + (i1 + 1) + ".reward." + (i2 + 1) + ".title", reward.getRawTitle());
194+
reward.getRawTitle().compareTo("{" + prefix + ".quest." + (i1 + 1) + ".reward." + (i2 + 1) + ".title}");
195+
}
196+
}
197+
}
198+
}
199+
200+
File output = new File(parent, "config/ftbquests");
201+
202+
file.writeDataFull(output.toPath());
203+
204+
String lang = context.getArgument("lang", String.class);
205+
saveLang(transKeys, lang, transFiles);
206+
207+
if (!lang.equalsIgnoreCase("en_us")) {
208+
saveLang(transKeys, "en_us", transFiles);
209+
}
210+
211+
context.getSource().sendMessage(Text.translatable("command.ftbqkeys.message", parent.getAbsolutePath()));
212+
213+
} catch (Exception e) {
214+
e.printStackTrace();
215+
}
216+
217+
return 1;
218+
}).build();
219+
220+
rootCommandNode.addChild(commandNode);
221+
commandNode.addChild(argumentCommandNode);
222+
});
30223
}
31224
}

0 commit comments

Comments
 (0)