Added creating setting up a server for the user when the form is filled in

This commit is contained in:
lieght
2025-09-17 20:12:36 +02:00
parent 395dc8c603
commit 032d388f4f
4 changed files with 79 additions and 11 deletions

21
.idea/workspace.xml generated
View File

@@ -7,9 +7,8 @@
<list default="true" id="997b32da-b4d4-48ac-ab51-52d65f364f81" name="Changes" comment=""> <list default="true" id="997b32da-b4d4-48ac-ab51-52d65f364f81" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/org/toop/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/toop/Main.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/org/toop/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/toop/Main.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/org/toop/eventbus/Events.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/toop/eventbus/Events.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/org/toop/UI/GameSelectorWindow.form" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/toop/UI/GameSelectorWindow.form" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/org/toop/game/TTT.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/toop/game/TTT.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/org/toop/UI/GameSelectorWindow.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/toop/UI/GameSelectorWindow.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/resources/log4j2.xml" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/log4j2.xml" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -51,6 +50,10 @@
&quot;accountId&quot;: &quot;7694f583-f911-4763-8185-8ea3ed608804&quot; &quot;accountId&quot;: &quot;7694f583-f911-4763-8185-8ea3ed608804&quot;
} }
}</component> }</component>
<component name="KubernetesApiPersistence"><![CDATA[{}]]></component>
<component name="KubernetesApiProvider"><![CDATA[{
"isMigrated": true
}]]></component>
<component name="ProjectColorInfo">{ <component name="ProjectColorInfo">{
&quot;customColor&quot;: &quot;&quot;, &quot;customColor&quot;: &quot;&quot;,
&quot;associatedIndex&quot;: 1 &quot;associatedIndex&quot;: 1
@@ -67,7 +70,8 @@
"RunOnceActivity.ShowReadmeOnStart": "true", "RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager": "true", "RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager": "true",
"RunOnceActivity.git.unshallow": "true", "RunOnceActivity.git.unshallow": "true",
"git-widget-placeholder": "#25 on Merging Ticho", "UI_DESIGNER_EDITOR_MODE.UIDesignerToolWindowManager.WIDTH": "421",
"git-widget-placeholder": "#25 on Ticho",
"node.js.detected.package.eslint": "true", "node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true", "node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)", "node.js.selected.package.eslint": "(autodetect)",
@@ -109,6 +113,15 @@
<updated>1758117514311</updated> <updated>1758117514311</updated>
<workItem from="1758117515668" duration="8923000" /> <workItem from="1758117515668" duration="8923000" />
</task> </task>
<task id="LOCAL-00001">
<option name="closed" value="true" />
<created>1758131224799</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1758131224799</updated>
</task>
<option name="localTasksCounter" value="2" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">

View File

@@ -18,6 +18,7 @@ public class Main {
public static void main(String[] args) throws ExecutionException, InterruptedException { public static void main(String[] args) throws ExecutionException, InterruptedException {
initSystems(); initSystems();
registerEvents(); registerEvents();
/* /*
Window window = Window.setup(Window.API.GLFW, "Test", new Window.Size(1280, 720)); Window window = Window.setup(Window.API.GLFW, "Test", new Window.Size(1280, 720));
Renderer renderer = Renderer.setup(Renderer.API.OPENGL); Renderer renderer = Renderer.setup(Renderer.API.OPENGL);
@@ -34,7 +35,9 @@ public class Main {
Window.start(""); Window.start("");
*/ */
new Thread(() -> {
GameSelectorWindow gameSelectorWindow = new GameSelectorWindow(); GameSelectorWindow gameSelectorWindow = new GameSelectorWindow();
}).start();
} }
/** /**

View File

@@ -17,7 +17,9 @@
<preferred-size width="150" height="-1"/> <preferred-size width="150" height="-1"/>
</grid> </grid>
</constraints> </constraints>
<properties/> <properties>
<text value=""/>
</properties>
</component> </component>
<vspacer id="4e05c"> <vspacer id="4e05c">
<constraints> <constraints>
@@ -46,7 +48,9 @@
<preferred-size width="150" height="-1"/> <preferred-size width="150" height="-1"/>
</grid> </grid>
</constraints> </constraints>
<properties/> <properties>
<text value=""/>
</properties>
</component> </component>
<component id="26a0" class="javax.swing.JTextField" binding="portTextField"> <component id="26a0" class="javax.swing.JTextField" binding="portTextField">
<constraints> <constraints>

View File

@@ -1,9 +1,13 @@
package org.toop.UI; package org.toop.UI;
import org.toop.eventbus.Events;
import org.toop.eventbus.GlobalEventBus; import org.toop.eventbus.GlobalEventBus;
import javax.swing.*; import javax.swing.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.*; import java.awt.*;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class GameSelectorWindow extends JFrame { public class GameSelectorWindow extends JFrame {
@@ -34,10 +38,54 @@ public class GameSelectorWindow extends JFrame {
} }
private void init() { private void init() {
connectButton.addActionListener(( connectButton.addActionListener((ActionEvent e) -> {
ActionEvent e) -> { if( !nameTextField.getText().isEmpty() &&
if(!nameTextField.getText().equals("") && !ipTextField.getText().equals("") && !portTextField.getText().equals("")) { !ipTextField.getText().isEmpty() &&
System.out.println(gameSelectorBox.getSelectedItem().toString()); //todo attempt connecting to the server with given ip, port and name. !portTextField.getText().isEmpty()) {
CompletableFuture<String> serverIdFuture = new CompletableFuture<>();
GlobalEventBus.post(new Events.ServerEvents.StartServerRequest(
portTextField.getText(),
Objects.requireNonNull(gameSelectorBox.getSelectedItem()).toString().toLowerCase().replace(" ", ""),
serverIdFuture
));
String serverId;
try {
serverId = serverIdFuture.get();
} catch (InterruptedException | ExecutionException ex) {
throw new RuntimeException(ex);
} // TODO: Better error handling to not crash the system.
CompletableFuture<String> connectionIdFuture = new CompletableFuture<>();
GlobalEventBus.post(new Events.ServerEvents.StartConnectionRequest(
ipTextField.getText(),
portTextField.getText(),
connectionIdFuture
));
String connectionId;
try {
connectionId = connectionIdFuture.get();
} catch (InterruptedException | ExecutionException ex) {
throw new RuntimeException(ex);
} // TODO: Better error handling to not crash the system.
CompletableFuture<String> ticTacToeGame = new CompletableFuture<>();
GlobalEventBus.post(new Events.ServerEvents.CreateTicTacToeGameRequest( // TODO: Make this happen through commands send through the connection, instead of an event.
serverId,
nameTextField.getText(),
"P",
ticTacToeGame
));
String ticTacToeGameId;
try {
ticTacToeGameId = ticTacToeGame.get();
} catch (InterruptedException | ExecutionException ex) {
throw new RuntimeException(ex);
} // TODO: Better error handling to not crash the system.
GlobalEventBus.post(new Events.ServerEvents.RunTicTacToeGame(serverId, ticTacToeGameId)); // TODO: attempt connecting to the server with given ip, port and name.
frame.remove(mainMenu); frame.remove(mainMenu);
UIGameBoard ttt = new UIGameBoard(gameSelectorBox.getSelectedItem().toString(),this); UIGameBoard ttt = new UIGameBoard(gameSelectorBox.getSelectedItem().toString(),this);
frame.add(ttt.getTTTPanel()); frame.add(ttt.getTTTPanel());