Selectable mod releases (#7079)
* filterable power node connections * selectable mod releases * Update contributors * selectable mod releases * Update contributors * Revert "Merge branch 'master' of https://github.com/KayyAyeAre/Mindustry" This reverts commit1f210a898a, reversing changes made to8ba6d4b2aa. * move the release selection to a new button
This commit is contained in:
@@ -44,7 +44,12 @@ mods.browser = Mod Browser
|
|||||||
mods.browser.selected = Selected mod
|
mods.browser.selected = Selected mod
|
||||||
mods.browser.add = Install
|
mods.browser.add = Install
|
||||||
mods.browser.reinstall = Reinstall
|
mods.browser.reinstall = Reinstall
|
||||||
|
mods.browser.view-releases = View Releases
|
||||||
|
mods.browser.noreleases = [scarlet]No Releases Found\n[accent]Couldn't find any releases for this mod. Check if the mod's repository has any releases published.
|
||||||
|
mods.browser.latest = <Latest>
|
||||||
|
mods.browser.releases = Releases
|
||||||
mods.github.open = Repo
|
mods.github.open = Repo
|
||||||
|
mods.github.open-release = Release Page
|
||||||
mods.browser.sortdate = Sort by recent
|
mods.browser.sortdate = Sort by recent
|
||||||
mods.browser.sortstars = Sort by stars
|
mods.browser.sortstars = Sort by stars
|
||||||
|
|
||||||
|
|||||||
@@ -142,3 +142,4 @@ xem8k5小恶魔
|
|||||||
BlueWolf
|
BlueWolf
|
||||||
[Error_27]
|
[Error_27]
|
||||||
code-explorer786
|
code-explorer786
|
||||||
|
KayAyeAre
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import arc.struct.*;
|
|||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import arc.util.io.*;
|
import arc.util.io.*;
|
||||||
import arc.util.serialization.*;
|
import arc.util.serialization.*;
|
||||||
|
import arc.util.serialization.Jval.*;
|
||||||
import mindustry.*;
|
import mindustry.*;
|
||||||
import mindustry.core.*;
|
import mindustry.core.*;
|
||||||
import mindustry.ctype.*;
|
import mindustry.ctype.*;
|
||||||
@@ -192,7 +193,7 @@ public class ModsDialog extends BaseDialog{
|
|||||||
|
|
||||||
Core.settings.put("lastmod", text);
|
Core.settings.put("lastmod", text);
|
||||||
//there's no good way to know if it's a java mod here, so assume it's not
|
//there's no good way to know if it's a java mod here, so assume it's not
|
||||||
githubImportMod(text, false);
|
githubImportMod(text, false, null);
|
||||||
});
|
});
|
||||||
}).margin(12f);
|
}).margin(12f);
|
||||||
});
|
});
|
||||||
@@ -348,7 +349,7 @@ public class ModsDialog extends BaseDialog{
|
|||||||
boolean showImport = !mod.hasSteamID();
|
boolean showImport = !mod.hasSteamID();
|
||||||
dialog.buttons.button("@mods.github.open", Icon.link, () -> Core.app.openURI("https://github.com/" + mod.getRepo()));
|
dialog.buttons.button("@mods.github.open", Icon.link, () -> Core.app.openURI("https://github.com/" + mod.getRepo()));
|
||||||
if(mobile && showImport) dialog.buttons.row();
|
if(mobile && showImport) dialog.buttons.row();
|
||||||
if(showImport) dialog.buttons.button("@mods.browser.reinstall", Icon.download, () -> githubImportMod(mod.getRepo(), mod.isJava()));
|
if(showImport) dialog.buttons.button("@mods.browser.reinstall", Icon.download, () -> githubImportMod(mod.getRepo(), mod.isJava(), null));
|
||||||
}
|
}
|
||||||
|
|
||||||
dialog.cont.pane(desc -> {
|
dialog.cont.pane(desc -> {
|
||||||
@@ -495,11 +496,59 @@ public class ModsDialog extends BaseDialog{
|
|||||||
var found = mods.list().find(l -> mod.repo != null && mod.repo.equals(l.getRepo()));
|
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.buttons.button(found == null ? "@mods.browser.add" : "@mods.browser.reinstall", Icon.download, () -> {
|
||||||
sel.hide();
|
sel.hide();
|
||||||
githubImportMod(mod.repo, mod.hasJava);
|
githubImportMod(mod.repo, mod.hasJava, null);
|
||||||
});
|
});
|
||||||
sel.buttons.button("@mods.github.open", Icon.link, () -> {
|
sel.buttons.button("@mods.github.open", Icon.link, () -> {
|
||||||
Core.app.openURI("https://github.com/" + mod.repo);
|
Core.app.openURI("https://github.com/" + mod.repo);
|
||||||
});
|
});
|
||||||
|
sel.buttons.button("@mods.browser.view-releases", Icon.zoom, () -> {
|
||||||
|
BaseDialog load = new BaseDialog("");
|
||||||
|
load.cont.add("[accent]Fetching Releases...");
|
||||||
|
load.show();
|
||||||
|
Http.get(ghApi + "/repos/" + mod.repo + "/releases", res -> {
|
||||||
|
load.hide();
|
||||||
|
var json = Jval.read(res.getResultAsString());
|
||||||
|
JsonArray releases = json.asArray();
|
||||||
|
|
||||||
|
if(releases.size == 0){
|
||||||
|
ui.showInfo("@mods.browser.noreleases");
|
||||||
|
}else{
|
||||||
|
sel.hide();
|
||||||
|
BaseDialog downloads = new BaseDialog("@mods.browser.releases");
|
||||||
|
downloads.cont.pane(p -> {
|
||||||
|
for(int j = 0; j < releases.size; j++){
|
||||||
|
var release = releases.get(j);
|
||||||
|
|
||||||
|
int index = j;
|
||||||
|
p.table(((TextureRegionDrawable) Tex.whiteui).tint(Pal.darkestGray), t -> {
|
||||||
|
t.add((index == 0 ? Core.bundle.get("mods.browser.latest") + " " : "") + release.getString("name")).top().left().growX().wrap().pad(5f).color(Pal.accent);
|
||||||
|
t.row();
|
||||||
|
t.add((release.getString("published_at")).substring(0, 10).replaceAll("-", "/")).top().left().growX().wrap().pad(5f).color(Color.gray);
|
||||||
|
t.table(b -> {
|
||||||
|
b.defaults().size(150f, 54f).pad(2f);
|
||||||
|
b.button("@mods.github.open-release", Icon.link, () -> Core.app.openURI(release.getString("html_url")));
|
||||||
|
b.button("@mods.browser.add", Icon.download, () -> {
|
||||||
|
String releaseUrl = release.getString("url");
|
||||||
|
githubImportMod(mod.repo, mod.hasJava, releaseUrl.substring(releaseUrl.lastIndexOf("/") + 1));
|
||||||
|
});
|
||||||
|
}).right();
|
||||||
|
}).margin(5f).growX().pad(5f);
|
||||||
|
|
||||||
|
if(j < releases.size - 1) p.row();
|
||||||
|
}
|
||||||
|
}).width(600f).scrollX(false).fillY();
|
||||||
|
downloads.buttons.button("@back", Icon.left, () -> {
|
||||||
|
downloads.clear();
|
||||||
|
downloads.hide();
|
||||||
|
sel.show();
|
||||||
|
}).size(150f, 54f).pad(2f);
|
||||||
|
downloads.keyDown(KeyCode.escape, downloads::hide);
|
||||||
|
downloads.keyDown(KeyCode.back, downloads::hide);
|
||||||
|
downloads.hidden(sel::show);
|
||||||
|
downloads.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
sel.keyDown(KeyCode.escape, sel::hide);
|
sel.keyDown(KeyCode.escape, sel::hide);
|
||||||
sel.keyDown(KeyCode.back, sel::hide);
|
sel.keyDown(KeyCode.back, sel::hide);
|
||||||
sel.show();
|
sel.show();
|
||||||
@@ -547,13 +596,13 @@ public class ModsDialog extends BaseDialog{
|
|||||||
Core.app.post(() -> modError(t));
|
Core.app.post(() -> modError(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void githubImportMod(String repo, boolean isJava){
|
private void githubImportMod(String repo, boolean isJava, @Nullable String release){
|
||||||
modImportProgress = 0f;
|
modImportProgress = 0f;
|
||||||
ui.loadfrag.show("@downloading");
|
ui.loadfrag.show("@downloading");
|
||||||
ui.loadfrag.setProgress(() -> modImportProgress);
|
ui.loadfrag.setProgress(() -> modImportProgress);
|
||||||
|
|
||||||
if(isJava){
|
if(isJava){
|
||||||
githubImportJavaMod(repo);
|
githubImportJavaMod(repo, release);
|
||||||
}else{
|
}else{
|
||||||
Http.get(ghApi + "/repos/" + repo, res -> {
|
Http.get(ghApi + "/repos/" + repo, res -> {
|
||||||
var json = Jval.read(res.getResultAsString());
|
var json = Jval.read(res.getResultAsString());
|
||||||
@@ -563,17 +612,17 @@ public class ModsDialog extends BaseDialog{
|
|||||||
//this is a crude heuristic for class mods; only required for direct github import
|
//this is a crude heuristic for class mods; only required for direct github import
|
||||||
//TODO make a more reliable way to distinguish java mod repos
|
//TODO make a more reliable way to distinguish java mod repos
|
||||||
if(language.equals("Java") || language.equals("Kotlin")){
|
if(language.equals("Java") || language.equals("Kotlin")){
|
||||||
githubImportJavaMod(repo);
|
githubImportJavaMod(repo, release);
|
||||||
}else{
|
}else{
|
||||||
githubImportBranch(mainBranch, repo);
|
githubImportBranch(mainBranch, repo, release);
|
||||||
}
|
}
|
||||||
}, this::importFail);
|
}, this::importFail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void githubImportJavaMod(String repo){
|
private void githubImportJavaMod(String repo, @Nullable String release){
|
||||||
//grab latest release
|
//grab latest release
|
||||||
Http.get(ghApi + "/repos/" + repo + "/releases/latest", res -> {
|
Http.get(ghApi + "/repos/" + repo + "/releases/" + (release == null ? "latest" : release), res -> {
|
||||||
var json = Jval.read(res.getResultAsString());
|
var json = Jval.read(res.getResultAsString());
|
||||||
var assets = json.get("assets").asArray();
|
var assets = json.get("assets").asArray();
|
||||||
|
|
||||||
@@ -592,15 +641,30 @@ public class ModsDialog extends BaseDialog{
|
|||||||
}, this::importFail);
|
}, this::importFail);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void githubImportBranch(String branch, String repo){
|
private void githubImportBranch(String branch, String repo, @Nullable String release){
|
||||||
Http.get(ghApi + "/repos/" + repo + "/zipball/" + branch, loc -> {
|
if(release != null) {
|
||||||
if(loc.getHeader("Location") != null){
|
Http.get(ghApi + "/repos/" + repo + "/releases/" + release, res -> {
|
||||||
Http.get(loc.getHeader("Location"), result -> {
|
String zipUrl = Jval.read(res.getResultAsString()).getString("zipball_url");
|
||||||
handleMod(repo, result);
|
Http.get(zipUrl, loc -> {
|
||||||
|
if(loc.getHeader("Location") != null){
|
||||||
|
Http.get(loc.getHeader("Location"), result -> {
|
||||||
|
handleMod(repo, result);
|
||||||
|
}, this::importFail);
|
||||||
|
}else{
|
||||||
|
handleMod(repo, loc);
|
||||||
|
}
|
||||||
}, this::importFail);
|
}, this::importFail);
|
||||||
}else{
|
});
|
||||||
handleMod(repo, loc);
|
}else{
|
||||||
}
|
Http.get(ghApi + "/repos/" + repo + "/zipball/" + branch, loc -> {
|
||||||
}, this::importFail);
|
if(loc.getHeader("Location") != null){
|
||||||
|
Http.get(loc.getHeader("Location"), result -> {
|
||||||
|
handleMod(repo, result);
|
||||||
|
}, this::importFail);
|
||||||
|
}else{
|
||||||
|
handleMod(repo, loc);
|
||||||
|
}
|
||||||
|
}, this::importFail);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user