This commit is contained in:
ThePythonGuy
2020-07-31 16:06:42 +02:00
committed by GitHub
parent 2e09373fdc
commit 451a4faa5b
+14 -10
View File
@@ -152,8 +152,8 @@ 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) {
@@ -162,30 +162,31 @@ public class ModsDialog extends BaseDialog{
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, () -> {
ui.loadfrag.show();
Core.net.httpGet("http://api.github.com/repos/" + modsbrolist.repo + "/zipball/master", loc -> { Core.net.httpGet("http://api.github.com/repos/" + modsbrolist.repo + "/zipball/master", loc -> {
Core.net.httpGet(loc.getHeader("Location"), result -> { Core.net.httpGet(loc.getHeader("Location"), result -> {
if(result.getStatus() != HttpStatus.OK){ if (result.getStatus() != HttpStatus.OK) {
ui.showErrorMessage(Core.bundle.format("connectfail", result.getStatus())); ui.showErrorMessage(Core.bundle.format("connectfail", result.getStatus()));
ui.loadfrag.hide(); ui.loadfrag.hide();
}else{ } else {
try{ try {
Fi file = tmpDirectory.child((modsbrolist.repo).replace("/", "") + ".zip"); Fi file = tmpDirectory.child((modsbrolist.repo).replace("/", "") + ".zip");
Streams.copy(result.getResultAsStream(), file.write(false)); Streams.copy(result.getResultAsStream(), file.write(false));
mods.importMod(file); mods.importMod(file);
file.delete(); file.delete();
Core.app.post(() -> { Core.app.post(() -> {
try{ try {
setup(); setup();
ui.loadfrag.hide(); ui.loadfrag.hide();
}catch(Throwable e){ } catch (Throwable e) {
ui.showException(e); ui.showException(e);
} }
}); });
}catch(Throwable e){ } catch (Throwable e) {
modError(e); modError(e);
} }
} }
@@ -194,6 +195,7 @@ public class ModsDialog extends BaseDialog{
}).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);