From 3b2797f25973d86751ebaa4aac9f07ad528f4b42 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Sun, 29 May 2022 17:02:05 +0200 Subject: [PATCH] Added first implementation of CC:Tweaked driver and improved UI. --- README.md | 23 ++++++------ component-drivers.md | 2 +- quasar-app/src/api/components.js | 13 +++++++ quasar-app/src/api/linkTokens.js | 2 +- quasar-app/src/api/websocket.js | 10 ++++- .../src/components/rs/SegmentListItem.vue | 2 +- .../components/rs/SelectedComponentView.vue | 14 ++++++- .../components/rs/settings/LinkTokensView.vue | 30 +++++++++++++-- quasar-app/src/render/drawing.js | 14 ++++++- .../live/ComponentDownlinkService.java | 11 +++++- .../live/dto/SegmentStatusMessage.java | 6 +-- .../live/websocket/AppUpdateService.java | 6 +-- .../websocket/ComponentWebsocketHandler.java | 2 - ...omponentWebsocketHandshakeInterceptor.java | 2 +- .../live/websocket/WebsocketConfig.java | 3 ++ .../rest/ComponentsApiController.java | 7 ++++ .../rest/LinkTokensApiController.java | 6 +-- .../StandaloneLinkTokenApiController.java | 21 +++++++++++ .../in/SwitchConfigurationUpdatePayload.java | 8 ++++ .../LinkTokenCreatedResponse.java | 2 +- .../{ => link_token}/LinkTokenPayload.java | 2 +- .../{ => link_token}/LinkTokenResponse.java | 2 +- .../StandaloneLinkTokenResponse.java | 37 +++++++++++++++++++ .../service/ComponentService.java | 27 +++++++++++++- .../service/LinkTokenService.java | 12 ++++-- .../railsignalapi/service/SegmentService.java | 13 +++++-- 26 files changed, 229 insertions(+), 48 deletions(-) create mode 100644 src/main/java/nl/andrewl/railsignalapi/rest/StandaloneLinkTokenApiController.java create mode 100644 src/main/java/nl/andrewl/railsignalapi/rest/dto/component/in/SwitchConfigurationUpdatePayload.java rename src/main/java/nl/andrewl/railsignalapi/rest/dto/{ => link_token}/LinkTokenCreatedResponse.java (53%) rename src/main/java/nl/andrewl/railsignalapi/rest/dto/{ => link_token}/LinkTokenPayload.java (82%) rename src/main/java/nl/andrewl/railsignalapi/rest/dto/{ => link_token}/LinkTokenResponse.java (91%) create mode 100644 src/main/java/nl/andrewl/railsignalapi/rest/dto/link_token/StandaloneLinkTokenResponse.java diff --git a/README.md b/README.md index a8d4c3d..15ea018 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,18 @@ -# RailSignalAPI -A simple API for tracking rail traffic in signalled blocks. +# Rail Signal +A comprehensive solution to tracking and managing your rail system, in real time. -You can download the program via [releases](https://github.com/andrewlalis/RailSignalAPI/releases). +## Development +To work on and develop Rail Signal, you will need to run both the Java/Spring-Boot backend API, and the Vue/Quasar frontend app. -Once you download the JAR file, you can simply run it with `java -jar `. Note that this program requires Java 17. +To start up the API, the project directory in IntelliJ (or the IDE of your choice), and run the `RailSignalApiApplication` main method. -Once it's started up, navigate to http://localhost:8080 to view the RailSignal web interface, where you can make changes to your systems. You should start by creating a new rail system. +To start up the app, open a terminal in the `quasar-app` directory, and run `quasar dev`. -Once you've done that, you can go ahead and create some signals for your system. - -## Immersive Railroading and ComputerCraft -To begin controlling your signals from within the game, you can set up a signal controller computer with a two detector augments on the rail (one for redstone, one for the computer connection) and two monitors. Make sure all perhipherals are connected to the network, and then run this command: +### Building +To build a complete API/app distributable JAR file, simply run the following: ``` -pastebin run Z72QhG7G +./build_system.d ``` -This will run an installation script that will guide you through setting up your signal's configuration. +> Note: The build script requires the D language toolchain to be installed on your system. Also, you can compile `build_system.d` to a native executable to run the build script more efficiently. -See [here](https://imgur.com/a/685HV7d) for some examples of how to build the signal structures within your world. +This will produce a `rail-signal-api-XXX.jar` file in the `target` directory, which contains both the API, and the frontend app, packaged together so that the entire JAR can simply be run via `java -jar`. \ No newline at end of file diff --git a/component-drivers.md b/component-drivers.md index bb5a29c..e9e3043 100644 --- a/component-drivers.md +++ b/component-drivers.md @@ -80,7 +80,7 @@ Signals display the status of a connected segment, and as such can only receive { "cId": 123, "type": "SEGMENT_STATUS", - "sId": 4, + "segmentId": 4, "occupied": true } ``` diff --git a/quasar-app/src/api/components.js b/quasar-app/src/api/components.js index b16d61f..36ca6e9 100644 --- a/quasar-app/src/api/components.js +++ b/quasar-app/src/api/components.js @@ -97,3 +97,16 @@ export function removeComponent(rs, id) { .catch(reject); }); } + +export function updateSwitchConfiguration(rs, sw, configId) { + return new Promise((resolve, reject) => { + axios.post( + `${API_URL}/rs/${rs.id}/c/${sw.id}/activeConfiguration`, + { + activeConfigurationId: configId + } + ) + .then(resolve) + .catch(reject); + }); +} diff --git a/quasar-app/src/api/linkTokens.js b/quasar-app/src/api/linkTokens.js index f0b2490..6017825 100644 --- a/quasar-app/src/api/linkTokens.js +++ b/quasar-app/src/api/linkTokens.js @@ -51,7 +51,7 @@ export function createLinkToken(rs, data) { * @param {RailSystem} rs * @param {Number} tokenId */ -export function deleteToken(rs, tokenId) { +export function deleteLinkToken(rs, tokenId) { return new Promise((resolve, reject) => { axios.delete(`${API_URL}/rs/${rs.id}/lt/${tokenId}`) .then(() => { diff --git a/quasar-app/src/api/websocket.js b/quasar-app/src/api/websocket.js index 160700f..d60765b 100644 --- a/quasar-app/src/api/websocket.js +++ b/quasar-app/src/api/websocket.js @@ -23,7 +23,15 @@ export function establishWebsocketConnection(rs) { } }; rs.websocket.onmessage = msg => { - console.log(msg); + const data = JSON.parse(msg.data); + console.log(data); + if (data.type === "COMPONENT_DATA") { + const id = data.cId; + const idx = rs.components.findIndex(c => c.id === id); + if (idx > -1) { + rs.components[idx] = data.data; + } + } }; rs.websocket.onerror = error => { console.log(error); diff --git a/quasar-app/src/components/rs/SegmentListItem.vue b/quasar-app/src/components/rs/SegmentListItem.vue index ac24153..1945fc2 100644 --- a/quasar-app/src/components/rs/SegmentListItem.vue +++ b/quasar-app/src/components/rs/SegmentListItem.vue @@ -5,7 +5,7 @@ Id: {{segment.id}} - + Occupied diff --git a/quasar-app/src/components/rs/SelectedComponentView.vue b/quasar-app/src/components/rs/SelectedComponentView.vue index 2eba20e..b27ccfe 100644 --- a/quasar-app/src/components/rs/SelectedComponentView.vue +++ b/quasar-app/src/components/rs/SelectedComponentView.vue @@ -7,6 +7,12 @@ {{component.type}} Id: {{component.id}} + + Online + + + Offline + @@ -100,6 +106,9 @@ /> + + Set Active + @@ -118,7 +127,7 @@ import { RailSystem } from "src/api/railSystems"; import { useRailSystemsStore } from "stores/railSystemsStore"; import SegmentListItem from "components/rs/SegmentListItem.vue"; import { useQuasar } from "quasar"; -import { removeComponent } from "src/api/components"; +import { removeComponent, updateSwitchConfiguration } from "src/api/components"; export default { name: "SelectedComponentView", @@ -166,6 +175,9 @@ export default { }); }); }); + }, + setActiveSwitchConfig(sw, configId) { + updateSwitchConfiguration(this.railSystem, sw, configId); } } }; diff --git a/quasar-app/src/components/rs/settings/LinkTokensView.vue b/quasar-app/src/components/rs/settings/LinkTokensView.vue index c6957a4..a92ed11 100644 --- a/quasar-app/src/components/rs/settings/LinkTokensView.vue +++ b/quasar-app/src/components/rs/settings/LinkTokensView.vue @@ -11,11 +11,11 @@ v-for="token in railSystem.linkTokens" :key="token.id" > - + {{token.label}} {{token.id}} - + Components + + + @@ -102,7 +105,7 @@