From 54f0a3efb9879e7076448909e1994f032929ba2a Mon Sep 17 00:00:00 2001 From: Aleksandr Zaitsev Date: Sun, 21 Jul 2024 21:00:12 +0300 Subject: [PATCH] add join link --- src/i18n/locales/en.json | 1 + src/i18n/locales/ru.json | 1 + src/stores/game.js | 6 +++++- src/views/LobbyView.vue | 9 ++++++++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 6779ce6..bcc9546 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -13,6 +13,7 @@ "generate": "Release the fish", "ready": "Ready", "cancel": "Cancel", + "copyLink": "Copy join link", "mainScreen": "Go to main screen", "instruction": "How to play", "rules": "Game rules" diff --git a/src/i18n/locales/ru.json b/src/i18n/locales/ru.json index 23ad8b0..251fbfb 100644 --- a/src/i18n/locales/ru.json +++ b/src/i18n/locales/ru.json @@ -13,6 +13,7 @@ "generate": "Запустить рыбу", "ready": "Готов", "cancel": "Отмена", + "copyLink": "Копировать ссылку для подключения", "mainScreen": "На главный экран", "instruction": "Как играть", "rules": "Правила" diff --git a/src/stores/game.js b/src/stores/game.js index 58762ea..2d04aa0 100644 --- a/src/stores/game.js +++ b/src/stores/game.js @@ -124,7 +124,11 @@ export const useGameStore = defineStore("game", { ready() { const board = new boardConstructor(this.boardSize, this.getAvailableItems()) if (!board.isAllItemsReady(this.player.items)) return - this.player.status = "ready" + if (this.player.status == "ready") { + this.player.status = "lobby" + } else { + this.player.status = "ready" + } if (this.mode == "single") { useBotStore().generate() return diff --git a/src/views/LobbyView.vue b/src/views/LobbyView.vue index f699ea7..329d9ac 100644 --- a/src/views/LobbyView.vue +++ b/src/views/LobbyView.vue @@ -27,9 +27,16 @@ const generate = () => { //Set ready status for player const ready = () => { if (game.mode == 'single') useBotStore().generate() - if (game.player.status == 'ready') game.player.status = 'lobby' if (board.isAllItemsReady(game.player.items)) game.ready() } + +const copyJoinLink = async () => { + try { + await navigator.clipboard.writeText(window.location.origin + '/join/' + game.id); + } catch (err) { + console.error('Failed to copy: ', err); + } +} const drawCell = (row, col) => { let classes = '' let cell = ((row * game.boardSize) + col) - 1