fix: replace duplicate class with ParticipantType

This commit is contained in:
punchready 2021-05-18 18:49:33 +02:00
parent 89a75f982b
commit 65e9e88f51
5 changed files with 13 additions and 16 deletions

@ -1 +1 @@
Subproject commit 1348e342d6ec3685424244ceae6d920652239555 Subproject commit 588633fe4627e274dd9b4b1f69b2fe5da17d976f

View File

@ -6,9 +6,9 @@ import uulm.teamname.marvelous.gamelibrary.events.EventBuilder;
import uulm.teamname.marvelous.gamelibrary.events.EventType; import uulm.teamname.marvelous.gamelibrary.events.EventType;
import uulm.teamname.marvelous.gamelibrary.gamelogic.EventObserver; import uulm.teamname.marvelous.gamelibrary.gamelogic.EventObserver;
import uulm.teamname.marvelous.gamelibrary.gamelogic.GameInstance; import uulm.teamname.marvelous.gamelibrary.gamelogic.GameInstance;
import uulm.teamname.marvelous.gamelibrary.gamelogic.ParticipantType;
import uulm.teamname.marvelous.gamelibrary.requests.Request; import uulm.teamname.marvelous.gamelibrary.requests.Request;
import uulm.teamname.marvelous.server.LobbyManager.LobbyConnection; import uulm.teamname.marvelous.server.LobbyManager.LobbyConnection;
import uulm.teamname.marvelous.server.LobbyManager.MessageSource;
import java.util.*; import java.util.*;
@ -30,7 +30,7 @@ public class Lobby extends EventObserver {
connection.broadcastEvents(events); connection.broadcastEvents(events);
} }
public void receiveRequests(MessageSource source, Request[] requests) { public void receiveRequests(ParticipantType source, Request[] requests) {
ArrayList<Request> stateRelevant = new ArrayList<>(); ArrayList<Request> stateRelevant = new ArrayList<>();
for(Request request: requests) { for(Request request: requests) {
@ -39,7 +39,7 @@ public class Lobby extends EventObserver {
stateRelevant.add(request); // these need to be checked all together by the game instance itself stateRelevant.add(request); // these need to be checked all together by the game instance itself
} }
case PauseStopRequest, PauseStartRequest, EndRoundRequest, DisconnectRequest, Req -> { case PauseStopRequest, PauseStartRequest, EndRoundRequest, DisconnectRequest, Req -> {
processRequest(request); processRequest(source, request);
return; // only one of these will ever be sent at once, and if that is the case, we wont have any other state relevant events return; // only one of these will ever be sent at once, and if that is the case, we wont have any other state relevant events
} }
} }
@ -51,7 +51,7 @@ public class Lobby extends EventObserver {
} }
} }
private void processRequest(Request request) { private void processRequest(ParticipantType source, Request request) {
//TODO: handle the rest of the requests //TODO: handle the rest of the requests
switch(request.type) { switch(request.type) {
case PauseStopRequest -> { case PauseStopRequest -> {

View File

@ -2,6 +2,7 @@ package uulm.teamname.marvelous.server.LobbyManager;
import org.java_websocket.WebSocket; import org.java_websocket.WebSocket;
import uulm.teamname.marvelous.gamelibrary.events.Event; import uulm.teamname.marvelous.gamelibrary.events.Event;
import uulm.teamname.marvelous.gamelibrary.gamelogic.ParticipantType;
import uulm.teamname.marvelous.server.Lobby.Lobby; import uulm.teamname.marvelous.server.Lobby.Lobby;
import java.util.HashSet; import java.util.HashSet;
@ -100,8 +101,8 @@ public class LobbyConnection {
// Methods to send events // Methods to send events
public void sendEvents(MessageSource target, Event... events) { public void sendEvents(ParticipantType target, Event... events) {
MessageRelay.getInstance().sendMessage(this, events, target); MessageRelay.getInstance().sendMessage(this, target, events);
} }
public void broadcastEvents(Event... events) { public void broadcastEvents(Event... events) {

View File

@ -2,6 +2,7 @@ package uulm.teamname.marvelous.server.LobbyManager;
import org.java_websocket.WebSocket; import org.java_websocket.WebSocket;
import uulm.teamname.marvelous.gamelibrary.events.Event; import uulm.teamname.marvelous.gamelibrary.events.Event;
import uulm.teamname.marvelous.gamelibrary.gamelogic.ParticipantType;
import uulm.teamname.marvelous.server.Lobby.Lobby; import uulm.teamname.marvelous.server.Lobby.Lobby;
import java.util.HashMap; import java.util.HashMap;
@ -29,14 +30,16 @@ public class MessageRelay {
// TODO: send to target lobby // TODO: send to target lobby
} }
public void sendMessage (LobbyConnection origin, Event[] events, MessageSource target) { public void sendMessage (LobbyConnection origin, ParticipantType target, Event[] events) {
switch (target) { switch (target) {
case Player1 -> { case Player1 -> {
} }
case Player2 -> { case Player2 -> {
} }
case Spectator -> { case Spectator -> {
} }
} }
} }

View File

@ -1,7 +0,0 @@
package uulm.teamname.marvelous.server.LobbyManager;
public enum MessageSource {
Player1,
Player2,
Spectator,
}