diff --git a/README.md b/README.md index 82d8404..9754990 100644 --- a/README.md +++ b/README.md @@ -21,10 +21,8 @@ and run: npm install ``` -### Start the container (in the project root) +### Start the container ```shell docker compose up --build ``` - -You can then access the website on `localhost:8080` diff --git a/docker-compose.yml b/docker-compose.yml index 2672685..96250c1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,32 +1,33 @@ -version: '3.1' - -services: - db: - build: backend/db - container_name: postgres-db - environment: - POSTGRES_DB: ${POSTGRES_DB} - POSTGRES_USER: ${POSTGRES_USER} - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} - ports: - - "${POSTGRES_PORT}:5432" - volumes: - - ./backend/pgdata:/var/lib/postgresql/data - - api: - build: backend/api - depends_on: - - db - container_name: express-api - ports: - - "${EXPRESS_PORT}:3000" - - vue: - build: frontend - container_name: frontend - ports: - - "${FRONTEND_PORT}:8080" - - - volumes: - - ./frontend:/app +version: '3.1' + +services: + db: + build: backend/db + container_name: postgres-db + environment: + POSTGRES_DB: ${POSTGRES_DB} + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + ports: + - "${POSTGRES_PORT}:5432" + volumes: + - ./backend/pgdata:/var/lib/postgresql/data + + api: + build: backend/api + depends_on: + - db + container_name: express-api + ports: + - "${EXPRESS_PORT}:3000" + + vue: + build: frontend + container_name: frontend + ports: + - "${FRONTEND_PORT}:8080" + + + volumes: + - ./frontend:/app + diff --git a/frontend/public/game.js b/frontend/public/game.js index 3b51b91..eaecfb2 100644 --- a/frontend/public/game.js +++ b/frontend/public/game.js @@ -43,7 +43,7 @@ var score = 0; var paused; var hasAlreadyScored = false; var hasDied = true; -var ready = true; +var ready = false; function preload(){ font = loadFont(FONT_PATH); @@ -67,6 +67,12 @@ function setup(){ window.dispatchEvent(event); originalSetItem.apply(this, arguments); }; + window.addEventListener("itemInserted", e => { + if(e.key === "frontend-ready"){ + ready = e.value === "true"; + score = 0; + } + }) } function setupObstacleConsts(){ @@ -155,13 +161,15 @@ function collisionCheck(o){ function die(){ if(localStorage.getItem("frontend-ready") == "false") return; - + ready = false; hasDied = true; playTime = Date.now() - startTime; exportToLocalStorage(); setTimeout(function(){ - return ready = true; + if(localStorage.getItem("frontend-ready") == "true"){ + return ready = true; + } }, 1000); } @@ -208,19 +216,20 @@ function checkRaspberryScore(){ } function resetScore(){ - if(!hasDied || localStorage.getItem("frontend-ready") == "false") + if(!hasDied) return; hasDied = false; score = 0; hasAlreadyScored = false; startTime = Date.now(); - exportToLocalStorage(); } function keyPressed(){ - if(!ready) + if(!ready){ return; + } + if(BOOST_KEYS.includes(key.toLowerCase())){ resetScore(); raspberry.boost(); diff --git a/frontend/src/components/Login.vue b/frontend/src/components/Login.vue index 3be8534..ec3a1ce 100644 --- a/frontend/src/components/Login.vue +++ b/frontend/src/components/Login.vue @@ -39,6 +39,7 @@ export default { if (user) { this.$emit('userChange', user); + localStorage.setItem("frontend-ready", "true"); } }, } diff --git a/frontend/src/model/Rest.ts b/frontend/src/model/Rest.ts index 53b902e..04d93cc 100644 --- a/frontend/src/model/Rest.ts +++ b/frontend/src/model/Rest.ts @@ -1,3 +1,3 @@ export class Rest { - static readonly URL = 'http://localhost:3000'; + static readonly URL = 'http://139.144.178.216:3000'; } \ No newline at end of file