Refactored almost every class, somehow didn't break game yet
This commit is contained in:
53
desktop/src/io/anuke/mindustry/desktop/CrashHandler.java
Normal file
53
desktop/src/io/anuke/mindustry/desktop/CrashHandler.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package io.anuke.mindustry.desktop;
|
||||
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class CrashHandler {
|
||||
|
||||
public static void handle(Throwable e){
|
||||
//TODO send full error report to server via HTTP
|
||||
e.printStackTrace();
|
||||
|
||||
//attempt to close connections, if applicable
|
||||
try{
|
||||
Net.dispose();
|
||||
}catch (Throwable p){
|
||||
p.printStackTrace();
|
||||
}
|
||||
|
||||
//don't create crash logs for me (anuke), as it's expected
|
||||
if(System.getProperty("user.name").equals("anuke")) return;
|
||||
|
||||
//parse exception
|
||||
String result = Strings.parseException(e, true);
|
||||
boolean failed = false;
|
||||
|
||||
String filename = "";
|
||||
|
||||
//try to write it
|
||||
try{
|
||||
filename = "crash-report-" + new SimpleDateFormat("dd-MM-yy h.mm.ss").format(new Date()) + ".txt";
|
||||
Files.write(Paths.get(filename), result.getBytes());
|
||||
}catch (Throwable i){
|
||||
i.printStackTrace();
|
||||
failed = true;
|
||||
}
|
||||
|
||||
try{
|
||||
JOptionPane.showMessageDialog(null, "An error has occured: \n" + result + "\n\n" +
|
||||
(!failed ? "A crash report has been written to " + new File(filename).getAbsolutePath() + ".\nPlease send this file to the developer!"
|
||||
: "Failed to generate crash report.\nPlease send an image of this crash log to the developer!"));
|
||||
}catch (Throwable i){
|
||||
i.printStackTrace();
|
||||
//what now?
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,12 @@
|
||||
package io.anuke.mindustry.desktop;
|
||||
|
||||
import club.minnced.discord.rpc.DiscordEventHandlers;
|
||||
import club.minnced.discord.rpc.DiscordRPC;
|
||||
import club.minnced.discord.rpc.DiscordRichPresence;
|
||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
|
||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.kryonet.KryoClient;
|
||||
import io.anuke.kryonet.KryoServer;
|
||||
import io.anuke.mindustry.Mindustry;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.io.PlatformFunction;
|
||||
import io.anuke.mindustry.io.Platform;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.DateFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
public class DesktopLauncher {
|
||||
|
||||
@@ -37,114 +18,15 @@ public class DesktopLauncher {
|
||||
config.setWindowedMode(960, 540);
|
||||
config.setWindowIcon("sprites/icon.png");
|
||||
|
||||
DiscordRPC lib = DiscordRPC.INSTANCE;
|
||||
String applicationId = "398246104468291591";
|
||||
DiscordEventHandlers handlers = new DiscordEventHandlers();
|
||||
handlers.joinGame = secret -> {
|
||||
Platform.instance = new DesktopPlatform();
|
||||
|
||||
};
|
||||
|
||||
handlers.joinRequest = request -> {
|
||||
//TODO actual text, implementation of discord join dialog, possibly move it to Dialogs
|
||||
Vars.ui.showConfirmListen("$text.join.discord.title", "$text.join.discord", b -> {
|
||||
if(b){
|
||||
lib.Discord_Respond(request.userId, DiscordRPC.DISCORD_REPLY_YES);
|
||||
}else{
|
||||
lib.Discord_Respond(request.userId, DiscordRPC.DISCORD_REPLY_NO);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
lib.Discord_Initialize(applicationId, handlers, true, "");
|
||||
|
||||
Mindustry.platforms = new PlatformFunction(){
|
||||
DateFormat format = SimpleDateFormat.getDateTimeInstance();
|
||||
|
||||
@Override
|
||||
public String format(Date date){
|
||||
return format.format(date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String format(int number){
|
||||
return NumberFormat.getIntegerInstance().format(number);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showError(String text){
|
||||
JOptionPane.showMessageDialog(null, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocaleName(Locale locale){
|
||||
return locale.getDisplayName(locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateRPC() {
|
||||
DiscordRichPresence presence = new DiscordRichPresence();
|
||||
|
||||
if(!GameState.is(State.menu)){
|
||||
presence.state = Strings.capitalize(Vars.control.getMode().name()) + ", Solo";
|
||||
presence.details = Strings.capitalize(Vars.world.getMap().name) + " | Wave " + Vars.control.getWave();
|
||||
presence.largeImageText = "Wave " + Vars.control.getWave();
|
||||
if(Net.active() ){
|
||||
presence.partyMax = 16;
|
||||
presence.partySize = Vars.control.playerGroup.amount();
|
||||
presence.state = Strings.capitalize(Vars.control.getMode().name());
|
||||
}
|
||||
}else{
|
||||
if(Vars.ui.editor != null && Vars.ui.editor.isShown()){
|
||||
presence.state = "In Editor";
|
||||
}else {
|
||||
presence.state = "In Menu";
|
||||
}
|
||||
}
|
||||
|
||||
presence.largeImageKey = "logo";
|
||||
|
||||
lib.Discord_UpdatePresence(presence);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGameExit() {
|
||||
lib.Discord_Shutdown();
|
||||
}
|
||||
};
|
||||
|
||||
Mindustry.args = Array.with(arg);
|
||||
|
||||
//Net.setClientProvider(new JavaWebsocketClient());
|
||||
Net.setClientProvider(new KryoClient());
|
||||
Net.setServerProvider(new KryoServer());
|
||||
|
||||
try {
|
||||
new Lwjgl3Application(new Mindustry(), config);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
|
||||
//attempt to close connections
|
||||
try{ Net.dispose(); }catch (Exception p){}
|
||||
|
||||
//don't create crash logs for me (anuke), as it's expected
|
||||
if(System.getProperty("user.name").equals("anuke")) return;
|
||||
|
||||
String result = Strings.parseException(e, true);
|
||||
boolean failed = false;
|
||||
|
||||
String filename = "";
|
||||
|
||||
try{
|
||||
filename = "crash-report-" + new SimpleDateFormat("dd-MM-yy h.mm.ss").format(new Date()) + ".txt";
|
||||
Files.write(Paths.get(filename), result.getBytes());
|
||||
}catch (IOException i){
|
||||
i.printStackTrace();
|
||||
failed = true;
|
||||
}
|
||||
|
||||
JOptionPane.showMessageDialog(null, "An error has occured: \n" + result + "\n\n" +
|
||||
(!failed ? "A crash report has been written to " + new File(filename).getAbsolutePath() + ".\nPlease send this file to the developer!"
|
||||
: "Failed to generate crash report.\nPlease send an image of this crash log to the developer!"));
|
||||
}catch (Throwable e){
|
||||
CrashHandler.handle(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
83
desktop/src/io/anuke/mindustry/desktop/DesktopPlatform.java
Normal file
83
desktop/src/io/anuke/mindustry/desktop/DesktopPlatform.java
Normal file
@@ -0,0 +1,83 @@
|
||||
package io.anuke.mindustry.desktop;
|
||||
|
||||
import club.minnced.discord.rpc.DiscordEventHandlers;
|
||||
import club.minnced.discord.rpc.DiscordRPC;
|
||||
import club.minnced.discord.rpc.DiscordRichPresence;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.io.Platform;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.text.DateFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import static io.anuke.mindustry.Vars.state;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class DesktopPlatform extends Platform {
|
||||
DateFormat format = SimpleDateFormat.getDateTimeInstance();
|
||||
DiscordRPC lib = DiscordRPC.INSTANCE;
|
||||
|
||||
public DesktopPlatform(){
|
||||
String applicationId = "398246104468291591";
|
||||
DiscordEventHandlers handlers = new DiscordEventHandlers();
|
||||
|
||||
lib.Discord_Initialize(applicationId, handlers, true, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String format(Date date){
|
||||
return format.format(date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String format(int number){
|
||||
return NumberFormat.getIntegerInstance().format(number);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showError(String text){
|
||||
JOptionPane.showMessageDialog(null, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocaleName(Locale locale){
|
||||
return locale.getDisplayName(locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateRPC() {
|
||||
DiscordRichPresence presence = new DiscordRichPresence();
|
||||
|
||||
if(!state.is(State.menu)){
|
||||
presence.state = Strings.capitalize(state.mode.name()) + ", Solo";
|
||||
presence.details = Strings.capitalize(world.getMap().name) + " | Wave " + state.wave;
|
||||
presence.largeImageText = "Wave " + state.wave;
|
||||
if(Net.active() ){
|
||||
presence.partyMax = 16;
|
||||
presence.partySize = Net.getConnections().size;
|
||||
presence.state = Strings.capitalize(state.mode.name());
|
||||
}
|
||||
}else{
|
||||
if(ui.editor != null && ui.editor.isShown()){
|
||||
presence.state = "In Editor";
|
||||
}else {
|
||||
presence.state = "In Menu";
|
||||
}
|
||||
}
|
||||
|
||||
presence.largeImageKey = "logo";
|
||||
|
||||
lib.Discord_UpdatePresence(presence);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGameExit() {
|
||||
lib.Discord_Shutdown();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user