mirror of
https://github.com/AndrioCelos/TableturfBattleApp.git
synced 2026-04-26 09:59:59 -05:00
Add 'show QR code' button to the lobby
This commit is contained in:
parent
f2d1d3c998
commit
886a4d0787
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
[submodule "TableturfBattleClient/qrcodejs"]
|
||||||
|
path = TableturfBattleClient/qrcodejs
|
||||||
|
url = https://github.com/davidshimjs/qrcodejs.git
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
<link rel="manifest" href="assets/site.webmanifest">
|
<link rel="manifest" href="assets/site.webmanifest">
|
||||||
<link rel="stylesheet" href="tableturf.css"/>
|
<link rel="stylesheet" href="tableturf.css"/>
|
||||||
<script src="config/config.js"></script>
|
<script src="config/config.js"></script>
|
||||||
|
<script src="qrcodejs/qrcode.js"></script>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<meta property="og:type" content="website"/>
|
<meta property="og:type" content="website"/>
|
||||||
<meta name="title" property="og:title" content="Tableturf Battle"/>
|
<meta name="title" property="og:title" content="Tableturf Battle"/>
|
||||||
|
|
@ -58,7 +59,8 @@
|
||||||
</div>
|
</div>
|
||||||
<div id="lobbySection" hidden>
|
<div id="lobbySection" hidden>
|
||||||
<section id="lobbyPlayerListSection">
|
<section id="lobbyPlayerListSection">
|
||||||
<p>Other players can join using a link to this page. <button type="button" id="shareLinkButton">Share link</button></p>
|
<p>Other players can join using a link to this page.<br/>
|
||||||
|
<button type="button" id="shareLinkButton">Share link</button><button type="button" id="showQrCodeButton">Show QR code</button></p>
|
||||||
<ul id="playerList"></ul>
|
<ul id="playerList"></ul>
|
||||||
<div id="lobbySelectedStageSection" hidden>
|
<div id="lobbySelectedStageSection" hidden>
|
||||||
<h3>Stage</h3>
|
<h3>Stage</h3>
|
||||||
|
|
@ -81,6 +83,13 @@
|
||||||
<p><button type="button" id="submitDeckButton" disabled>Submit</button></p>
|
<p><button type="button" id="submitDeckButton" disabled>Submit</button></p>
|
||||||
<div id="lobbyDeckList" class="deckList"></div>
|
<div id="lobbyDeckList" class="deckList"></div>
|
||||||
</div>
|
</div>
|
||||||
|
<dialog id="qrCodeDialog">
|
||||||
|
<form method="dialog">
|
||||||
|
<p>Scan this QR code to join the game.</p>
|
||||||
|
<div id="qrCode"></div>
|
||||||
|
<button type="submit">Close</button>
|
||||||
|
</form>
|
||||||
|
</dialog>
|
||||||
</div>
|
</div>
|
||||||
<div id="gameSection" hidden>
|
<div id="gameSection" hidden>
|
||||||
<div class="playerBar" data-index="1">
|
<div class="playerBar" data-index="1">
|
||||||
|
|
|
||||||
1
TableturfBattleClient/qrcodejs
Submodule
1
TableturfBattleClient/qrcodejs
Submodule
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 04f46c6a0708418cb7b96fc563eacae0fbf77674
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
interface Config {
|
interface Config {
|
||||||
apiBaseUrl: string
|
apiBaseUrl: string,
|
||||||
|
qrCodeGameUrl: string | null | undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
var config: Config;
|
declare var config: Config;
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
const stageButtons: StageButton[] = [ ];
|
const stageButtons: StageButton[] = [ ];
|
||||||
const shareLinkButton = document.getElementById('shareLinkButton') as HTMLButtonElement;
|
const shareLinkButton = document.getElementById('shareLinkButton') as HTMLButtonElement;
|
||||||
|
const showQrCodeButton = document.getElementById('showQrCodeButton') as HTMLButtonElement;
|
||||||
const submitDeckButton = document.getElementById('submitDeckButton') as HTMLButtonElement;
|
const submitDeckButton = document.getElementById('submitDeckButton') as HTMLButtonElement;
|
||||||
let lobbyShareData: ShareData | null;
|
|
||||||
const stageSelectionForm = document.getElementById('stageSelectionForm') as HTMLFormElement;
|
const stageSelectionForm = document.getElementById('stageSelectionForm') as HTMLFormElement;
|
||||||
const stageRandomLabel = document.getElementById('stageRandomLabel')!;
|
const stageRandomLabel = document.getElementById('stageRandomLabel')!;
|
||||||
const stageRandomButton = document.getElementById('stageRandomButton') as HTMLInputElement;
|
const stageRandomButton = document.getElementById('stageRandomButton') as HTMLInputElement;
|
||||||
|
|
@ -14,6 +14,10 @@ const lobbyStageSection = document.getElementById('lobbyStageSection')!;
|
||||||
const lobbyDeckSection = document.getElementById('lobbyDeckSection')!;
|
const lobbyDeckSection = document.getElementById('lobbyDeckSection')!;
|
||||||
const lobbyDeckList = document.getElementById('lobbyDeckList')!;
|
const lobbyDeckList = document.getElementById('lobbyDeckList')!;
|
||||||
|
|
||||||
|
const qrCodeDialog = document.getElementById('qrCodeDialog') as HTMLDialogElement;
|
||||||
|
let qrCode: QRCode | null;
|
||||||
|
let lobbyShareData: ShareData | null;
|
||||||
|
|
||||||
let selectedStageButton = null as StageButton | null;
|
let selectedStageButton = null as StageButton | null;
|
||||||
|
|
||||||
function initLobbyPage(url: string) {
|
function initLobbyPage(url: string) {
|
||||||
|
|
@ -27,13 +31,29 @@ function initLobbyPage(url: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
shareLinkButton.addEventListener('click', () => {
|
shareLinkButton.addEventListener('click', () => {
|
||||||
if (lobbyShareData != null) {
|
if (lobbyShareData) {
|
||||||
navigator.share(lobbyShareData);
|
navigator.share(lobbyShareData);
|
||||||
} else {
|
} else {
|
||||||
navigator.clipboard.writeText(window.location.toString()).then(() => shareLinkButton.innerText = 'Copied');
|
navigator.clipboard.writeText(window.location.toString()).then(() => shareLinkButton.innerText = 'Copied');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
showQrCodeButton.addEventListener('click', () => {
|
||||||
|
const qrCodeUrl = config.qrCodeGameUrl ? config.qrCodeGameUrl.replace('$id', currentGame!.id) : window.location.href;
|
||||||
|
if (qrCode)
|
||||||
|
qrCode.makeCode(qrCodeUrl);
|
||||||
|
else
|
||||||
|
qrCode = new QRCode(document.getElementById("qrCode")!, qrCodeUrl);
|
||||||
|
qrCodeDialog.showModal();
|
||||||
|
});
|
||||||
|
|
||||||
|
qrCodeDialog.addEventListener('click', e => {
|
||||||
|
if (e.target == qrCodeDialog && (e.offsetX < 0 || e.offsetY < 0 || e.offsetX >= qrCodeDialog.offsetWidth || e.offsetY >= qrCodeDialog.offsetHeight)) {
|
||||||
|
// Background was clicked.
|
||||||
|
qrCodeDialog.close();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
function clearReady() {
|
function clearReady() {
|
||||||
if (currentGame == null) return;
|
if (currentGame == null) return;
|
||||||
for (var i = 0; i < currentGame.players.length; i++) {
|
for (var i = 0; i < currentGame.players.length; i++) {
|
||||||
|
|
|
||||||
17
TableturfBattleClient/src/qrcode.d.ts
vendored
Normal file
17
TableturfBattleClient/src/qrcode.d.ts
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
declare class QRCode {
|
||||||
|
constructor(el: HTMLElement | string, vOption: string | {
|
||||||
|
width: number | undefined,
|
||||||
|
height: number | undefined,
|
||||||
|
colorDark: string | undefined,
|
||||||
|
colorLight: string | undefined,
|
||||||
|
correctLevel: QRCode.CorrectLevel | undefined
|
||||||
|
} | undefined);
|
||||||
|
|
||||||
|
makeCode(sText: string) : void;
|
||||||
|
clear() : void;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
declare namespace QRCode {
|
||||||
|
enum CorrectLevel { M, L, H, Q }
|
||||||
|
}
|
||||||
|
|
@ -8,10 +8,12 @@
|
||||||
src: url('assets/splatoon2.woff2') format('woff2');
|
src: url('assets/splatoon2.woff2') format('woff2');
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body, dialog {
|
||||||
margin: 0;
|
|
||||||
color: white;
|
color: white;
|
||||||
background: black;
|
background: black;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
font-family: 'Splatoon 2', sans-serif;
|
font-family: 'Splatoon 2', sans-serif;
|
||||||
/* Default colours - normally the game data sent from the server will override these */
|
/* Default colours - normally the game data sent from the server will override these */
|
||||||
--primary-colour-1 : hsl(63, 99%, 49%);
|
--primary-colour-1 : hsl(63, 99%, 49%);
|
||||||
|
|
@ -104,6 +106,19 @@ footer {
|
||||||
to { left: 0; }
|
to { left: 0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dialog {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
dialog::backdrop {
|
||||||
|
background: black;
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
#qrCode {
|
||||||
|
background: white;
|
||||||
|
border: 1em solid white;
|
||||||
|
}
|
||||||
|
|
||||||
/* Stages */
|
/* Stages */
|
||||||
|
|
||||||
#stageList {
|
#stageList {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user