This commit is contained in:
ThePythonGuy
2020-07-31 16:06:42 +02:00
committed by GitHub
parent 2e09373fdc
commit 451a4faa5b

View File

@@ -152,47 +152,49 @@ public class ModsDialog extends BaseDialog{
tablebrow.margin(10f).top(); tablebrow.margin(10f).top();
Core.net.httpGet("https://raw.githubusercontent.com/Anuken/MindustryMods/master/mods.json", response -> { Core.net.httpGet("https://raw.githubusercontent.com/Anuken/MindustryMods/master/mods.json", response -> {
if (response.getStatus() != HttpStatus.OK) { if (response.getStatus() != HttpStatus.OK) {
return; ui.showErrorMessage(Core.bundle.format("connectfail", response.getStatus()));
} } else {
Json json = new Json(); Json json = new Json();
Seq<ModListing> listings = json.fromJson(Seq.class, ModListing.class, response.getResultAsString()); Seq<ModListing> listings = json.fromJson(Seq.class, ModListing.class, response.getResultAsString());
for (ModListing modsbrolist : listings) { for (ModListing modsbrolist : listings) {
tablebrow.button(btn -> { tablebrow.button(btn -> {
btn.top().left(); btn.top().left();
btn.margin(12f); btn.margin(12f);
btn.table(con -> { btn.table(con -> {
con.left(); con.left();
con.add("[lightgray]Name:[] " + modsbrolist.name + "\n[lightgray]Author:[] " + modsbrolist.author + "\n[]Stars: " + modsbrolist.stars + "\n" + modsbrolist.description).wrap().width(380f).growX(); con.add("[lightgray]Name:[] " + modsbrolist.name + "\n[lightgray]Author:[] " + modsbrolist.author + "\n[]Stars: " + modsbrolist.stars + "\n" + modsbrolist.description).wrap().width(380f).growX().get().setWrap(true);
con.add().growX(); con.add().growX();
}).fillY(); }).fillY();
}, Styles.clearPartialt, () -> { }, Styles.clearPartialt, () -> {
Core.net.httpGet("http://api.github.com/repos/" + modsbrolist.repo + "/zipball/master", loc -> { ui.loadfrag.show();
Core.net.httpGet(loc.getHeader("Location"), result -> { Core.net.httpGet("http://api.github.com/repos/" + modsbrolist.repo + "/zipball/master", loc -> {
if(result.getStatus() != HttpStatus.OK){ Core.net.httpGet(loc.getHeader("Location"), result -> {
ui.showErrorMessage(Core.bundle.format("connectfail", result.getStatus())); if (result.getStatus() != HttpStatus.OK) {
ui.loadfrag.hide(); ui.showErrorMessage(Core.bundle.format("connectfail", result.getStatus()));
}else{ ui.loadfrag.hide();
try{ } else {
Fi file = tmpDirectory.child((modsbrolist.repo).replace("/", "") + ".zip"); try {
Streams.copy(result.getResultAsStream(), file.write(false)); Fi file = tmpDirectory.child((modsbrolist.repo).replace("/", "") + ".zip");
mods.importMod(file); Streams.copy(result.getResultAsStream(), file.write(false));
file.delete(); mods.importMod(file);
Core.app.post(() -> { file.delete();
try{ Core.app.post(() -> {
setup(); try {
ui.loadfrag.hide(); setup();
}catch(Throwable e){ ui.loadfrag.hide();
ui.showException(e); } catch (Throwable e) {
} ui.showException(e);
}); }
}catch(Throwable e){ });
modError(e); } catch (Throwable e) {
modError(e);
}
} }
} }, t2 -> Core.app.post(() -> modError(t2)));
}, t2 -> Core.app.post(() -> modError(t2))); }, t2 -> Core.app.post(() -> modError(t2)));
}, t2 -> Core.app.post(() -> modError(t2))); }).width(380f).margin(15f).growX().left().fillY();
}).width(380f).margin(15f).growX().left().fillY(); tablebrow.row();
tablebrow.row(); }
} }
}, error -> { }, error -> {
ui.showErrorMessage(error.toString()); ui.showErrorMessage(error.toString());
@@ -201,7 +203,9 @@ public class ModsDialog extends BaseDialog{
}); });
dialog2.addCloseButton(); dialog2.addCloseButton();
dialog2.show(); dialog2.show();
}catch (Exception ignored){ } }catch (Exception e){
//ignore
}
}).margin(12f); }).margin(12f);