Mobile version improvements

- Most of the game should work on mobile now
- It's not yet perfect and needs finishes/improvements
This commit is contained in:
MaciejkaG 2024-03-31 15:08:31 +02:00
parent e7b0470653
commit c0ae701507
4 changed files with 57 additions and 18 deletions

View File

@ -283,24 +283,44 @@ app.post('/api/nickname', (req, res) => {
app.get('/game', async (req, res) => { app.get('/game', async (req, res) => {
const locale = new Lang(req.acceptsLanguages());
const game = await redis.json.get(`game:${req.query.id}`); const game = await redis.json.get(`game:${req.query.id}`);
if (req.session.nickname == null) { if (req.session.nickname == null) {
res.redirect('/setup'); res.redirect('/setup');
} else if (req.query.id == null || game == null || game.state == 'expired' || req.session.activeGame == null) { } else if (req.query.id == null || game == null || game.state == 'expired' || req.session.activeGame == null) {
res.render("error", { auth.getLanguage(req.session.userId).then(language => {
helpers: { var locale;
error: "Nie znaleziono wskazanej gry", if (language) {
fallback: "/", locale = new Lang([language]);
t: (key) => { return locale.t(key) } req.session.langs = [language];
} else {
locale = new Lang(req.acceptsLanguages());
req.session.langs = req.acceptsLanguages();
} }
res.render("error", {
helpers: {
error: "Nie znaleziono wskazanej gry",
fallback: "/",
t: (key) => { return locale.t(key) }
}
});
}); });
} else { } else {
res.render('board', { auth.getLanguage(req.session.userId).then(language => {
helpers: { var locale;
t: (key) => { return locale.t(key) } if (language) {
locale = new Lang([language]);
req.session.langs = [language];
} else {
locale = new Lang(req.acceptsLanguages());
req.session.langs = req.acceptsLanguages();
} }
res.render('board', {
helpers: {
t: (key) => { return locale.t(key) }
}
});
}); });
} }
}); });

View File

@ -36,5 +36,9 @@
body { body {
overflow-x: hidden; overflow-x: hidden;
} }
.secondary {
transform: scale(0);
}
} }

View File

@ -45,6 +45,8 @@ $('#board .field').on('click', function () {
}); });
function manualPlace(posX, posY) { function manualPlace(posX, posY) {
hoveredShip = null;
refreshBoardView();
socket.emit("place ship", selectedShip, posX, posY, shipRotation); socket.emit("place ship", selectedShip, posX, posY, shipRotation);
} }
@ -57,6 +59,10 @@ $('#secondaryBoard .field').on('click', function () {
} }
}); });
function manualShoot(posX, posY) {
socket.emit("shoot", posX, posY);
}
$('.field').on('contextmenu', function () { $('.field').on('contextmenu', function () {
if ($(this).hasClass('active') && new Date().getTime() / 1000 - lastTimeClick > 0.3) { if ($(this).hasClass('active') && new Date().getTime() / 1000 - lastTimeClick > 0.3) {
let originPos = occupiedFields.find((elem) => elem.pos[0] == $(this).data('pos-x') && elem.pos[1] == $(this).data('pos-y')).origin; let originPos = occupiedFields.find((elem) => elem.pos[0] == $(this).data('pos-x') && elem.pos[1] == $(this).data('pos-y')).origin;

View File

@ -136,12 +136,16 @@ export class MailAuth {
authCode = authCode.slice(0, 4) + " " + authCode.slice(4); authCode = authCode.slice(0, 4) + " " + authCode.slice(4);
const lookup = geoip.lookup(ip);
const lookupData = `User-Agent: ${agent}\nAdres IP: ${ip}\nKraj: ${lookup.country}\nRegion: ${lookup.region}\nMiasto: ${lookup.city}`;
try { try {
await this.mail.sendMail({ await this.mail.sendMail({
from: this.mailFrom, from: this.mailFrom,
to: email, to: email,
subject: `${authCode} to twój kod autoryzacji do Statków`, subject: `${authCode} to twój kod autoryzacji do Statków`,
html: html.replace("{{ CODE }}", authCode), html: html.replace("{{ CODE }}", authCode).replace("{{ LOOKUP }}", lookupData),
}); });
} catch (e) { } catch (e) {
reject(e); reject(e);
@ -168,14 +172,19 @@ export class MailAuth {
const lookup = geoip.lookup(ip); const lookup = geoip.lookup(ip);
const lookupData = `User-Agent: ${agent}\nAdres IP: ${ip}\nKraj: ${lookup.country}\nRegion: ${lookup.region}\nMiasto: ${lookup.city}` const lookupData = `User-Agent: ${agent}\nAdres IP: ${ip}\nKraj: ${lookup.country}\nRegion: ${lookup.region}\nMiasto: ${lookup.city}`;
await this.mail.sendMail({ try {
from: this.mailFrom, await this.mail.sendMail({
to: email, from: this.mailFrom,
subject: `${authCode} to twój kod logowania do Statków`, to: email,
html: html.replace("{{ NICKNAME }}", row.nickname).replace("{{ CODE }}", authCode).replace("{{ LOOKUP }}", lookupData), subject: `${authCode} to twój kod logowania do Statków`,
}); html: html.replace("{{ NICKNAME }}", row.nickname).replace("{{ CODE }}", authCode).replace("{{ LOOKUP }}", lookupData),
});
} catch (e) {
reject(e);
}
resolve({ status: 1, uid: row.user_id }); resolve({ status: 1, uid: row.user_id });
}); });