Skip to content

Commit

Permalink
feat: choose a game randomly (#1000)
Browse files Browse the repository at this point in the history
* chore: change menu entries order

* feat: random game feature

Still fine tuning to do

* Chore: fine tune player css

* chore: typo
  • Loading branch information
jy95 authored Nov 14, 2024
1 parent 0df1502 commit e56b9bd
Show file tree
Hide file tree
Showing 11 changed files with 654 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/refreshJSONFiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ jobs:
- planning.json
- stats.json
- past-planning.json
- dlcs.json
- dlcs.json
- identifiers.json
draft: false
20 changes: 19 additions & 1 deletion generateJsonFiles.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const FILES = {
"STATS": "src/app/api/stats/stats.json",
"PAST_GAMES": "src/app/api/planning/past-planning.json",
"DLCS": "src/app/api/dlcs/dlcs.json",
"IDENTIFIERS": "src/app/api/random/identifiers.json"
}

const db = new Database(databasePath, {
Expand Down Expand Up @@ -241,6 +242,22 @@ async function extractAndSaveDLCS(db) {
console.log(`${FILES.DLCS} successfully written`);
}

/**
* Extracts game identifiers from the database and saves them to a file.
* @param {import('better-sqlite3').Database} db - The database instance
*/
async function extractAndSaveRandomList(db) {
// We can pick up also DLC to have a complete list
const extractGamesList = db.prepare("SELECT videoId, playlistId FROM games_in_present");
const games = extractGamesList.all();
await writeFile(
FILES.IDENTIFIERS,
stringifyJSON(games),
"utf-8"
);
console.log(`${FILES.IDENTIFIERS} successfully written`);
}

// Operations time
await extractAndSavePlatforms(db)
await extractAndSaveGenres(db)
Expand All @@ -251,4 +268,5 @@ await extractAndSaveSeries(db)
await extractAndSaveTests(db)
await extractAndSaveStats(db)
await extractAndSavePastGames(db);
await extractAndSaveDLCS(db);
await extractAndSaveDLCS(db);
await extractAndSaveRandomList(db);
1 change: 1 addition & 0 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
}
},
"gamesLibrary": {
"randomButtonLabel": "Click to unveil a new game !",
"sortButtonLabel": "Sorts",
"tabs": {
"grid": "Games",
Expand Down
1 change: 1 addition & 0 deletions messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
}
},
"gamesLibrary": {
"randomButtonLabel": "Cliquez pour découvrir un nouveau jeu !",
"sortButtonLabel": "Tris",
"tabs": {
"grid": "Jeux",
Expand Down
6 changes: 5 additions & 1 deletion src/app/[locale]/playlist/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import { useParams } from 'next/navigation'
import YTPlayer from "@/components/YTPlayer/Player";
import RandomButton from '@/components/GamesView/RandomButton';

export default function PlaylistPage() {

const { id } = useParams();
const identifier = id as string;

return (
<YTPlayer type="PLAYLIST" identifier={identifier}/>
<>
<YTPlayer type="PLAYLIST" identifier={identifier}/>
<RandomButton />
</>
)
}
6 changes: 5 additions & 1 deletion src/app/[locale]/video/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import { useParams } from 'next/navigation'
import YTPlayer from "@/components/YTPlayer/Player";
import RandomButton from '@/components/GamesView/RandomButton';

export default function PlaylistPage() {

const { id } = useParams();
const identifier = id as string;

return (
<YTPlayer type="VIDEO" identifier={identifier}/>
<>
<YTPlayer type="VIDEO" identifier={identifier}/>
<RandomButton />
</>
)
}
Loading

0 comments on commit e56b9bd

Please sign in to comment.