mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
add JVM check
This commit is contained in:
23
forge-gui-mobile-dev/src/forge/app/DialogWindow.java
Normal file
23
forge-gui-mobile-dev/src/forge/app/DialogWindow.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package forge.app;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JOptionPane;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DialogWindow {
|
||||
public DialogWindow(String title, String message) {
|
||||
List<Object> options = new ArrayList<>();
|
||||
JButton ok = new JButton("OK");
|
||||
options.add(ok);
|
||||
JOptionPane pane = new JOptionPane(message, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null, options.toArray());
|
||||
JDialog dlg = pane.createDialog(JOptionPane.getRootFrame(), title);
|
||||
ok.addActionListener(e -> {
|
||||
dlg.setVisible(false);
|
||||
System.exit(0);
|
||||
});
|
||||
dlg.setResizable(false);
|
||||
dlg.setVisible(true);
|
||||
}
|
||||
}
|
||||
70
forge-gui-mobile-dev/src/forge/app/GameLauncher.java
Normal file
70
forge-gui-mobile-dev/src/forge/app/GameLauncher.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package forge.app;
|
||||
|
||||
import com.badlogic.gdx.ApplicationListener;
|
||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
|
||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
|
||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Clipboard;
|
||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3WindowAdapter;
|
||||
import com.badlogic.gdx.graphics.glutils.HdpiMode;
|
||||
import forge.Forge;
|
||||
import forge.adventure.util.Config;
|
||||
import forge.util.BuildInfo;
|
||||
import forge.util.FileUtil;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class GameLauncher {
|
||||
public GameLauncher() {
|
||||
// Set this to "true" to make the mobile game port run as a full-screen desktop application
|
||||
boolean desktopMode = true;//cmd.hasOption("fullscreen");
|
||||
// Set this to the location where you want the mobile game port to look for assets when working as a full-screen desktop application
|
||||
// (uncomment the bottom version and comment the top one to load the res folder from the current folder the .jar is in if you would
|
||||
// like to make the game load from a desktop game folder configuration).
|
||||
//String desktopModeAssetsDir = "../forge-gui/";
|
||||
String desktopModeAssetsDir = "./";
|
||||
if (!Files.exists(Paths.get(desktopModeAssetsDir + "res")))
|
||||
desktopModeAssetsDir = "../forge-gui/";//try IDE run
|
||||
|
||||
// Assets directory used when the game fully emulates smartphone/tablet mode (desktopMode = false), useful when debugging from IDE
|
||||
String assetsDir;
|
||||
if (!AssetsDownloader.SHARE_DESKTOP_ASSETS) {
|
||||
assetsDir = "testAssets/";
|
||||
FileUtil.ensureDirectoryExists(assetsDir);
|
||||
} else {
|
||||
assetsDir = "./";
|
||||
if (!Files.exists(Paths.get(assetsDir + "res")))
|
||||
assetsDir = "../forge-gui/";
|
||||
}
|
||||
|
||||
// Place the file "switch_orientation.ini" to your assets folder to make the game switch to landscape orientation (unless desktopMode = true)
|
||||
String switchOrientationFile = assetsDir + "switch_orientation.ini";
|
||||
|
||||
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
|
||||
config.setResizable(false);
|
||||
ApplicationListener start = Forge.getApp(new Lwjgl3Clipboard(), new Main.DesktopAdapter(switchOrientationFile),//todo get totalRAM && isTabletDevice
|
||||
desktopMode ? desktopModeAssetsDir : assetsDir, false, false, 0, false, 0, "", "");
|
||||
if (Config.instance().getSettingData().fullScreen) {
|
||||
config.setFullscreenMode(Lwjgl3ApplicationConfiguration.getDisplayMode());
|
||||
config.setAutoIconify(true);
|
||||
config.setHdpiMode(HdpiMode.Logical);
|
||||
} else {
|
||||
config.setWindowedMode(Config.instance().getSettingData().width, Config.instance().getSettingData().height);
|
||||
}
|
||||
config.setTitle("Forge - " + BuildInfo.getVersionString());
|
||||
config.setWindowListener(new Lwjgl3WindowAdapter() {
|
||||
@Override
|
||||
public boolean closeRequested() {
|
||||
//use the device adpater to exit properly
|
||||
if (Forge.safeToClose)
|
||||
Forge.exit(true);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (desktopMode)
|
||||
config.setHdpiMode(HdpiMode.Logical);
|
||||
|
||||
new Lwjgl3Application(start, config);
|
||||
}
|
||||
}
|
||||
@@ -1,143 +1,50 @@
|
||||
package forge.app;
|
||||
|
||||
import com.badlogic.gdx.ApplicationListener;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.backends.lwjgl3.*;
|
||||
import com.badlogic.gdx.graphics.glutils.HdpiMode;
|
||||
import forge.Forge;
|
||||
import forge.adventure.util.Config;
|
||||
import forge.assets.AssetsDownloader;
|
||||
import forge.interfaces.IDeviceAdapter;
|
||||
import forge.localinstance.properties.ForgePreferences;
|
||||
import forge.model.FModel;
|
||||
import forge.util.FileUtil;
|
||||
import forge.util.JVMOptions;
|
||||
import forge.util.OperatingSystem;
|
||||
import forge.util.RestartUtil;
|
||||
import forge.util.Utils;
|
||||
import org.apache.commons.cli.*;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.Desktop;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.RuntimeMXBean;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Options options = new Options();
|
||||
options.addOption("h","help", false, "Show help.");
|
||||
options.addOption("f","fullscreen", false,"fullscreen mode");
|
||||
options.addOption("l","landscape", false,"landscape mode");
|
||||
options.addOption("r","resolution", true,"resolution (WxH)");
|
||||
|
||||
CommandLineParser parser = new DefaultParser();
|
||||
HelpFormatter formatter = new HelpFormatter();
|
||||
CommandLine cmd;
|
||||
|
||||
try {
|
||||
cmd = parser.parse(options, args);
|
||||
} catch (ParseException e) {
|
||||
System.out.println(e.getMessage());
|
||||
formatter.printHelp("forge-mobile-dev", options);
|
||||
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
// Set this to "true" to make the mobile game port run as a full-screen desktop application
|
||||
boolean desktopMode = true;//cmd.hasOption("fullscreen");
|
||||
// Set this to the location where you want the mobile game port to look for assets when working as a full-screen desktop application
|
||||
// (uncomment the bottom version and comment the top one to load the res folder from the current folder the .jar is in if you would
|
||||
// like to make the game load from a desktop game folder configuration).
|
||||
//String desktopModeAssetsDir = "../forge-gui/";
|
||||
String desktopModeAssetsDir = "./";
|
||||
if(!Files.exists(Paths.get(desktopModeAssetsDir+"res")))
|
||||
desktopModeAssetsDir = "../forge-gui/";//try IDE run
|
||||
|
||||
// Assets directory used when the game fully emulates smartphone/tablet mode (desktopMode = false), useful when debugging from IDE
|
||||
String assetsDir ;
|
||||
if (!AssetsDownloader.SHARE_DESKTOP_ASSETS) {
|
||||
assetsDir= "testAssets/";
|
||||
FileUtil.ensureDirectoryExists(assetsDir);
|
||||
}
|
||||
else
|
||||
{
|
||||
assetsDir= "./";
|
||||
if(!Files.exists(Paths.get(assetsDir+"res")))
|
||||
assetsDir = "../forge-gui/";
|
||||
}
|
||||
|
||||
// Place the file "switch_orientation.ini" to your assets folder to make the game switch to landscape orientation (unless desktopMode = true)
|
||||
String switchOrientationFile = assetsDir + "switch_orientation.ini";
|
||||
boolean landscapeMode = FileUtil.doesFileExist(switchOrientationFile) || cmd.hasOption("landscape");
|
||||
String[] res;
|
||||
|
||||
// Width and height for standard smartphone/tablet mode (desktopMode = false)
|
||||
int screenWidth = landscapeMode ? (int)(Utils.BASE_HEIGHT * 16 / 9) : (int)Utils.BASE_WIDTH;
|
||||
int screenHeight = (int)Utils.BASE_HEIGHT;
|
||||
if (cmd.hasOption("resolution")) {
|
||||
res = cmd.getOptionValue("resolution").split("x");
|
||||
if (res.length >= 2) {
|
||||
screenWidth = Integer.parseInt(res[0].trim());
|
||||
screenHeight = Integer.parseInt(res[1].trim());
|
||||
}
|
||||
desktopMode=false;
|
||||
}
|
||||
|
||||
// Fullscreen width and height for desktop mode (desktopMode = true)
|
||||
// Can be specified inside the file fullscreen_resolution.ini to override default (in the format WxH, e.g. 1920x1080)
|
||||
int desktopScreenWidth = Lwjgl3ApplicationConfiguration.getDisplayMode().width;
|
||||
int desktopScreenHeight = Lwjgl3ApplicationConfiguration.getDisplayMode().height;
|
||||
boolean fullscreenFlag = true;
|
||||
if (FileUtil.doesFileExist(desktopModeAssetsDir + "screen_resolution.ini")) {
|
||||
res = FileUtil.readFileToString(desktopModeAssetsDir + "screen_resolution.ini").split("x");
|
||||
fullscreenFlag = res.length != 3 || Integer.parseInt(res[2].trim()) > 0;
|
||||
if (res.length >= 2) {
|
||||
desktopScreenWidth = Integer.parseInt(res[0].trim());
|
||||
desktopScreenHeight = Integer.parseInt(res[1].trim());
|
||||
}
|
||||
}
|
||||
|
||||
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
|
||||
config.setResizable(false);
|
||||
ForgePreferences prefs = FModel.getPreferences();
|
||||
boolean propertyConfig = prefs != null && prefs.getPrefBoolean(ForgePreferences.FPref.UI_NETPLAY_COMPAT);
|
||||
ApplicationListener start = Forge.getApp(new Lwjgl3Clipboard(), new DesktopAdapter(switchOrientationFile),//todo get totalRAM && isTabletDevice
|
||||
desktopMode ? desktopModeAssetsDir : assetsDir, propertyConfig, false, 0, false, 0, "", "");
|
||||
if (Config.instance().getSettingData().fullScreen) {
|
||||
config.setFullscreenMode(Lwjgl3ApplicationConfiguration.getDisplayMode());
|
||||
config.setAutoIconify(true);
|
||||
config.setHdpiMode(HdpiMode.Logical);
|
||||
} else {
|
||||
config.setWindowedMode(Config.instance().getSettingData().width, Config.instance().getSettingData().height);
|
||||
}
|
||||
config.setTitle("Forge");
|
||||
config.setWindowListener(new Lwjgl3WindowAdapter(){
|
||||
@Override
|
||||
public boolean closeRequested() {
|
||||
//use the device adpater to exit properly
|
||||
if (Forge.safeToClose)
|
||||
Forge.exit(true);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (desktopMode)
|
||||
config.setHdpiMode(HdpiMode.Logical);
|
||||
|
||||
new Lwjgl3Application(start, config);
|
||||
checkJVMArgs(System.getProperty("java.version"));
|
||||
}
|
||||
|
||||
private static class DesktopAdapter implements IDeviceAdapter {
|
||||
static void checkJVMArgs(String javaVersion) {
|
||||
RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
|
||||
List<String> arguments = runtimeMxBean.getInputArguments();
|
||||
JVMOptions.getStringBuilder().append("Java Version: ").append(javaVersion).append("\nArguments: \n");
|
||||
for (String a : arguments) {
|
||||
if (a.startsWith("-agent") || a.startsWith("-javaagent"))
|
||||
continue;
|
||||
JVMOptions.getStringBuilder().append(a).append("\n");
|
||||
}
|
||||
if (!JVMOptions.checkRuntime(arguments)) {
|
||||
new DialogWindow("Error", JVMOptions.getStringBuilder().toString());
|
||||
} else
|
||||
new GameLauncher();
|
||||
}
|
||||
|
||||
public static class DesktopAdapter implements IDeviceAdapter {
|
||||
private final String switchOrientationFile;
|
||||
|
||||
private DesktopAdapter(String switchOrientationFile0) {
|
||||
DesktopAdapter(String switchOrientationFile0) {
|
||||
switchOrientationFile = switchOrientationFile0;
|
||||
}
|
||||
|
||||
@@ -162,8 +69,7 @@ public class Main {
|
||||
try {
|
||||
Desktop.getDesktop().open(new File(filename));
|
||||
return true;
|
||||
}
|
||||
catch (IOException e) {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
@@ -193,8 +99,7 @@ public class Main {
|
||||
//create file to indicate that landscape mode should be used
|
||||
if (landscapeMode) {
|
||||
FileUtil.writeFile(switchOrientationFile, "1");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
FileUtil.deleteFile(switchOrientationFile);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user