Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianjnuwu committed Jan 10, 2025
1 parent eed2aeb commit e34263e
Show file tree
Hide file tree
Showing 14 changed files with 302 additions and 244 deletions.
3 changes: 0 additions & 3 deletions socket/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
"type": "module",
"license": "Apache-2.0",
"author": "Sebastian Jn <[email protected]>",
"imports": {
"#functions": "./functions/functions.js"
},
"dependencies": {
"socket.io": "^4.8.1"
},
Expand Down
11 changes: 0 additions & 11 deletions socket/src/functions/functions.js

This file was deleted.

13 changes: 11 additions & 2 deletions socket/src/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { Server } from "socket.io";
import { $generate_code, $generate_uuid } from "#functions";

const io = new Server();
const ROOMS = {};
let roomIdCounter = 0;

function $generate_uuid() {
roomIdCounter += 1;
return roomIdCounter;
}

// code
function $generate_code() {
return Math.random().toString(36).substring(2, 8).toUpperCase();
}

/**
* Event listener for a new connection from a client.
Expand Down
1 change: 1 addition & 0 deletions typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ check-filename = true
[files]
extend-exclude = [
"www/src/js/modules",
"www/src/locales/lang",
"node_modules",
"android",
"socket"
Expand Down
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "dotenv/config";

export default defineConfig({
root: "./www",
target: 'esnext',
build: {
outDir: "../build",
minify: false,
Expand Down
376 changes: 203 additions & 173 deletions www/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion www/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import "@plugin/admob.ts";
import "@ts/main.ts";
import "@ts/game.ts";
import "@plugin/push-notifications.ts";
import "bootstrap/dist/css/bootstrap.min.css";
import "bootstrap/dist/css/bootstrap.min.css";
16 changes: 9 additions & 7 deletions www/src/locales/lang/en-US.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// @lang/en-US
export const translation = {
const translation = {
general: {
cookies: "Cookies",
seconds: "Seconds",
timeLabel: "Time:",
start: "GO!",
message_now: "Now"
message_now: "Now",
},
splashScreen: {
splashClick: "Click...",
Expand All @@ -31,16 +31,18 @@ export const translation = {
roomCodeLabel: "Room Code",
gameTimeLabel: "Game Time (in seconds)",
},
room: {
room: {
no_room_player: "It seems you haven't set your nickname!",
no_room_time: "It seems you haven't set the room time!",
time_check: "The room time must be greater than 10 seconds and less than or equal to 10 minutes!",
time_check:
"The room time must be greater than 10 seconds and less than or equal to 10 minutes!",
no_room_code: "It seems you haven't added the room code!",
no_connected: "It seems you've been disconnected from the Cookie game!"
},

no_connected: "It seems you've been disconnected from the Cookie game!",
},
modal: {
cancel: "Cancel",
confirm: "Confirm",
},
};

export default translation;
15 changes: 9 additions & 6 deletions www/src/locales/lang/es-ES.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// @lang/es-ES
export const translation = {
const translation = {
general: {
cookies: "Galletas",
seconds: "Segundos",
timeLabel: "Tiempo:",
start: "¡IR!",
message_now: "Ahora"
message_now: "Ahora",
},
splashScreen: {
splashClick: "Haz clic...",
Expand All @@ -31,16 +31,19 @@ export const translation = {
roomCodeLabel: "Código de la Sala",
gameTimeLabel: "Tiempo de Juego (en segundos)",
},
room: {
room: {
no_room_player: "¡Parece que no has definido tu apodo!",
no_room_time: "¡Parece que no has definido el tiempo de la sala!",
time_check: "¡El tiempo de la sala debe ser mayor a 10 segundos y menor o igual a 10 minutos!",
time_check:
"¡El tiempo de la sala debe ser mayor a 10 segundos y menor o igual a 10 minutos!",
no_room_code: "¡Parece que no has añadido el código de la sala!",
no_connected: "¡Parece que te desconectaste del juego Cookie!"
},
no_connected: "¡Parece que te desconectaste del juego Cookie!",
},

modal: {
cancel: "Cancelar",
confirm: "Confirmar",
},
};

export default translation;
13 changes: 8 additions & 5 deletions www/src/locales/lang/pt-BR.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// @lang/pt-BR
export const translation = {
const translation = {
general: {
cookies: "Biscoitos",
seconds: "Segundos",
timeLabel: "Tempo:",
start: "JA!",
message_now: "Agora"
message_now: "Agora",
},
splashScreen: {
splashClick: "Clique...",
Expand Down Expand Up @@ -34,12 +34,15 @@ export const translation = {
room: {
no_room_player: "Parece que você não definiu seu nickname!",
no_room_time: "Parece que você não definiu o tempo da sala!",
time_check: "O tempo da sala deve ser maior que 10 segundos e menor ou igual a 10 minutos!",
time_check:
"O tempo da sala deve ser maior que 10 segundos e menor ou igual a 10 minutos!",
no_room_code: "Parece que você não adicionou o código da sala",
no_connected: "Parece que você foi desconectado do jogo Cookie!"
},
no_connected: "Parece que você foi desconectado do jogo Cookie!",
},
modal: {
cancel: "Cancelar",
confirm: "Confirmar",
},
};

export default translation;
46 changes: 30 additions & 16 deletions www/src/locales/main.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
import i18next, { type TFunction } from "i18next";
import { resources } from "@language/resources.ts";
import $ from "jquery";

i18next.init({
lng: "pt-BR",
debug: false,
preload: true,
resources,
interpolation: {
escapeValue: false,
useRawValueToEscape: true,
},
load: "all",
});
import pt from "@lang/pt-BR.ts";
import en from "@lang/en-US.ts";
import es from "@lang/es-ES.ts";

i18next.init({
lng: "pt-BR",
debug: false,
preload: true,
resources: {
"en-US": {
translation: en,
},
"pt-BR": {
translation: pt,
},
"es-ES": {
translation: es,
},
},
interpolation: {
escapeValue: false,
useRawValueToEscape: true,
},
load: "all",
});


let lang: TFunction | undefined;

switch (window.navigator.language) {
switch ("en-US" || window.navigator.language) {
case "pt-BR":
lang = i18next.getFixedT("pt-BR");
break;
Expand All @@ -30,9 +44,9 @@ switch (window.navigator.language) {
lang = i18next.getFixedT("en-US");
}

$('[i18next-id]').each(function() {
const id = $(this).attr('i18next-id');
$("[i18next-id]").each(function () {
const id = $(this).attr("i18next-id");
$(this).text(lang(id));
});

export { lang };
export { lang };
5 changes: 0 additions & 5 deletions www/src/locales/resources.ts

This file was deleted.

41 changes: 28 additions & 13 deletions www/src/ts/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@ function showMessage(text: string): void {
<div class="toast-header">
<img style="width: 10%;" src="https://i.imgur.com/EOzKknx.webp" class="rounded me-2">
<strong class="me-auto">Cookie</strong>
<small><i18next i18next-id="general.message_now">${lang('general.message_now')}</i18next></small>
<small><i18next i18next-id="general.message_now">${lang("general.message_now")}</i18next></small>
<button type="button" style="box-shadow: none; outline: none;" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">${text}</div></div>`);
}

// Create socket connection
const socket: Socket = io(import.meta.env.VITE_SOCKET_URL || 'https://socket-hj1h.onrender.com', {
transports: ["websocket", "polling"],
});
const socket: Socket = io(
import.meta.env.VITE_SOCKET_URL || "https://socket-hj1h.onrender.com",
{
transports: ["websocket", "polling"],
},
);

// Initialize cookies count and handle local storage
let cookies: number = Number(localStorage.getItem("cookie")) || 0;
Expand Down Expand Up @@ -128,29 +131,39 @@ $("#form_button").on("click", () => {
const roomTime = $("#room_time").val() as string | null;

if (!roomPlayer) {
return showMessage(`<i class="fas fa-exclamation-circle"></i> ${lang('room.no_room_player')}`);
return showMessage(
`<i class="fas fa-exclamation-circle"></i> ${lang("room.no_room_player")}`,
);
}

// Verificação do tempo só se a opção for "create"
if (option === "create") {
if (!roomTime) {
return showMessage(`<i class="fas fa-exclamation-circle"></i> ${lang('room.no_room_time')}`);
return showMessage(
`<i class="fas fa-exclamation-circle"></i> ${lang("room.no_room_time")}`,
);
}

const timeCheck = roomTime ? Number.parseInt(roomTime, 10) : NaN;
const timeCheck = roomTime ? Number.parseInt(roomTime, 10) : Number.NaN;

if (Number.isNaN(timeCheck) || timeCheck <= 10 || timeCheck > 600) {
return showMessage(`<i class="fas fa-exclamation-circle"></i> ${lang('room.time_check')}`);
return showMessage(
`<i class="fas fa-exclamation-circle"></i> ${lang("room.time_check")}`,
);
}
}

// Verificação do código da sala só se a opção for "join"
if (option === "join" && !roomCode) {
return showMessage(`<i class="fas fa-exclamation-circle"></i> ${lang('room.no_room_code')}`);
return showMessage(
`<i class="fas fa-exclamation-circle"></i> ${lang("room.no_room_code")}`,
);
}

if (!socket.connected) {
return showMessage(`<i class="fas fa-exclamation-circle"></i> ${lang('room.no_connected')}`);
return showMessage(
`<i class="fas fa-exclamation-circle"></i> ${lang("room.no_connected")}`,
);
}

$room_modal.hide();
Expand Down Expand Up @@ -226,7 +239,7 @@ socket.on("count_down", ({ countdown }: { countdown: number }) => {
if (countdown > 0) {
$("#countdown").text(countdown);
} else {
$("#countdown").text(lang('general.start'));
$("#countdown").text(lang("general.start"));

setTimeout(() => {
$("#countdown-container").hide();
Expand Down Expand Up @@ -259,7 +272,9 @@ socket.on("game_end", ({ ranking }: { ranking: any[] }) => {

// Show trophy icon before ranking
$("#countdown-container").show();
$("#countdown").html('<i class="fas fa-trophy" style="color: #f4a261; font-size: 10rem; text-align: center;"></i>');
$("#countdown").html(
'<i class="fas fa-trophy" style="color: #f4a261; font-size: 10rem; text-align: center;"></i>',
);

setTimeout(() => {
$("#countdown-container").hide();
Expand All @@ -272,7 +287,7 @@ socket.on("game_end", ({ ranking }: { ranking: any[] }) => {
</li>
`);
});
}, 1200);
}, 1200);
});

// Game exit functionality
Expand Down
3 changes: 1 addition & 2 deletions www/src/ts/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import $ from "jquery";

/**
* This function runs when the document is ready.
* It initializes interactions with the splash screen and handles the game room code visibility logic.
*/
$(() => {

/**
* Event handler for clicking on the splash screen.
* Hides the splash screen and shows the start screen after a 1-second delay.
Expand Down

0 comments on commit e34263e

Please sign in to comment.