From 92b2a5a76497a707e0e6ce91915f397e26bec182 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 14 Oct 2024 19:38:50 -0400 Subject: [PATCH] Fallback URL for mod list --- core/src/mindustry/Vars.java | 6 +- core/src/mindustry/ui/dialogs/ModsDialog.java | 66 +++++++++++-------- 2 files changed, 44 insertions(+), 28 deletions(-) diff --git a/core/src/mindustry/Vars.java b/core/src/mindustry/Vars.java index c838f55c15..b18ee6062f 100644 --- a/core/src/mindustry/Vars.java +++ b/core/src/mindustry/Vars.java @@ -71,10 +71,12 @@ public class Vars implements Loadable{ public static final String discordURL = "https://discord.gg/mindustry"; /** URL the links to the wiki's modding guide.*/ public static final String modGuideURL = "https://mindustrygame.github.io/wiki/modding/1-modding/"; - /** URL to the JSON file containing all the BE servers. Only queried in BE. */ + /** URLs to the JSON file containing all the BE servers. Only queried in BE. */ public static final String[] serverJsonBeURLs = {"https://raw.githubusercontent.com/Anuken/MindustryServerList/master/servers_be.json", "https://cdn.jsdelivr.net/gh/anuken/mindustryserverlist/servers_be.json"}; - /** URL to the JSON file containing all the stable servers. */ + /** URLs to the JSON file containing all the stable servers. */ public static final String[] serverJsonURLs = {"https://raw.githubusercontent.com/Anuken/MindustryServerList/master/servers_v8.json", "https://cdn.jsdelivr.net/gh/anuken/mindustryserverlist/servers_v8.json"}; + /** URLs to the JSON files containing the list of mods. */ + public static final String[] modJsonURLs = {"https://raw.githubusercontent.com/Anuken/MindustryMods/master/mods.json", "https://cdn.jsdelivr.net/gh/anuken/mindustrymods/mods.json"}; /** URL of the github issue report template.*/ public static final String reportIssueURL = "https://github.com/Anuken/Mindustry/issues/new?labels=bug&template=bug_report.md"; /** list of built-in servers.*/ diff --git a/core/src/mindustry/ui/dialogs/ModsDialog.java b/core/src/mindustry/ui/dialogs/ModsDialog.java index 193c616540..f32ef1e9d5 100644 --- a/core/src/mindustry/ui/dialogs/ModsDialog.java +++ b/core/src/mindustry/ui/dialogs/ModsDialog.java @@ -112,35 +112,49 @@ public class ModsDialog extends BaseDialog{ } } - void getModList(Cons> listener){ - if(modList == null){ - Http.get("https://raw.githubusercontent.com/Anuken/MindustryMods/master/mods.json", response -> { - String strResult = response.getResultAsString(); + void getModList(int index, Cons> listener){ + if(index >= modJsonURLs.length) return; + if(modList != null){ + listener.get(modList); + return; + } + + Http.get(modJsonURLs[index], response -> { + String strResult = response.getResultAsString(); + + Core.app.post(() -> { + try{ + modList = JsonIO.json.fromJson(Seq.class, ModListing.class, strResult); + + var d = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); + Func parser = text -> { + try{ + return d.parse(text); + }catch(Exception e){ + return new Date(); + } + }; + + modList.sortComparing(m -> parser.get(m.lastUpdated)).reverse(); + listener.get(modList); + }catch(Exception e){ + Log.err(e); + ui.showException(e); + } + }); + }, error -> { + if(index < modJsonURLs.length - 1){ + getModList(index + 1, listener); + }else{ Core.app.post(() -> { - try{ - modList = JsonIO.json.fromJson(Seq.class, ModListing.class, strResult); - - var d = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); - Func parser = text -> { - try{ - return d.parse(text); - }catch(Exception e){ - return new Date(); - } - }; - - modList.sortComparing(m -> parser.get(m.lastUpdated)).reverse(); - listener.get(modList); - }catch(Exception e){ - e.printStackTrace(); - ui.showException(e); + modError(error); + if(browser != null){ + browser.hide(); } }); - }, error -> Core.app.post(() -> modError(error))); - }else{ - listener.get(modList); - } + } + }); } void setup(){ @@ -456,7 +470,7 @@ public class ModsDialog extends BaseDialog{ int cols = (int)Math.max(Core.graphics.getWidth() / Scl.scl(480), 1); - getModList(rlistings -> { + getModList(0, rlistings -> { browserTable.clear(); int i = 0;