From 47b7980f242c055982bc84301b64efe63c49e7ed Mon Sep 17 00:00:00 2001 From: Charles Gould Date: Wed, 20 May 2020 00:17:07 -0500 Subject: [PATCH] Spruce up JavaFX client, README --- .build.yml | 2 +- README.md | 29 +++++++++------ client/LingoClient.launch | 24 ------------ client/pom.xml | 15 ++++++-- client/src/main/config/application.yaml | 14 ------- .../client/multiplayer/MultiplayerConfig.java | 3 +- .../client/multiplayer/StompTemplate.java | 8 ++-- .../singleplayer/SinglePlayerPresenter.java | 2 +- client/src/main/java/module-info.java | 4 ++ .../src/main/resources/application.properties | 2 + client/src/main/resources/fxml/Lingo.fxml | 15 +++++--- .../main/resources/fxml/LingoMultiplayer.fxml | 2 +- client/src/main/resources/style.css | 37 +++++++++++++++++-- pom.xml | 12 +----- server/LingoServer.launch | 24 ------------ server/pom.xml | 5 +-- server/src/main/config/application.yaml | 11 ------ .../src/main/resources/application.properties | 2 + 18 files changed, 93 insertions(+), 118 deletions(-) delete mode 100644 client/LingoClient.launch delete mode 100644 client/src/main/config/application.yaml create mode 100644 client/src/main/resources/application.properties delete mode 100644 server/LingoServer.launch delete mode 100644 server/src/main/config/application.yaml create mode 100644 server/src/main/resources/application.properties diff --git a/.build.yml b/.build.yml index 2f88146..6592b0c 100644 --- a/.build.yml +++ b/.build.yml @@ -5,7 +5,7 @@ packages: sources: - https://git.sr.ht/~crg/lingo artifacts: - - lingo/server/target/lingo-server-1.0.jar + - lingo/server/target/lingo-server.jar tasks: - build: | cd lingo diff --git a/README.md b/README.md index e091da8..c31e93a 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,24 @@ -# Lingo WebSocket +## Lingo -Lingo with WebSockets +A word guessing game based on the [game show](https://en.wikipedia.org/wiki/Lingo_(American_game_show)). -## Build +#### Browser client -`mvn clean install` +- Practice: https://lingo.charego.com/practice.html +- Competitive: https://lingo.charego.com -## Launch server +#### JavaFX client -`mvn -f ./server/pom.xml spring-boot:run` +- Requirements: Java 11, Maven 3 +- Build: `mvn clean install` +- Start client: `mvn -f client javafx:run` -## Launch client +#### Running locally -`mvn -f ./client/pom.xml exec:java` - -Practice: - -Multiplayer: +- Build: `mvn clean install` +- Start server + * Default port (8080): `java -jar server/target/lingo-server.jar` + * Custom port: `java -jar server/target/lingo-server.jar --server.port=` +- Start client + * Browser: `open http://localhost:` + * JavaFX: `mvn -f client javafx:run -Dlingo-url=http://localhost:` diff --git a/client/LingoClient.launch b/client/LingoClient.launch deleted file mode 100644 index de5b631..0000000 --- a/client/LingoClient.launch +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/client/pom.xml b/client/pom.xml index 7126f1a..6fd0e97 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -13,6 +13,7 @@ 11.0.2 + https://lingo.charego.com @@ -48,15 +49,23 @@ + + org.openjfx + javafx-maven-plugin + 0.0.4 + + com.charego.lingo.client.bootstrap.LingoClient + + + + + org.codehaus.mojo exec-maven-plugin com.charego.lingo.client.bootstrap.LingoClient true - - src/main/config - diff --git a/client/src/main/config/application.yaml b/client/src/main/config/application.yaml deleted file mode 100644 index 15a39c2..0000000 --- a/client/src/main/config/application.yaml +++ /dev/null @@ -1,14 +0,0 @@ -# http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html - -# Development -web.base.url: http://localhost:8080 -web.socket.url: ws://localhost:8080/sockjs - -# Production -#web.base.url: https://lingo.charego.com -#web.socket.url: wss://lingo.charego.com/sockjs - -# Logging -logging: - level: - com.charego.lingo: DEBUG diff --git a/client/src/main/java/com/charego/lingo/client/multiplayer/MultiplayerConfig.java b/client/src/main/java/com/charego/lingo/client/multiplayer/MultiplayerConfig.java index d8a646d..6e4a482 100644 --- a/client/src/main/java/com/charego/lingo/client/multiplayer/MultiplayerConfig.java +++ b/client/src/main/java/com/charego/lingo/client/multiplayer/MultiplayerConfig.java @@ -66,8 +66,9 @@ public class MultiplayerConfig { @Bean public RestTemplate restTemplate(Environment env) { + String webServerUrl = env.getRequiredProperty("lingo.url"); RestTemplate restTemplate = new RestTemplate(); - restTemplate.setUriTemplateHandler(new RootUriTemplateHandler(env.getProperty("web.base.url"))); + restTemplate.setUriTemplateHandler(new RootUriTemplateHandler(webServerUrl)); return restTemplate; } diff --git a/client/src/main/java/com/charego/lingo/client/multiplayer/StompTemplate.java b/client/src/main/java/com/charego/lingo/client/multiplayer/StompTemplate.java index d3111d9..a6dd53e 100644 --- a/client/src/main/java/com/charego/lingo/client/multiplayer/StompTemplate.java +++ b/client/src/main/java/com/charego/lingo/client/multiplayer/StompTemplate.java @@ -10,7 +10,7 @@ import javax.annotation.PreDestroy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.env.Environment; import org.springframework.core.task.TaskExecutor; import org.springframework.messaging.simp.stomp.StompCommand; import org.springframework.messaging.simp.stomp.StompFrameHandler; @@ -26,8 +26,8 @@ public class StompTemplate { private static final Logger log = LoggerFactory.getLogger(StompTemplate.class); - @Value("${web.socket.url}") - private String webSocketUrl; + @Autowired + private Environment env; @Autowired private TaskExecutor taskExecutor; @@ -49,6 +49,8 @@ public class StompTemplate { @PostConstruct private void postConstruct() { + String webServerUrl = env.getRequiredProperty("lingo.url"); + String webSocketUrl = webServerUrl.replace("http", "ws") + "/sockjs"; log.info("Connecting to STOMP endpoint: " + webSocketUrl); taskExecutor.execute(() -> stompClient.connect(webSocketUrl, new WebSocketSessionHandler())); taskExecutor.execute(new WebSocketSessionListener()); diff --git a/client/src/main/java/com/charego/lingo/client/singleplayer/SinglePlayerPresenter.java b/client/src/main/java/com/charego/lingo/client/singleplayer/SinglePlayerPresenter.java index 0000640..cbee79d 100644 --- a/client/src/main/java/com/charego/lingo/client/singleplayer/SinglePlayerPresenter.java +++ b/client/src/main/java/com/charego/lingo/client/singleplayer/SinglePlayerPresenter.java @@ -44,7 +44,7 @@ public class SinglePlayerPresenter { public SinglePlayerPresenter(WordRepository wordRepo, int wordLength, EventHandler backButtonHandler) { backButton = new Button("Back"); - backButton.getStyleClass().add("game-nav"); + backButton.getStyleClass().add("navigation"); StackPane.setAlignment(backButton, Pos.BOTTOM_LEFT); StackPane.setMargin(backButton, new Insets(0, 0, 10, 10)); backButton.setOnAction(backButtonHandler); diff --git a/client/src/main/java/module-info.java b/client/src/main/java/module-info.java index 5a44c11..51d5e35 100644 --- a/client/src/main/java/module-info.java +++ b/client/src/main/java/module-info.java @@ -15,4 +15,8 @@ module com.charego.lingo.client { requires spring.messaging; requires spring.web; requires spring.websocket; + exports com.charego.lingo.client.bootstrap; + exports com.charego.lingo.client.multiplayer; + opens com.charego.lingo.client.bootstrap to javafx.fxml, spring.core; + opens com.charego.lingo.client.multiplayer to javafx.fxml, spring.core; } diff --git a/client/src/main/resources/application.properties b/client/src/main/resources/application.properties new file mode 100644 index 0000000..95a6d6b --- /dev/null +++ b/client/src/main/resources/application.properties @@ -0,0 +1,2 @@ +# https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html +logging.level.com.charego.lingo = DEBUG diff --git a/client/src/main/resources/fxml/Lingo.fxml b/client/src/main/resources/fxml/Lingo.fxml index a56a7af..6e7f1c2 100644 --- a/client/src/main/resources/fxml/Lingo.fxml +++ b/client/src/main/resources/fxml/Lingo.fxml @@ -3,6 +3,7 @@ + @@ -14,16 +15,20 @@
+ + + +
- -
-