mirror of
https://github.com/anatolykopyl/vk-bingo.git
synced 2026-03-26 12:54:25 +00:00
Game works
This commit is contained in:
190
backend/index.js
190
backend/index.js
@@ -84,49 +84,56 @@ const client = new MongoClient(process.env.URI, { useUnifiedTopology: true });
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
async function drawCard() {
|
||||||
|
let card;
|
||||||
|
// Тянем карты и отбрасываем их в соответствии с их вероятностью отбрасывания
|
||||||
|
do {
|
||||||
|
/* eslint-disable no-await-in-loop */
|
||||||
|
card = await cardsCollection.aggregate([
|
||||||
|
{
|
||||||
|
$sample: { size: 1 },
|
||||||
|
}, {
|
||||||
|
$unset: ['link', 'date'],
|
||||||
|
},
|
||||||
|
]).toArray();
|
||||||
|
/* eslint-enable no-await-in-loop */
|
||||||
|
[card] = card;
|
||||||
|
} while (Math.random() < dropProb[card.name]);
|
||||||
|
return card;
|
||||||
|
}
|
||||||
|
|
||||||
|
let players = {}
|
||||||
|
let oldPlayers = {}
|
||||||
|
let score = {}
|
||||||
|
let card = await drawCard()
|
||||||
|
let oldCard = null;
|
||||||
|
let answers = 0
|
||||||
|
|
||||||
app.post('/api/auth', async (req, res) => {
|
app.post('/api/auth', async (req, res) => {
|
||||||
if (req.session.loggedIn) {
|
const { pass, username } = req.body;
|
||||||
res.status(200).send('Logged in');
|
|
||||||
|
if (username && !Object.keys(players).includes(username)) {
|
||||||
|
players[username] = null;
|
||||||
|
emitter.emit('connection', Object.keys(players))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pass && pass.toLowerCase() === process.env.PASSWORD) {
|
||||||
|
req.session.loggedIn = true;
|
||||||
|
return res.status(200).send('Logged in');
|
||||||
} else {
|
} else {
|
||||||
try {
|
return res.status(401).send('Wrong password');
|
||||||
const { pass } = req.body;
|
|
||||||
if (pass && pass.toLowerCase() === process.env.PASSWORD) {
|
|
||||||
req.session.loggedIn = true;
|
|
||||||
res.status(200).send('Logged in');
|
|
||||||
} else {
|
|
||||||
res.status(401).send('Wrong password');
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.log(`Error: ${e}`);
|
|
||||||
res.status(500).send();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/api/card', async (req, res) => {
|
app.get('/api/card', async (req, res) => {
|
||||||
async function drawCard() {
|
if (!req.session.loggedIn) {
|
||||||
let card;
|
return res.status(403).send();
|
||||||
// Тянем карты и отбрасываем их в соответствии с их вероятностью отбрасывания
|
|
||||||
do {
|
|
||||||
/* eslint-disable no-await-in-loop */
|
|
||||||
card = await cardsCollection.aggregate([
|
|
||||||
{
|
|
||||||
$sample: { size: 1 },
|
|
||||||
}, {
|
|
||||||
$unset: ['name', 'link', 'date'],
|
|
||||||
},
|
|
||||||
]).toArray();
|
|
||||||
/* eslint-enable no-await-in-loop */
|
|
||||||
[card] = card;
|
|
||||||
} while (Math.random() < dropProb[card.name]);
|
|
||||||
return card;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.session.loggedIn) {
|
return res.status(200).send({
|
||||||
res.status(200).send(await drawCard());
|
...card,
|
||||||
} else {
|
name: undefined
|
||||||
res.status(403).send();
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/api/meme', async (req, res) => {
|
app.get('/api/meme', async (req, res) => {
|
||||||
@@ -142,7 +149,6 @@ const client = new MongoClient(process.env.URI, { useUnifiedTopology: true });
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const state = {}
|
|
||||||
app.post('/api/answer', async (req, res) => {
|
app.post('/api/answer', async (req, res) => {
|
||||||
if (!req.session.loggedIn) {
|
if (!req.session.loggedIn) {
|
||||||
return res.status(403).send();
|
return res.status(403).send();
|
||||||
@@ -168,8 +174,11 @@ const client = new MongoClient(process.env.URI, { useUnifiedTopology: true });
|
|||||||
selected: req.body.data.name,
|
selected: req.body.data.name,
|
||||||
});
|
});
|
||||||
|
|
||||||
state[req.body.data.username] = true
|
players[req.body.data.username] = req.body.data.name;
|
||||||
emitter.emit('answer', req.body.data.username);
|
emitter.emit('answer', {
|
||||||
|
username: req.body.data.username,
|
||||||
|
selected: req.body.data.name
|
||||||
|
});
|
||||||
|
|
||||||
// return res.status(200).send({
|
// return res.status(200).send({
|
||||||
// correct,
|
// correct,
|
||||||
@@ -193,31 +202,33 @@ const client = new MongoClient(process.env.URI, { useUnifiedTopology: true });
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.get('/api/stats', async (req, res) => {
|
app.get('/api/stats', async (req, res) => {
|
||||||
if (req.session.loggedIn) {
|
if (!req.session.loggedIn) {
|
||||||
answersCollection.aggregate([
|
return res.status(403).send();
|
||||||
{
|
}
|
||||||
$group: {
|
|
||||||
_id: '$selected',
|
const stats = await answersCollection.aggregate([
|
||||||
correct: {
|
{
|
||||||
$sum: {
|
$group: {
|
||||||
$cond: [
|
_id: '$selected',
|
||||||
'$correct', 1, 0,
|
correct: {
|
||||||
],
|
$sum: {
|
||||||
},
|
$cond: [
|
||||||
|
'$correct', 1, 0,
|
||||||
|
],
|
||||||
},
|
},
|
||||||
wrong: {
|
},
|
||||||
$sum: {
|
wrong: {
|
||||||
$cond: [
|
$sum: {
|
||||||
'$correct', 0, 1,
|
$cond: [
|
||||||
],
|
'$correct', 0, 1,
|
||||||
},
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]).toArray().then((stats) => res.status(200).send(stats));
|
},
|
||||||
} else {
|
]).toArray();
|
||||||
res.status(403).send();
|
|
||||||
}
|
return res.status(200).send(stats);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/api/options', async (req, res) => {
|
app.get('/api/options', async (req, res) => {
|
||||||
@@ -228,27 +239,20 @@ const client = new MongoClient(process.env.URI, { useUnifiedTopology: true });
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let usernames = new Set();
|
app.get('/api/players', async (req, res) => {
|
||||||
app.post('/api/connect', async (req, res) => {
|
|
||||||
if (!req.session.loggedIn) {
|
if (!req.session.loggedIn) {
|
||||||
return res.status(403).send();
|
return res.status(403).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
const { username } = req.body;
|
return res.status(200).send(Object.keys(players));
|
||||||
usernames.add(username);
|
})
|
||||||
state[username] = false;
|
|
||||||
emitter.emit('connection', usernames)
|
|
||||||
|
|
||||||
return res.status(200).send();
|
|
||||||
});
|
|
||||||
|
|
||||||
app.post('/api/end', async (req, res) => {
|
app.post('/api/end', async (req, res) => {
|
||||||
if (!req.session.loggedIn) {
|
if (!req.session.loggedIn) {
|
||||||
return res.status(403).send();
|
return res.status(403).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
usernames = new Set();
|
players = {}
|
||||||
state = {}
|
|
||||||
return res.status(200).send();
|
return res.status(200).send();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -261,21 +265,45 @@ const client = new MongoClient(process.env.URI, { useUnifiedTopology: true });
|
|||||||
});
|
});
|
||||||
res.flushHeaders();
|
res.flushHeaders();
|
||||||
|
|
||||||
emitter.on('connection', (usernames) => {
|
emitter.on('connection', (players) => {
|
||||||
const data = usernames
|
const data = players
|
||||||
res.write(`data: ${JSON.stringify(data)}\nevent: userlist\n\n`);
|
res.write(`data: ${JSON.stringify(data)}\nevent: userlist\n\n`);
|
||||||
})
|
})
|
||||||
|
|
||||||
emitter.on('answer', (username) => {
|
emitter.on('answer', async ({
|
||||||
|
username, selected
|
||||||
|
}) => {
|
||||||
const data = {
|
const data = {
|
||||||
username,
|
username,
|
||||||
state
|
players,
|
||||||
|
selected
|
||||||
}
|
}
|
||||||
res.write(`data: ${JSON.stringify(data)}\nevent: answer\n\n`);
|
res.write(`data: ${JSON.stringify(data)}\nevent: answer\n\n`);
|
||||||
|
|
||||||
|
answers += 1
|
||||||
|
|
||||||
|
if (answers === Object.keys(players).length) {
|
||||||
|
Object.keys(players).forEach((key) => {
|
||||||
|
if (card.name === players[key]) {
|
||||||
|
score[key] = (score[key] ?? 0) + 1
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
Object.keys(players).forEach((key) => {
|
||||||
|
players[key] = null
|
||||||
|
})
|
||||||
|
answers = 0
|
||||||
|
oldCard = { ...card }
|
||||||
|
card = await drawCard()
|
||||||
|
emitter.emit('allDone');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
emitter.on('allDone', () => {
|
emitter.on('allDone', () => {
|
||||||
const data = {}
|
const data = {
|
||||||
|
correctAnswer: oldCard.name,
|
||||||
|
score
|
||||||
|
}
|
||||||
res.write(`data: ${JSON.stringify(data)}\nevent: reveal\n\n`);
|
res.write(`data: ${JSON.stringify(data)}\nevent: reveal\n\n`);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -284,17 +312,5 @@ const client = new MongoClient(process.env.URI, { useUnifiedTopology: true });
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
let answers = 0;
|
|
||||||
emitter.on('answer', () => {
|
|
||||||
answers += 1;
|
|
||||||
|
|
||||||
if (answers === usernames.length) {
|
|
||||||
Object.keys(state).forEach((key) => {
|
|
||||||
state[key] = false
|
|
||||||
})
|
|
||||||
emitter.emit('allDone');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.listen(process.env.PORT, () => console.log(`Server started on ${process.env.PORT}`));
|
app.listen(process.env.PORT, () => console.log(`Server started on ${process.env.PORT}`));
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -7,13 +7,14 @@
|
|||||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||||
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
|
<link rel="icon" href="favicon.ico">
|
||||||
<link rel="manifest" href="<%= BASE_URL %>manifest.json">
|
<link rel="manifest" href="manifest.json">
|
||||||
<title>Флекспатруль мультиплеер</title>
|
<title>Флекспатруль мультиплеер</title>
|
||||||
|
<script type="module" src="/src/main.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<noscript>
|
<noscript>
|
||||||
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
<strong>We're sorry but Флекспатруль мультиплеер doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
||||||
</noscript>
|
</noscript>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<!-- built files will be auto injected -->
|
<!-- built files will be auto injected -->
|
||||||
@@ -4,33 +4,31 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"serve": "vue-cli-service serve",
|
"dev": "vite dev",
|
||||||
"build": "vue-cli-service build",
|
"build": "vite build"
|
||||||
"lint": "vue-cli-service lint"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.21.1",
|
"axios": "^0.21.1",
|
||||||
"core-js": "^3.6.5",
|
|
||||||
"pinia": "^2.1.4",
|
"pinia": "^2.1.4",
|
||||||
|
"pinia-plugin-persistedstate": "^3.1.0",
|
||||||
"vue": "^3.3.4",
|
"vue": "^3.3.4",
|
||||||
"vue-peel": "^0.1.1",
|
"vue-peel": "^0.1.1",
|
||||||
"vue-router": "4",
|
"vue-router": "4",
|
||||||
"vue-spinner": "^1.0.4"
|
"vue-spinner": "^1.0.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vue/cli-plugin-babel": "~4.5.0",
|
"@vitejs/plugin-vue": "^4.2.3",
|
||||||
"@vue/cli-plugin-eslint": "~4.5.0",
|
|
||||||
"@vue/cli-service": "~4.5.0",
|
|
||||||
"@vue/compiler-sfc": "^3.0.0",
|
|
||||||
"babel-eslint": "^10.1.0",
|
|
||||||
"dotenv-webpack": "^7.0.2",
|
"dotenv-webpack": "^7.0.2",
|
||||||
"eslint": "^6.7.2",
|
"eslint": "8",
|
||||||
"eslint-plugin-vue": "^7.0.0"
|
"eslint-plugin-vue": "8",
|
||||||
|
"sass": "^1.63.4",
|
||||||
|
"vite": "^4.3.9"
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
"root": true,
|
"root": true,
|
||||||
"env": {
|
"env": {
|
||||||
"node": true
|
"node": true,
|
||||||
|
"es2022": true
|
||||||
},
|
},
|
||||||
"extends": [
|
"extends": [
|
||||||
"plugin:vue/vue3-recommended",
|
"plugin:vue/vue3-recommended",
|
||||||
|
|||||||
BIN
frontend/public/fonts/PPNeueMontreal-Bold.otf
Normal file
BIN
frontend/public/fonts/PPNeueMontreal-Bold.otf
Normal file
Binary file not shown.
BIN
frontend/public/fonts/PPNeueMontreal-Medium.otf
Normal file
BIN
frontend/public/fonts/PPNeueMontreal-Medium.otf
Normal file
Binary file not shown.
BIN
frontend/public/fonts/PPPangramSansRounded-Bold.otf
Normal file
BIN
frontend/public/fonts/PPPangramSansRounded-Bold.otf
Normal file
Binary file not shown.
BIN
frontend/public/fonts/PPPangramSansRounded-Light.otf
Normal file
BIN
frontend/public/fonts/PPPangramSansRounded-Light.otf
Normal file
Binary file not shown.
BIN
frontend/public/fonts/PPPangramSansRounded-Medium.otf
Normal file
BIN
frontend/public/fonts/PPPangramSansRounded-Medium.otf
Normal file
Binary file not shown.
BIN
frontend/public/fonts/PPPangramSansRounded-Semibold.otf
Normal file
BIN
frontend/public/fonts/PPPangramSansRounded-Semibold.otf
Normal file
Binary file not shown.
BIN
frontend/public/fonts/donner.ttf
Normal file
BIN
frontend/public/fonts/donner.ttf
Normal file
Binary file not shown.
@@ -1,15 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<h1>Флекспатруль мультиплеер</h1>
|
|
||||||
|
|
||||||
<router-view />
|
<router-view />
|
||||||
|
|
||||||
<a
|
|
||||||
class="source"
|
|
||||||
href="https://github.com/anatolykopyl/vk-bingo"
|
|
||||||
target="_blank"
|
|
||||||
>
|
|
||||||
Исходный код
|
|
||||||
</a>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
@@ -17,49 +7,44 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@font-face {
|
||||||
|
font-family: "Pangram Sans Rounded";
|
||||||
|
font-weight: bold;
|
||||||
|
src: local("Pangram Sans Rounded"), url("/fonts/PPPangramSansRounded-Bold.otf") format("opentype");
|
||||||
|
}
|
||||||
|
|
||||||
|
@font-face {
|
||||||
|
font-family: "Pangram Sans Rounded";
|
||||||
|
font-weight: 600;
|
||||||
|
src: local("Pangram Sans Rounded"), url("/fonts/PPPangramSansRounded-Semibold.otf") format("opentype");
|
||||||
|
}
|
||||||
|
|
||||||
|
@font-face {
|
||||||
|
font-family: "Pangram Sans Rounded";
|
||||||
|
font-weight: normal;
|
||||||
|
src: local("Pangram Sans Rounded"), url("/fonts/PPPangramSansRounded-Medium.otf") format("opentype");
|
||||||
|
}
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--clr-bg: #ffd537;
|
||||||
|
--clr-accent: #37ffac;
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
background-color: #5a5a5a;
|
background-color: var(--clr-bg);
|
||||||
}
|
}
|
||||||
|
|
||||||
#app {
|
#app {
|
||||||
font-family: Avenir, Helvetica, Arial, sans-serif;
|
font-family: "Pangram Sans Rounded", Avenir, Helvetica, Arial, sans-serif;
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
-moz-osx-font-smoothing: grayscale;
|
-moz-osx-font-smoothing: grayscale;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #f3f3f3;
|
color: black;
|
||||||
margin-top: 60px;
|
margin-top: 60px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#game {
|
#game {
|
||||||
margin-bottom: 100px;
|
margin-bottom: 100px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.source {
|
|
||||||
color: #f3f3f350;
|
|
||||||
background-color: #12121250;
|
|
||||||
border-radius: 6px;
|
|
||||||
padding: 3px 6px;
|
|
||||||
position: fixed;
|
|
||||||
width: 20ch;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
bottom: 10px;
|
|
||||||
text-align: center;
|
|
||||||
margin: 0 auto;
|
|
||||||
transition: all 0.3s;
|
|
||||||
cursor: pointer;
|
|
||||||
z-index: -1;
|
|
||||||
}
|
|
||||||
.source:hover {
|
|
||||||
color: #f3f3f3;
|
|
||||||
background-color: #121212;
|
|
||||||
box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.6);
|
|
||||||
}
|
|
||||||
|
|
||||||
@media only screen and (max-width: 520px) {
|
|
||||||
.source {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
39
frontend/src/components/SourceCodeLink.vue
Normal file
39
frontend/src/components/SourceCodeLink.vue
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<template>
|
||||||
|
<a
|
||||||
|
class="source"
|
||||||
|
href="https://github.com/anatolykopyl/vk-bingo"
|
||||||
|
target="_blank"
|
||||||
|
>
|
||||||
|
Исходный код
|
||||||
|
</a>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.source {
|
||||||
|
color: #f3f3f350;
|
||||||
|
background-color: #12121250;
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 3px 6px;
|
||||||
|
position: fixed;
|
||||||
|
width: 20ch;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 10px;
|
||||||
|
text-align: center;
|
||||||
|
margin: 0 auto;
|
||||||
|
transition: all 0.3s;
|
||||||
|
cursor: pointer;
|
||||||
|
z-index: -1;
|
||||||
|
}
|
||||||
|
.source:hover {
|
||||||
|
color: #f3f3f3;
|
||||||
|
background-color: #121212;
|
||||||
|
box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.6);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media only screen and (max-width: 520px) {
|
||||||
|
.source {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
export default () => {
|
export default () => {
|
||||||
// const store = useStore()
|
// const store = useStore()
|
||||||
|
|
||||||
const evtSource = new EventSource(`${process.env.VUE_APP_BACKEND}/stream`);
|
const evtSource = new EventSource(`${import.meta.env.VITE_APP_BACKEND}/stream`);
|
||||||
|
|
||||||
function addAnswerListener(handler) {
|
function addAnswerListener(handler) {
|
||||||
evtSource.addEventListener('answer', (event) => handler(JSON.parse(event.data)))
|
evtSource.addEventListener('answer', (event) => handler(JSON.parse(event.data)))
|
||||||
@@ -13,5 +13,9 @@ export default () => {
|
|||||||
evtSource.addEventListener('userlist', (event) => handler(JSON.parse(event.data)))
|
evtSource.addEventListener('userlist', (event) => handler(JSON.parse(event.data)))
|
||||||
}
|
}
|
||||||
|
|
||||||
return { addAnswerListener, addUserlistListener }
|
function addRevealListener(handler) {
|
||||||
|
evtSource.addEventListener('reveal', (event) => handler(JSON.parse(event.data)))
|
||||||
|
}
|
||||||
|
|
||||||
|
return { addAnswerListener, addUserlistListener, addRevealListener }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
|
import { createPinia } from 'pinia'
|
||||||
|
import piniaPluginPersistedstate from "pinia-plugin-persistedstate";
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
import router from './router'
|
import router from './router'
|
||||||
|
|
||||||
const app = createApp(App)
|
const app = createApp(App)
|
||||||
|
const pinia = createPinia()
|
||||||
|
pinia.use(piniaPluginPersistedstate);
|
||||||
|
|
||||||
app.use(router)
|
app.use(router)
|
||||||
|
app.use(pinia)
|
||||||
app.mount('#app')
|
app.mount('#app')
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import Login from './views/Login/Index.vue'
|
|||||||
import Screen from './views/Screen/Index.vue'
|
import Screen from './views/Screen/Index.vue'
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
{ path: '/', component: Game },
|
{ path: '/game', component: Game },
|
||||||
{ path: '/login', component: Login },
|
{ path: '/', component: Login },
|
||||||
{ path: '/screen', component: Screen }
|
{ path: '/screen', component: Screen }
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
|
|
||||||
export default defineStore('store', {
|
export default defineStore({
|
||||||
|
id: 'store',
|
||||||
|
persist: true,
|
||||||
|
|
||||||
state: () => ({
|
state: () => ({
|
||||||
username: null
|
username: null
|
||||||
}),
|
}),
|
||||||
|
|||||||
9
frontend/src/styles/_prepend.scss
Normal file
9
frontend/src/styles/_prepend.scss
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
@mixin filled-shadow($distance) {
|
||||||
|
$resulting-shadow: null;
|
||||||
|
|
||||||
|
@for $i from 1 through $distance {
|
||||||
|
$resulting-shadow: $resulting-shadow, #{$i}px #{$i}px 0 black;
|
||||||
|
}
|
||||||
|
|
||||||
|
box-shadow: $resulting-shadow;
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div class="end">
|
||||||
<button @click="endGame">
|
<button
|
||||||
|
@click="endGame"
|
||||||
|
class="endButton"
|
||||||
|
>
|
||||||
Закончить игру
|
Закончить игру
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -12,7 +15,28 @@ import { useRouter } from 'vue-router';
|
|||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
function endGame() {
|
function endGame() {
|
||||||
axios.post(process.env.VUE_APP_BACKEND + '/end')
|
axios.post(import.meta.env.VITE_APP_BACKEND + '/end')
|
||||||
router.push('/login')
|
router.push('/')
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.end {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 8px;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.endButton {
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
font: inherit;
|
||||||
|
padding: 8px 12px;
|
||||||
|
border-bottom: 1px dotted black;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<h1>Флекспатруль мультиплеер</h1>
|
||||||
|
|
||||||
|
<div class="main">
|
||||||
<div
|
<div
|
||||||
class="card"
|
class="card"
|
||||||
v-if="card"
|
v-if="card"
|
||||||
@@ -11,8 +13,8 @@
|
|||||||
<h2>Кто скинул этот мем?</h2>
|
<h2>Кто скинул этот мем?</h2>
|
||||||
<div class="interactive">
|
<div class="interactive">
|
||||||
<transition name="fade-answers">
|
<transition name="fade-answers">
|
||||||
<List
|
<List
|
||||||
v-if="!selectedAnswer"
|
v-if="!showResult"
|
||||||
:options="options"
|
:options="options"
|
||||||
@selectedAnswer="selectAnswer"
|
@selectedAnswer="selectAnswer"
|
||||||
/>
|
/>
|
||||||
@@ -20,98 +22,96 @@
|
|||||||
<transition name="spin-result">
|
<transition name="spin-result">
|
||||||
<Result
|
<Result
|
||||||
v-if="showResult"
|
v-if="showResult"
|
||||||
:name="card.name"
|
|
||||||
:selectedName="selectedAnswer"
|
:selectedName="selectedAnswer"
|
||||||
:date="card.date"
|
:correct="correctAnswer"
|
||||||
:correct="correctAnswer"
|
|
||||||
/>
|
/>
|
||||||
</transition>
|
</transition>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Score
|
|
||||||
v-if="card"
|
|
||||||
:score="score"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<EndGame />
|
<EndGame />
|
||||||
|
|
||||||
<square-loader
|
<square-loader
|
||||||
v-if="!card"
|
v-if="!card"
|
||||||
:color="'#f3f3f3'"
|
:color="'white'"
|
||||||
class="loader"
|
class="loader"
|
||||||
/>
|
/>
|
||||||
<Stats />
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { onMounted, reactive, ref } from 'vue'
|
import { onMounted, ref } from 'vue'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import List from './List.vue'
|
import List from './List.vue'
|
||||||
import Result from './Result.vue'
|
import Result from './Result.vue'
|
||||||
import Score from './Score.vue'
|
|
||||||
import Stats from './Stats.vue'
|
|
||||||
import EndGame from './EndGame.vue'
|
import EndGame from './EndGame.vue'
|
||||||
|
import useStore from '@/store'
|
||||||
|
import useServerEvents from '@/composables/useServerEvents'
|
||||||
|
|
||||||
import SquareLoader from 'vue-spinner/src/SquareLoader.vue'
|
import SquareLoader from 'vue-spinner/src/SquareLoader.vue'
|
||||||
|
|
||||||
|
const store = useStore()
|
||||||
|
const { addRevealListener } = useServerEvents()
|
||||||
|
|
||||||
const options = ref()
|
const options = ref()
|
||||||
const card = ref()
|
const card = ref()
|
||||||
const correctAnswer = ref()
|
const correctAnswer = ref()
|
||||||
const selectedAnswer = ref()
|
const selectedAnswer = ref()
|
||||||
const showResult = ref()
|
const showResult = ref()
|
||||||
const score = reactive({
|
|
||||||
"right": 0,
|
addRevealListener((data) => {
|
||||||
"wrong": 0
|
showResult.value = true
|
||||||
|
correctAnswer.value = data.correctAnswer
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
getCard()
|
||||||
|
}, 5000)
|
||||||
})
|
})
|
||||||
|
|
||||||
async function getCard() {
|
async function getCard() {
|
||||||
correctAnswer.value = null
|
correctAnswer.value = null
|
||||||
selectedAnswer.value = null
|
selectedAnswer.value = null
|
||||||
showResult.value = false
|
showResult.value = false
|
||||||
const response = await axios.get(process.env.VUE_APP_BACKEND + '/card')
|
card.value = null
|
||||||
|
const response = await axios.get(import.meta.env.VITE_APP_BACKEND + '/card')
|
||||||
card.value = response.data
|
card.value = response.data
|
||||||
}
|
}
|
||||||
|
|
||||||
async function selectAnswer(selection) {
|
async function selectAnswer(selection) {
|
||||||
selectedAnswer.value = selection
|
selectedAnswer.value = selection
|
||||||
// setTimeout(function() {
|
|
||||||
// showResult.value = true
|
|
||||||
// if (correctAnswer.value) {
|
|
||||||
// score.right++
|
|
||||||
// } else {
|
|
||||||
// score.wrong++
|
|
||||||
// }
|
|
||||||
// }, 805)
|
|
||||||
|
|
||||||
await axios.post(process.env.VUE_APP_BACKEND + '/answer', {
|
await axios.post(import.meta.env.VITE_APP_BACKEND + '/answer', {
|
||||||
'data': {
|
'data': {
|
||||||
'id': card.value._id,
|
'id': card.value._id,
|
||||||
'name': selectedAnswer.value
|
'name': selectedAnswer.value,
|
||||||
|
'username': store.username
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
getCard()
|
getCard()
|
||||||
const response = await axios.get(process.env.VUE_APP_BACKEND + '/options')
|
const response = await axios.get(import.meta.env.VITE_APP_BACKEND + '/options')
|
||||||
options.value = response.data
|
options.value = response.data
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped lang="scss">
|
||||||
|
.main {
|
||||||
|
padding-bottom: 200px;
|
||||||
|
}
|
||||||
|
|
||||||
.card {
|
.card {
|
||||||
width: 450px;
|
width: 450px;
|
||||||
padding: 18px;
|
|
||||||
border-radius: 17px;
|
|
||||||
box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.6);
|
|
||||||
background-color: #121212;
|
|
||||||
margin: auto;
|
margin: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.meme {
|
.meme {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-radius: 8px;
|
border-radius: 32px;
|
||||||
|
border: 3px solid black;
|
||||||
|
@include filled-shadow(16);
|
||||||
|
transform: translateX(-8px);
|
||||||
}
|
}
|
||||||
|
|
||||||
.clickable {
|
.clickable {
|
||||||
@@ -120,8 +120,11 @@ onMounted(async () => {
|
|||||||
|
|
||||||
.interactive {
|
.interactive {
|
||||||
position: relative;
|
position: relative;
|
||||||
-webkit-perspective: 900000px;
|
|
||||||
perspective: 900000px;
|
> * {
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.fade-answers-leave-active {
|
.fade-answers-leave-active {
|
||||||
|
|||||||
@@ -1,6 +1,16 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="answers">
|
<div
|
||||||
<span class="option" v-for="name in options" :key="name" v-on:click="selectAnswer(name)">
|
class="answers"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
class="option"
|
||||||
|
v-for="name in options"
|
||||||
|
:key="name"
|
||||||
|
@click="selectAnswer(name)"
|
||||||
|
:class="{
|
||||||
|
'-selected': selection === name
|
||||||
|
}"
|
||||||
|
>
|
||||||
{{ name }}
|
{{ name }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -12,8 +22,18 @@ export default {
|
|||||||
props: {
|
props: {
|
||||||
options: Array
|
options: Array
|
||||||
},
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
selection: null
|
||||||
|
}
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
selectAnswer: function(selection) {
|
selectAnswer: function(selection) {
|
||||||
|
if (this.selection) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.selection = selection
|
||||||
this.$emit('selectedAnswer', selection)
|
this.$emit('selectedAnswer', selection)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,15 +45,21 @@ export default {
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
justify-content: space-around;
|
justify-content: space-around;
|
||||||
|
gap: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.option {
|
.option {
|
||||||
background-color: #5a5a5a;
|
background-color: white;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
margin: 3px;
|
padding: 2px 6px;
|
||||||
padding: 5px 9px;
|
|
||||||
transition: transform 0.2s;
|
transition: transform 0.2s;
|
||||||
|
border: 3px dashed transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.option.-selected {
|
||||||
|
border-color: var(--clr-accent);
|
||||||
|
}
|
||||||
|
|
||||||
.option:hover {
|
.option:hover {
|
||||||
transform: scale(1.06);
|
transform: scale(1.06);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|||||||
@@ -1,8 +1,17 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<span v-show="!correct" class="wrong">Нет, это был не {{ selectedName }} 😢</span>
|
<div
|
||||||
<div class="result" v-bind:class="{correct: correct}">
|
class="result"
|
||||||
{{ name }} {{ date }}
|
:class="{correct: correct === selectedName}"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-show="correct !== selectedName"
|
||||||
|
class="wrong"
|
||||||
|
>
|
||||||
|
Нет, это был не {{ selectedName }} 😢
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{ correct }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -14,7 +23,7 @@ export default {
|
|||||||
name: String,
|
name: String,
|
||||||
selectedName: String,
|
selectedName: String,
|
||||||
date: String,
|
date: String,
|
||||||
correct: Boolean
|
correct: String
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -23,12 +32,12 @@ export default {
|
|||||||
.result {
|
.result {
|
||||||
padding: 30px 40px;
|
padding: 30px 40px;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
background-color: #5a5a5a;
|
background-color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
.correct {
|
.correct {
|
||||||
color: #121212;
|
color: black;
|
||||||
background-color: rgb(124, 230, 124);
|
background-color: var(--clr-accent);
|
||||||
}
|
}
|
||||||
|
|
||||||
.wrong {
|
.wrong {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export default {
|
|||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
axios
|
axios
|
||||||
.get(process.env.VUE_APP_BACKEND + '/stats')
|
.get(import.meta.env.VITE_APP_BACKEND + '/stats')
|
||||||
.then(response => {
|
.then(response => {
|
||||||
response.data.forEach(element => {
|
response.data.forEach(element => {
|
||||||
this.stats[element._id] = element.correct / element.wrong
|
this.stats[element._id] = element.correct / element.wrong
|
||||||
|
|||||||
@@ -1,25 +1,41 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<h1>Флекспатруль мультиплеер</h1>
|
||||||
|
|
||||||
|
<div class="authCard">
|
||||||
<h1>Авторизация:</h1>
|
<h1>Авторизация:</h1>
|
||||||
<p>{{ question }}</p>
|
|
||||||
<input
|
<div class="auth">
|
||||||
placeholder="Ответ"
|
<p>{{ question }}</p>
|
||||||
v-model="answer"
|
<input
|
||||||
>
|
placeholder="Ответ"
|
||||||
<br>
|
v-model="answer"
|
||||||
<input
|
>
|
||||||
placeholder="Ваше имя"
|
<input
|
||||||
v-model="username"
|
v-if="mode === 'player'"
|
||||||
>
|
placeholder="Ваше имя"
|
||||||
<br>
|
v-model="username"
|
||||||
<button
|
>
|
||||||
@click="login"
|
|
||||||
:class="{
|
<button
|
||||||
wrong: loggedIn === false
|
v-if="mode === 'player'"
|
||||||
}"
|
@click="loginPlayer"
|
||||||
>
|
>
|
||||||
Ввод
|
Войти как игрок
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
v-else
|
||||||
|
@click="loginScreen"
|
||||||
|
>
|
||||||
|
Войти как большой экран
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
@click="switchMode"
|
||||||
|
class="secondary"
|
||||||
|
>
|
||||||
|
Я не {{ mode === 'player' ? 'игрок' : 'большой экран' }}!
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -30,39 +46,54 @@ import useStore from '../../store'
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
axios.defaults.withCredentials = true
|
axios.defaults.withCredentials = true
|
||||||
|
|
||||||
const question = process.env.VUE_APP_QUESTION
|
const question = import.meta.env.VITE_APP_QUESTION
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const store = useStore()
|
const store = useStore()
|
||||||
|
|
||||||
|
const mode = ref("player")
|
||||||
const answer = ref()
|
const answer = ref()
|
||||||
const loggedIn = ref()
|
|
||||||
const username = ref()
|
const username = ref()
|
||||||
|
|
||||||
async function login() {
|
function switchMode() {
|
||||||
|
mode.value = mode.value === 'player' ? 'screen' : 'player'
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loginPlayer() {
|
||||||
store.username = username.value
|
store.username = username.value
|
||||||
|
|
||||||
await axios
|
await axios
|
||||||
.post(process.env.VUE_APP_BACKEND + '/auth', {
|
.post(import.meta.env.VITE_APP_BACKEND + '/auth', {
|
||||||
|
"pass": answer.value,
|
||||||
|
"username": username.value,
|
||||||
|
})
|
||||||
|
|
||||||
|
router.push('/game')
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loginScreen() {
|
||||||
|
store.username = undefined
|
||||||
|
|
||||||
|
await axios
|
||||||
|
.post(import.meta.env.VITE_APP_BACKEND + '/auth', {
|
||||||
"pass": answer.value,
|
"pass": answer.value,
|
||||||
})
|
})
|
||||||
.then(response => {
|
|
||||||
loggedIn.value = response.status == "200"
|
router.push('/screen')
|
||||||
router.push('/')
|
|
||||||
})
|
|
||||||
|
|
||||||
axios
|
|
||||||
.post(process.env.VUE_APP_BACKEND + '/connect', {
|
|
||||||
'data': {
|
|
||||||
'username': username.value
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
div {
|
.auth {
|
||||||
|
display: flex;
|
||||||
|
gap: 16px;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.authCard {
|
||||||
background-color: #121212;
|
background-color: #121212;
|
||||||
|
color: white;
|
||||||
width: 400px;
|
width: 400px;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
border-radius: 18px;
|
border-radius: 18px;
|
||||||
@@ -74,7 +105,6 @@ input {
|
|||||||
font-size: 1em;
|
font-size: 1em;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding: 5px 8px;
|
padding: 5px 8px;
|
||||||
margin-bottom: 1em;
|
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
border: none;
|
border: none;
|
||||||
width: 20ch;
|
width: 20ch;
|
||||||
@@ -92,6 +122,11 @@ button {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
button.secondary {
|
||||||
|
background: #919191;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
@media only screen and (max-width: 520px) {
|
@media only screen and (max-width: 520px) {
|
||||||
div {
|
div {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
33
frontend/src/views/Screen/Answer.vue
Normal file
33
frontend/src/views/Screen/Answer.vue
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<template>
|
||||||
|
<div
|
||||||
|
class="answer"
|
||||||
|
:style="{
|
||||||
|
transform: `translate(${-50}%, ${-50}%) rotate(${position.rotation}deg)`
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
{{ props.answer }}
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { reactive } from 'vue'
|
||||||
|
|
||||||
|
const props = defineProps(["answer"])
|
||||||
|
const position = reactive({
|
||||||
|
rotation: Math.random() * 20 - 10,
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.answer {
|
||||||
|
position: fixed;
|
||||||
|
background: var(--clr-accent);
|
||||||
|
border-radius: 32px;
|
||||||
|
font-size: 30px;
|
||||||
|
padding: 32px;
|
||||||
|
border: 3px solid black;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,36 +1,214 @@
|
|||||||
<template>
|
<template>
|
||||||
<div v-if="card">
|
<div
|
||||||
|
v-if="card && !loading"
|
||||||
|
class="bigScreen"
|
||||||
|
>
|
||||||
<img
|
<img
|
||||||
|
class="image"
|
||||||
:src="card.image"
|
:src="card.image"
|
||||||
>
|
>
|
||||||
<div>
|
|
||||||
{{ users }}
|
<div class="answersState">
|
||||||
|
<div class="users -unanwsered">
|
||||||
|
<h2 class="usersTitle">Не ответили</h2>
|
||||||
|
<ul>
|
||||||
|
<li
|
||||||
|
class="user"
|
||||||
|
v-for="user in unansweredPlayers"
|
||||||
|
:key="user.name"
|
||||||
|
>
|
||||||
|
{{ user.name }}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="users">
|
||||||
|
<h2 class="usersTitle">Ответили</h2>
|
||||||
|
<ul>
|
||||||
|
<li
|
||||||
|
class="user"
|
||||||
|
v-for="user in answeredPlayers"
|
||||||
|
:key="user.name"
|
||||||
|
:class="{
|
||||||
|
'-wrong': correctAnswer && user.selected !== correctAnswer,
|
||||||
|
'-correct': correctAnswer && user.selected === correctAnswer
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
{{ user.name }}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<Answer
|
||||||
|
v-if="correctAnswer"
|
||||||
|
:answer="correctAnswer"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<square-loader
|
||||||
|
v-else
|
||||||
|
:color="'white'"
|
||||||
|
class="loader"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref, onMounted, computed } from 'vue'
|
||||||
import useServerEvents from '../../composables/useServerEvents';
|
import useServerEvents from '@/composables/useServerEvents'
|
||||||
|
import Answer from './Answer.vue'
|
||||||
|
|
||||||
const { addAnswerListener, addUserlistListener } = useServerEvents()
|
import SquareLoader from 'vue-spinner/src/SquareLoader.vue'
|
||||||
|
|
||||||
addAnswerListener(console.log)
|
const { addAnswerListener, addUserlistListener, addRevealListener } = useServerEvents()
|
||||||
|
|
||||||
const card = ref()
|
const card = ref()
|
||||||
const users = ref([])
|
const users = ref([])
|
||||||
|
const correctAnswer = ref()
|
||||||
|
const loading = ref()
|
||||||
|
|
||||||
async function getCard() {
|
async function getCard() {
|
||||||
const response = await axios.get(process.env.VUE_APP_BACKEND + '/card')
|
loading.value = true
|
||||||
|
const response = await axios.get(import.meta.env.VITE_APP_BACKEND + '/card')
|
||||||
|
loading.value = false
|
||||||
card.value = response.data
|
card.value = response.data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getPlayers() {
|
||||||
|
const response = await axios.get(import.meta.env.VITE_APP_BACKEND + '/players')
|
||||||
|
response.data.forEach((name) => {
|
||||||
|
users.value.push({
|
||||||
|
name,
|
||||||
|
selected: null
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const answeredPlayers = computed(() => {
|
||||||
|
return users.value.filter((user) => user.selected)
|
||||||
|
})
|
||||||
|
|
||||||
|
const unansweredPlayers = computed(() => {
|
||||||
|
return users.value.filter((user) => !user.selected)
|
||||||
|
})
|
||||||
|
|
||||||
|
addAnswerListener((data) => {
|
||||||
|
users.value = users.value.map((user) => {
|
||||||
|
if (user.name === data.username) {
|
||||||
|
return {
|
||||||
|
...user,
|
||||||
|
selected: data.selected
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return user
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
addUserlistListener((data) => {
|
addUserlistListener((data) => {
|
||||||
users.value = data
|
data.forEach((name) => {
|
||||||
|
users.value.push({
|
||||||
|
name,
|
||||||
|
selected: null
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
addRevealListener((data) => {
|
||||||
|
correctAnswer.value = data.correctAnswer
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
getCard()
|
||||||
|
correctAnswer.value = null
|
||||||
|
users.value = users.value.map((user) => ({
|
||||||
|
...user,
|
||||||
|
selected: null
|
||||||
|
}))
|
||||||
|
}, 5000)
|
||||||
})
|
})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
getCard()
|
getCard()
|
||||||
|
getPlayers()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.bigScreen {
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
height: 100vh;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-evenly;
|
||||||
|
gap: 64px;
|
||||||
|
align-items: center;
|
||||||
|
padding: 64px;
|
||||||
|
background: var(--clr-bg);
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
.image {
|
||||||
|
display: block;
|
||||||
|
max-width: 60%;
|
||||||
|
max-height: 100%;
|
||||||
|
object-fit: contain;
|
||||||
|
margin-top: auto;
|
||||||
|
margin-bottom: auto;
|
||||||
|
border: 3px solid black;
|
||||||
|
@include filled-shadow(16);
|
||||||
|
border-radius: 64px;
|
||||||
|
animation-name: rock;
|
||||||
|
animation-duration: 5s;
|
||||||
|
animation-direction: alternate;
|
||||||
|
animation-iteration-count: infinite;
|
||||||
|
animation-timing-function: ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes rock {
|
||||||
|
from {
|
||||||
|
transform: rotate(-2deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
to {
|
||||||
|
transform: rotate(2deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.users {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
height: 100%;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.users.-unanwsered {
|
||||||
|
border-right: 1px dashed black;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user.-correct {
|
||||||
|
color: green;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user.-wrong {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
.usersTitle {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.answersState {
|
||||||
|
display: flex;
|
||||||
|
flex-shrink: 0;
|
||||||
|
height: 300px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loader {
|
||||||
|
margin-top: 50%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
26
frontend/vite.config.js
Normal file
26
frontend/vite.config.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { defineConfig } from 'vite'
|
||||||
|
import vue from '@vitejs/plugin-vue'
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
|
// https://vitejs.dev/config/
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [vue()],
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
"@": path.resolve(__dirname, "./src"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
css: {
|
||||||
|
preprocessorOptions: {
|
||||||
|
scss: {
|
||||||
|
additionalData: `
|
||||||
|
@use 'sass:math';
|
||||||
|
@import '@/styles/_prepend.scss';
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
server: {
|
||||||
|
port: 8080
|
||||||
|
}
|
||||||
|
})
|
||||||
8802
frontend/yarn.lock
8802
frontend/yarn.lock
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user