From e590941e2f9f3ab900163f6c2d348748171be5fa Mon Sep 17 00:00:00 2001
From: lieght <49651652+BAFGdeJong@users.noreply.github.com>
Date: Wed, 24 Sep 2025 16:53:29 +0200
Subject: [PATCH] Fixed framework and moved window events to app
---
app/pom.xml | 8 ++
.../java/org/toop/events/WindowEvents.java | 24 ++++
.../events/{IEvent.java => EventType.java} | 2 +-
.../eventbus/events/EventWithUuid.java | 2 +-
.../eventbus/events/EventWithoutUuid.java | 3 +
.../framework/eventbus/events/Events.java | 108 +-----------------
.../eventbus/events/NetworkEvents.java | 28 ++---
.../eventbus/events/ServerEvents.java | 4 -
.../networking/NetworkingClientManager.java | 16 +--
9 files changed, 54 insertions(+), 141 deletions(-)
create mode 100644 app/src/main/java/org/toop/events/WindowEvents.java
rename framework/src/main/java/org/toop/framework/eventbus/events/{IEvent.java => EventType.java} (60%)
create mode 100644 framework/src/main/java/org/toop/framework/eventbus/events/EventWithoutUuid.java
delete mode 100644 framework/src/main/java/org/toop/framework/eventbus/events/ServerEvents.java
diff --git a/app/pom.xml b/app/pom.xml
index 5232dc7..460e517 100644
--- a/app/pom.xml
+++ b/app/pom.xml
@@ -8,6 +8,14 @@
org.toop.Main
+
+
+ org.toop
+ pism_framework
+ 0.1
+ compile
+
+
diff --git a/app/src/main/java/org/toop/events/WindowEvents.java b/app/src/main/java/org/toop/events/WindowEvents.java
new file mode 100644
index 0000000..dfefd4a
--- /dev/null
+++ b/app/src/main/java/org/toop/events/WindowEvents.java
@@ -0,0 +1,24 @@
+package org.toop.events;
+
+import org.toop.framework.eventbus.events.Events;
+
+public class WindowEvents extends Events {
+
+ /** Triggers when a cell is clicked in one of the game boards. */
+ public record CellClicked(int cell) {}
+
+ /** Triggers when the window wants to quit. */
+ public record OnQuitRequested() implements IEvent {}
+
+ /** Triggers when the window is resized. */
+// public record OnResize(Window.Size size) {}
+
+ /** Triggers when the mouse is moved within the window. */
+ public record OnMouseMove(int x, int y) implements IEvent {}
+
+ /** Triggers when the mouse is clicked within the window. */
+ public record OnMouseClick(int button) {}
+
+ /** Triggers when the mouse is released within the window. */
+ public record OnMouseRelease(int button) {}
+}
\ No newline at end of file
diff --git a/framework/src/main/java/org/toop/framework/eventbus/events/IEvent.java b/framework/src/main/java/org/toop/framework/eventbus/events/EventType.java
similarity index 60%
rename from framework/src/main/java/org/toop/framework/eventbus/events/IEvent.java
rename to framework/src/main/java/org/toop/framework/eventbus/events/EventType.java
index 1867942..15f3f1d 100644
--- a/framework/src/main/java/org/toop/framework/eventbus/events/IEvent.java
+++ b/framework/src/main/java/org/toop/framework/eventbus/events/EventType.java
@@ -1,3 +1,3 @@
package org.toop.framework.eventbus.events;
-public interface IEvent {}
+public interface EventType {}
diff --git a/framework/src/main/java/org/toop/framework/eventbus/events/EventWithUuid.java b/framework/src/main/java/org/toop/framework/eventbus/events/EventWithUuid.java
index 3ec2ea8..e0eec8c 100644
--- a/framework/src/main/java/org/toop/framework/eventbus/events/EventWithUuid.java
+++ b/framework/src/main/java/org/toop/framework/eventbus/events/EventWithUuid.java
@@ -2,7 +2,7 @@ package org.toop.framework.eventbus.events;
import java.util.Map;
-public interface EventWithUuid extends IEvent {
+public interface EventWithUuid extends EventType {
Map result();
String eventId();
}
diff --git a/framework/src/main/java/org/toop/framework/eventbus/events/EventWithoutUuid.java b/framework/src/main/java/org/toop/framework/eventbus/events/EventWithoutUuid.java
new file mode 100644
index 0000000..ef7bfce
--- /dev/null
+++ b/framework/src/main/java/org/toop/framework/eventbus/events/EventWithoutUuid.java
@@ -0,0 +1,3 @@
+package org.toop.framework.eventbus.events;
+
+public interface EventWithoutUuid extends EventType {}
diff --git a/framework/src/main/java/org/toop/framework/eventbus/events/Events.java b/framework/src/main/java/org/toop/framework/eventbus/events/Events.java
index eb733a5..00628cc 100644
--- a/framework/src/main/java/org/toop/framework/eventbus/events/Events.java
+++ b/framework/src/main/java/org/toop/framework/eventbus/events/Events.java
@@ -5,7 +5,7 @@ import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
/** Events that are used in the GlobalEventBus class. */
-public class Events implements IEvent {
+public class Events {
/**
* WIP, DO NOT USE!
@@ -68,115 +68,9 @@ public class Events implements IEvent {
return constructor.newInstance(args);
}
- public static class ServerEvents {
-
- /**
- * BLOCKING Requests all active servers. The result is returned via the provided
- * CompletableFuture.
- *
- * @param future List of all servers in string form.
- */
- public record RequestsAllServers(CompletableFuture future) {}
-
- /** Forces closing all active servers immediately. */
- public record ForceCloseAllServers() implements IEvent {}
-
- /**
- * Requests starting a server with a specific port and game type.
- *
- * @param port The port to open the server.
- * @param gameType Either "tictactoe" or ...
- */
- public record StartServer(int port, String gameType) implements IEvent {}
-
- /**
- * BLOCKING Requests starting a server with a specific port and game type, and returns a
- * CompletableFuture that completes when the server has started.
- *
- * @param port The port to open the server.
- * @param gameType Either "tictactoe" or ...
- * @param future The uuid of the server.
- */
- public record StartServerRequest(
- int port, String gameType, CompletableFuture future) implements IEvent{}
-
- /**
- * Represents a server that has successfully started.
- *
- * @param uuid The unique identifier of the server.
- * @param port The port the server is listening on.
- */
- public record ServerStarted(String uuid, int port) implements IEvent {}
-
- /**
- * BLOCKING Requests creation of a TicTacToe game on a specific server.
- *
- * @param serverUuid The unique identifier of the server where the game will be created.
- * @param playerA The name of the first player.
- * @param playerB The name of the second player.
- * @param future The game UUID when the game is created.
- */
- public record CreateTicTacToeGameRequest(
- String serverUuid,
- String playerA,
- String playerB,
- CompletableFuture future) implements IEvent {}
-
- /**
- * Requests running a TicTacToe game on a specific server.
- *
- * @param serverUuid The unique identifier of the server.
- * @param gameUuid The UUID of the game to run.
- */
- public record RunTicTacToeGame(String serverUuid, String gameUuid) implements IEvent {}
-
- /**
- * Requests ending a TicTacToe game on a specific server.
- *
- * @param serverUuid The UUID of the server the game is running on.
- * @param gameUuid The UUID of the game to end.
- */
- public record EndTicTacToeGame(String serverUuid, String gameUuid) implements IEvent {}
-
- // public record StartGameConnectionRequest(String ip, String port,
- // CompletableFuture future) {}
-
- /**
- * Triggers on changing the server IP.
- *
- * @param ip The new IP address.
- */
- public record OnChangingServerIp(String ip) {}
-
- /**
- * Triggers on changing the server port.
- *
- * @param port The new port.
- */
- public record OnChangingServerPort(int port) {}
-
- /** Triggers when a cell is clicked in one of the game boards. */
- public record CellClicked(int cell) {}
- }
-
public static class EventBusEvents {}
- public static class WindowEvents {
- /** Triggers when the window wants to quit. */
- public record OnQuitRequested() implements IEvent {}
- /** Triggers when the window is resized. */
-// public record OnResize(Window.Size size) {}
-
- /** Triggers when the mouse is moved within the window. */
- public record OnMouseMove(int x, int y) implements IEvent {}
-
- /** Triggers when the mouse is clicked within the window. */
- public record OnMouseClick(int button) {}
-
- /** Triggers when the mouse is released within the window. */
- public record OnMouseRelease(int button) {}
- }
public static class TttEvents {}
diff --git a/framework/src/main/java/org/toop/framework/eventbus/events/NetworkEvents.java b/framework/src/main/java/org/toop/framework/eventbus/events/NetworkEvents.java
index ae7d190..5aaeece 100644
--- a/framework/src/main/java/org/toop/framework/eventbus/events/NetworkEvents.java
+++ b/framework/src/main/java/org/toop/framework/eventbus/events/NetworkEvents.java
@@ -1,6 +1,5 @@
package org.toop.framework.eventbus.events;
-import org.toop.backend.tictactoe.TicTacToeServer;
import org.toop.framework.networking.NetworkingGameClientHandler;
import java.lang.reflect.RecordComponent;
@@ -18,14 +17,14 @@ public class NetworkEvents extends Events {
*
* @param future List of all connections in string form.
*/
- public record RequestsAllClients(CompletableFuture future) implements IEvent {}
+ public record RequestsAllClients(CompletableFuture future) implements EventWithoutUuid {}
/** Forces closing all active connections immediately. */
- public record ForceCloseAllClients() implements IEvent {}
+ public record ForceCloseAllClients() implements EventWithoutUuid {}
- public record CloseClientRequest(CompletableFuture future) {}
+ public record CloseClientRequest(CompletableFuture future) implements EventWithoutUuid {}
- public record CloseClient(String connectionId) implements IEvent {}
+ public record CloseClient(String connectionId) implements EventWithoutUuid {}
/**
* Event to start a new client connection to a server.
@@ -50,7 +49,7 @@ public class NetworkEvents extends Events {
* @param ip The IP address of the server to connect to.
* @param port The port number of the server to connect to.
* @param eventId A unique identifier for this event, typically injected
- * automatically by the {@link org.toop.framework.eventbus.EventPublisher}.
+ * automatically by the {@link org.toop.framework.eventbus.EventFlow}.
*/
public record StartClient(
Supplier extends NetworkingGameClientHandler> handlerFactory,
@@ -102,7 +101,7 @@ public class NetworkEvents extends Events {
*/
public record StartClientRequest(
Supplier extends NetworkingGameClientHandler> handlerFactory,
- String ip, int port, CompletableFuture future) implements IEvent {}
+ String ip, int port, CompletableFuture future) implements EventWithoutUuid {}
/**
*
@@ -138,18 +137,7 @@ public class NetworkEvents extends Events {
* @param connectionId The UUID of the connection to send the command on.
* @param args The command arguments.
*/
- public record SendCommand(String connectionId, String... args) implements IEvent {}
-
- /**
- * WIP Triggers when a command is sent to a server.
- *
- * @param command The TicTacToeServer instance that executed the command.
- * @param args The command arguments.
- * @param result The result returned from executing the command.
- */
- public record OnCommand(
- TicTacToeServer command, String[] args, String result) {} // TODO old
-
+ public record SendCommand(String connectionId, String... args) implements EventWithoutUuid {}
/**
* Triggers reconnecting to a previous address.
*
@@ -164,7 +152,7 @@ public class NetworkEvents extends Events {
* @param ConnectionUuid The UUID of the connection that received the message.
* @param message The message received.
*/
- public record ReceivedMessage(String ConnectionUuid, String message) implements IEvent {}
+ public record ReceivedMessage(String ConnectionUuid, String message) implements EventWithoutUuid {}
/**
* Triggers changing connection to a new address.
diff --git a/framework/src/main/java/org/toop/framework/eventbus/events/ServerEvents.java b/framework/src/main/java/org/toop/framework/eventbus/events/ServerEvents.java
deleted file mode 100644
index d7c0ef8..0000000
--- a/framework/src/main/java/org/toop/framework/eventbus/events/ServerEvents.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package org.toop.framework.eventbus.events;
-
-public class ServerEvents {
-}
diff --git a/framework/src/main/java/org/toop/framework/networking/NetworkingClientManager.java b/framework/src/main/java/org/toop/framework/networking/NetworkingClientManager.java
index e2772f9..8dec4b1 100644
--- a/framework/src/main/java/org/toop/framework/networking/NetworkingClientManager.java
+++ b/framework/src/main/java/org/toop/framework/networking/NetworkingClientManager.java
@@ -6,7 +6,7 @@ import java.util.function.Supplier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import org.toop.framework.eventbus.EventPublisher;
+import org.toop.framework.eventbus.EventFlow;
import org.toop.framework.eventbus.events.NetworkEvents;
public class NetworkingClientManager {
@@ -18,12 +18,12 @@ public class NetworkingClientManager {
/** Starts a connection manager, to manage, connections. */
public NetworkingClientManager() {
- new EventPublisher<>(NetworkEvents.StartClientRequest.class, this::handleStartClientRequest);
- new EventPublisher<>(NetworkEvents.StartClient.class, this::handleStartClient);
- new EventPublisher<>(NetworkEvents.SendCommand.class, this::handleCommand);
- new EventPublisher<>(NetworkEvents.CloseClient.class, this::handleCloseClient);
- new EventPublisher<>(NetworkEvents.RequestsAllClients.class, this::getAllConnections);
- new EventPublisher<>(NetworkEvents.ForceCloseAllClients.class, this::shutdownAll);
+ new EventFlow().listen(NetworkEvents.StartClientRequest.class, this::handleStartClientRequest);
+ new EventFlow().listen(NetworkEvents.StartClient.class, this::handleStartClient);
+ new EventFlow().listen(NetworkEvents.SendCommand.class, this::handleCommand);
+ new EventFlow().listen(NetworkEvents.CloseClient.class, this::handleCloseClient);
+ new EventFlow().listen(NetworkEvents.RequestsAllClients.class, this::getAllConnections);
+ new EventFlow().listen(NetworkEvents.ForceCloseAllClients.class, this::shutdownAll);
}
private String startClientRequest(Supplier extends NetworkingGameClientHandler> handlerFactory,
@@ -54,7 +54,7 @@ public class NetworkingClientManager {
private void handleStartClient(NetworkEvents.StartClient event) {
String uuid = this.startClientRequest(event.handlerFactory(), event.ip(), event.port());
- new EventPublisher<>(NetworkEvents.StartClientSuccess.class,
+ new EventFlow().addPostEvent(NetworkEvents.StartClientSuccess.class,
uuid, event.eventId()
).asyncPostEvent();
}