From b37ee6c45f9b9c435386f81e1cca913e97b6e0d4 Mon Sep 17 00:00:00 2001 From: austin Date: Fri, 16 Aug 2024 17:43:25 -0400 Subject: [PATCH] netconfig file support --- docs/src/progress/currenttarget.md | 3 +- docs/src/progress/renderertodo.md | 1 + .../java/electrosphere/engine/Globals.java | 3 + .../electrosphere/menu/MenuGenerators.java | 24 +++++- .../electrosphere/net/config/NetConfig.java | 84 +++++++++++++++++++ .../java/electrosphere/util/Utilities.java | 37 ++++---- 6 files changed, 123 insertions(+), 29 deletions(-) create mode 100644 src/main/java/electrosphere/net/config/NetConfig.java diff --git a/docs/src/progress/currenttarget.md b/docs/src/progress/currenttarget.md index c4c3be7d..41d65334 100644 --- a/docs/src/progress/currenttarget.md +++ b/docs/src/progress/currenttarget.md @@ -5,8 +5,7 @@ + when you grab the sword, a tutorial popup appears to tell you how to use in + on clearing the tutorial, continue the game when the sword is equipped, create another popup to teach sword controls. it pauses the game + when popup is accepted, spawn an enemy with an effect - review combat code (lifestate, damage calculation, etc) - Maybe a fade-out before deleting entity on death? + Script engine ability to spawn entities + rearchitecture Netconf file that pre-populates address, ip, username, password diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index d8c46720..0f09b727 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -598,6 +598,7 @@ Fix physics freakout for vertically aligned entities Fix AI components not resetting on turning off ai manager Fix broken rendering pipeline when creating new level Fix ui alignment for item panels in inventory menus (ie dont have to place in corner) +Netconfig file support # TODO diff --git a/src/main/java/electrosphere/engine/Globals.java b/src/main/java/electrosphere/engine/Globals.java index e21cee08..8e28e27b 100644 --- a/src/main/java/electrosphere/engine/Globals.java +++ b/src/main/java/electrosphere/engine/Globals.java @@ -44,6 +44,7 @@ import electrosphere.game.server.world.MacroData; import electrosphere.logger.LoggerInterface; import electrosphere.menu.WindowUtils; import electrosphere.net.client.ClientNetworking; +import electrosphere.net.config.NetConfig; import electrosphere.net.monitor.NetMonitor; import electrosphere.net.server.Server; import electrosphere.net.server.player.Player; @@ -141,6 +142,7 @@ public class Globals { public static boolean RUN_HIDDEN = false; //glfw session will be created with hidden window public static boolean RUN_AUDIO = true; public static int clientCharacterID; + public static NetConfig netConfig = null; // //Server manager thing @@ -444,6 +446,7 @@ public class Globals { //game config gameConfigDefault = electrosphere.game.data.Config.loadDefaultConfig(); gameConfigCurrent = gameConfigDefault; + NetConfig.readNetConfig(); // //Values that depend on the loaded config diff --git a/src/main/java/electrosphere/menu/MenuGenerators.java b/src/main/java/electrosphere/menu/MenuGenerators.java index 779c51b2..5cbb4f1b 100644 --- a/src/main/java/electrosphere/menu/MenuGenerators.java +++ b/src/main/java/electrosphere/menu/MenuGenerators.java @@ -229,7 +229,11 @@ public class MenuGenerators { //text entry (address) TextInput addressInput = new TextInput(100,screenTop + 125,1.0f); - addressInput.setText(NetUtils.getAddress()); + if(Globals.netConfig != null && Globals.netConfig.getAddress() != null){ + addressInput.setText(Globals.netConfig.getAddress()); + } else { + addressInput.setText(NetUtils.getAddress()); + } rVal.addChild(addressInput); //label (port) @@ -239,7 +243,11 @@ public class MenuGenerators { //text entry (port) TextInput portInput = new TextInput(100,screenTop + 275,1.0f); - portInput.setText(NetUtils.getPort() + ""); + if(Globals.netConfig != null && Globals.netConfig.getPort() != null){ + portInput.setText(Globals.netConfig.getPort()); + } else { + portInput.setText(NetUtils.getPort() + ""); + } rVal.addChild(portInput); //label (address) @@ -249,7 +257,11 @@ public class MenuGenerators { //text entry (address) TextInput usernameInput = new TextInput(100,screenTop + 425,1.0f); - usernameInput.setText(""); + if(Globals.netConfig != null && Globals.netConfig.getUsername() != null){ + usernameInput.setText(Globals.netConfig.getUsername()); + } else { + usernameInput.setText(""); + } rVal.addChild(usernameInput); //label (port) @@ -259,7 +271,11 @@ public class MenuGenerators { //text entry (port) TextInput passwordInput = new TextInput(100,screenTop + 575,1.0f); - passwordInput.setText(""); + if(Globals.netConfig != null && Globals.netConfig.getUsername() != null){ + passwordInput.setText(Globals.netConfig.getPassword()); + } else { + passwordInput.setText(""); + } rVal.addChild(passwordInput); //button (connect) diff --git a/src/main/java/electrosphere/net/config/NetConfig.java b/src/main/java/electrosphere/net/config/NetConfig.java new file mode 100644 index 00000000..db99816c --- /dev/null +++ b/src/main/java/electrosphere/net/config/NetConfig.java @@ -0,0 +1,84 @@ +package electrosphere.net.config; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; + +import electrosphere.engine.Globals; +import electrosphere.util.Utilities; + +/** + * A file that can be included in the root of the engine directory that + * will preload inputs for the join game page + */ +public class NetConfig { + + /** + * The address to connect to + */ + String address; + + /** + * The port to use + */ + String port; + + /** + * The username to use + */ + String username; + + /** + * The password to use + */ + String password; + + + /** + * Gets the address to connect to + * @return The address + */ + public String getAddress(){ + return address; + } + + /** + * Gets the port to connect to + * @return The port + */ + public String getPort(){ + return port; + } + + /** + * Gets the username to use + * @return The username + */ + public String getUsername(){ + return username; + } + + /** + * Gets the password to use + * @return The password + */ + public String getPassword(){ + return password; + } + + /** + * Reads the net config file + */ + public static void readNetConfig(){ + File file = new File("./netconfig.json"); + if(file.exists()){ + try { + Globals.netConfig = Utilities.deserialize(Files.readString(file.toPath()), NetConfig.class); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + +} diff --git a/src/main/java/electrosphere/util/Utilities.java b/src/main/java/electrosphere/util/Utilities.java index e6555701..1654bfaa 100644 --- a/src/main/java/electrosphere/util/Utilities.java +++ b/src/main/java/electrosphere/util/Utilities.java @@ -1,43 +1,22 @@ package electrosphere.util; -import electrosphere.engine.Globals; import electrosphere.engine.Main; import electrosphere.logger.LoggerInterface; -import electrosphere.renderer.model.Material; -import electrosphere.renderer.model.Mesh; -import electrosphere.renderer.model.Model; -import electrosphere.renderer.shader.ShaderProgram; -import electrosphere.renderer.texture.Texture; import electrosphere.renderer.texture.TextureMap; import com.google.gson.Gson; -import java.io.BufferedReader; import java.io.File; import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; import java.net.URISyntaxException; import java.net.URL; -import java.nio.FloatBuffer; -import java.nio.IntBuffer; import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; import org.joml.Matrix4d; import org.joml.Matrix4f; -import org.joml.Quaternionf; -import org.joml.Vector3f; -import org.lwjgl.BufferUtils; import org.lwjgl.assimp.AIMatrix4x4; -import static org.lwjgl.opengl.GL30.glBindVertexArray; -import static org.lwjgl.opengl.GL30.glGenVertexArrays; + /** - * - * @author awhoove + * Generic utilities */ public class Utilities { @@ -171,10 +150,22 @@ public class Utilities { } } + /** + * Serializes an object to json + * @param object The object + * @return The corresponding json + */ public static String stringify(Object object){ return gson.toJson(object); } + /** + * Deserializes an object from json + * @param The class of the object + * @param object The raw json string + * @param className The class to deserialize to + * @return The object + */ public static T deserialize(String object, Class className){ return gson.fromJson(object, className); }