Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化模组翻译匹配 #3231

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ static class ModInfoObject extends RecursiveTreeObject<ModInfoObject> implements
message.append(", ").append(i18n("archive.author")).append(": ").append(localModFile.getAuthors());
this.message = message.toString();

this.mod = ModTranslations.MOD.getModById(localModFile.getId());
this.mod = ModTranslations.MOD.getMod(localModFile.getName(), localModFile.getId());
}

String getTitle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static ModTranslations getTranslationsByRepositoryType(RemoteModRepositor

private final String resourceName;
private List<Mod> mods;
private Map<String, Mod> modIdMap; // mod id -> mod
private Map<String, Mod> modMap; // mod id and subname -> mod
private Map<String, Mod> curseForgeMap; // curseforge id -> mod
private List<Pair<String, Mod>> keywords;
private int maxKeywordLength = -1;
Expand All @@ -84,10 +84,19 @@ public Mod getModByCurseForgeId(String id) {
}

@Nullable
public Mod getModById(String id) {
if (StringUtils.isBlank(id) || !loadModIdMap()) return null;
public Mod getMod(String subname, String id) {
if (!loadModMap()) return null;

return modIdMap.get(id);
if (StringUtils.isNotBlank(subname)) {
String filteredSubName = "subname-" + subname.replaceAll("[^a-zA-Z]", "");
return modMap.get(filteredSubName);
}

if (StringUtils.isNotBlank(id)) {
return modMap.get(id);
}

return null;
Comment on lines +90 to +99
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yushijinhun 已改成优先使用 subname 匹配,如果没有 subname 则使用 id 进行匹配

}

public abstract String getMcmodUrl(Mod mod);
Expand Down Expand Up @@ -149,20 +158,27 @@ private boolean loadCurseForgeMap() {
return true;
}

private boolean loadModIdMap() {
if (modIdMap != null) {
private boolean loadModMap() {
if (modMap != null) {
return true;
}

if (mods == null) {
if (!loadFromResource()) return false;
}

modIdMap = new HashMap<>();
modMap = new HashMap<>();
for (Mod mod : mods) {
String subname = mod.getSubname();
if (StringUtils.isNotBlank(subname) && !"examplemod".equals(subname)) {
String filteredSubName = "subname-" + subname.replaceAll("[^a-zA-Z]", "");
if (!filteredSubName.isEmpty()) {
modMap.put(filteredSubName, mod);
}
}
for (String id : mod.getModIds()) {
if (StringUtils.isNotBlank(id) && !"examplemod".equals(id)) {
modIdMap.put(id, mod);
modMap.put(id, mod);
}
}
}
Expand Down
Loading