Version-specific release fetching for mods

This commit is contained in:
Anuken
2026-09-18 12:47:14 -04:00
parent cada4b2543
commit c58aac5f67
4 changed files with 44 additions and 14 deletions
+14 -6
View File
@@ -10,7 +10,7 @@ public class ModListing{
public boolean hasScripts, hasJava, iosCompatible, legacyCompatible, hasIcon;
/** game build -> release ID + mod version */
public @Nullable ArrayMap<String, ModRelease> releases;
public String[] contentTypes = {};
public String[] tags = {};
public int stars;
@Override
@@ -29,21 +29,29 @@ public class ModListing{
'}';
}
/** @return the specific release that matches the current game version, or null if no specific match is found (i.e. /latest should be used) */
public @Nullable ModRelease getMatchingRelease(){
if(releases == null) return null;
for(int i = 0; i < releases.size; i ++){
String key = releases.keys[i];
if(ModsDialog.matchesGameVersion(ModsDialog.parseVersion(key))){
return releases.values[i];
for(var entry : releases){
if(ModsDialog.matchesGameVersion(ModsDialog.parseVersion(entry.key))){
return entry.value;
}
}
return null;
}
public static class ModRelease{
/** Github release ID */
/** Github release ID ($API/releases/$ID) */
public String id = "";
/** Actual mod version string in release's mod.json */
public String version = "";
@Override
public String toString(){
return "ModRelease{" +
"id='" + id + '\'' +
", version='" + version + '\'' +
'}';
}
}
}
@@ -65,6 +65,11 @@ public class ModBrowserDialog extends BaseDialog{
shown(this::rebuildBrowser);
}
public @Nullable ModListing getCachedMod(String repo){
if(modList == null) return null;
return modList.find(m -> m.repo.equalsIgnoreCase(repo));
}
public void getModList(Cons<Seq<ModListing>> listener){
//mods already fetched, use that
if(modList != null){
@@ -247,7 +252,7 @@ public class ModBrowserDialog extends BaseDialog{
textureCache.put(repo, last = Core.atlas.find("nomap"));
if(mod.hasIcon){
Fi cacheFolder = Vars.mobile ? Core.files.cache("modIconCache"): dataDirectory.child("modIconCache");
Fi cacheFolder = mobile ? Core.files.cache("modIconCache"): dataDirectory.child("modIconCache");
cacheFolder.mkdirs();
Fi cacheFile = cacheFolder.child(Strings.sanitizeFilename(mod.repo + "_" + mod.iconHash) + ".png");
@@ -337,7 +342,7 @@ public class ModBrowserDialog extends BaseDialog{
var found = mods.list().find(l -> mod.repo != null && mod.repo.equals(l.getRepo()));
sel.buttons.button(found == null ? "@mods.browser.add" : "@mods.browser.reinstall", Icon.download, () -> {
sel.hide();
ui.mods.githubImportMod(mod.repo, mod.hasJava, null, true);
ui.mods.githubImportMod(mod);
});
if(Core.graphics.isPortrait()){
+22 -5
View File
@@ -109,7 +109,11 @@ public class ModsDialog extends BaseDialog{
var mod = repoToMod.get(entry.repo);
if(mod != null){
modToListing.put(mod, entry);
if(Strings.checkNewerSemver(entry.version, mod.meta.version)) withUpdates.add(mod);
var release = entry.getMatchingRelease();
//Only compare to the release that fits the current version the client is using, if one exists; don't look for updates that don't match the version
if(Strings.checkNewerSemver(entry.version, release == null ? mod.meta.version : release.version)){
withUpdates.add(mod);
}
}
}
@@ -175,8 +179,15 @@ public class ModsDialog extends BaseDialog{
if(text.startsWith("https://github.com/")) text = text.substring("https://github.com/".length());
Core.settings.put("lastmod", text);
//there's no good way to know if it's a java mod here, so assume it's not
githubImportMod(text, false, null, true);
var listing = browser.getCachedMod(text);
if(listing != null){
//auto-choose release when a listing is found
githubImportMod(listing);
}else{
//this will auto-detect whether it's java, then grab latest release unconditionally
//TODO: would be nice to grab version-appropriate release but I don't want to copy-paste browser logic for this
githubImportMod(text, false, null, true);
}
});
}).margin(12f);
});
@@ -530,7 +541,7 @@ public class ModsDialog extends BaseDialog{
}
}
public void viewReleases(String repo, boolean isJava, boolean reinstall) {
public void viewReleases(String repo, boolean isJava, boolean reinstall){
BaseDialog load = new BaseDialog("");
load.cont.add("[accent]" + Core.bundle.get("mods.browser.fetching"));
load.show();
@@ -600,6 +611,11 @@ public class ModsDialog extends BaseDialog{
}));
}
public void githubImportMod(ModListing mod){
var matchingRelease = mod.getMatchingRelease();
githubImportMod(mod.repo, mod.hasJava, matchingRelease == null ? null : matchingRelease.id, true);
}
public void githubImportMod(String repo, boolean isJava, boolean forceEnable){
githubImportMod(repo, isJava, null, forceEnable);
}
@@ -699,7 +715,8 @@ public class ModsDialog extends BaseDialog{
while(m.find()){
if(m.start() == 0 || m.end() == str.length()){
int major = Strings.parseInt(m.group(1));
if(major == Integer.MIN_VALUE) return null;
//any major version below 15 is likely a major-version tag like [v7] and should be ignored
if(major == Integer.MIN_VALUE || major < 15) return null;
int minor = m.group(2) != null ? Strings.parseInt(m.group(2)) : 0;
if(minor == Integer.MIN_VALUE) return null;
return new int[]{major, minor};
+1 -1
View File
@@ -26,4 +26,4 @@ org.gradle.caching=true
org.gradle.internal.http.socketTimeout=100000
org.gradle.internal.http.connectionTimeout=100000
android.enableR8.fullMode=false
archash=68a04fab6e
archash=4a83c3a235