Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions app/components/gameCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
* @param {string} [manifest.thumbnail] - Path to the thumbnail image.
* @param {object} [progress] - Optional progress data for the game.
* @param {number} [progress.highScore] - The player's high score for this game.
* @param {number} [progress.highestLevel] - The highest level reached (0-indexed;
* displayed as level + 1).
* @param {number} [progress.maxLevel] - The maximum level number reached.
* @param {number} [progress.maxPiggies] - The maximum number of piggies collected.
* @param {number} [progress.lowestDisplayTime] - The lowest display time achieved, in milliseconds.
* @returns {HTMLElement} An <article> element representing the game card.
*/
export function createGameCard(manifest, progress) {
Expand All @@ -36,18 +41,23 @@ export function createGameCard(manifest, progress) {
const description = document.createElement('p');
description.textContent = manifest.description || '';

// If this is Fast Piggie, show detailed stats if available
// Show saved stats when available.
let scoreElem = null;
if (manifest.id === 'fast-piggie' && progress) {
if (progress) {
scoreElem = document.createElement('p');
scoreElem.className = 'game-high-score';
const details = [];
if (typeof progress.highScore === 'number') details.push(`Top Score: ${progress.highScore}`);
if (typeof progress.highestLevel === 'number') details.push(`Max Level: ${progress.highestLevel + 1}`);
if (typeof progress.maxLevel === 'number') details.push(`Max Level: ${progress.maxLevel}`);
if (typeof progress.maxPiggies === 'number') details.push(`Max Piggies: ${progress.maxPiggies}`);
if (typeof progress.lowestDisplayTime === 'number') details.push(`Lowest Display Time: ${progress.lowestDisplayTime}ms`);
scoreElem.textContent = details.join(' | ');
scoreElem.setAttribute('aria-label', `Stats for ${manifest.name}: ${scoreElem.textContent}`);
if (details.length > 0) {
scoreElem.textContent = details.join(' | ');
scoreElem.setAttribute('aria-label', `Stats for ${manifest.name}: ${scoreElem.textContent}`);
} else {
scoreElem = null;
}
Comment on lines +44 to +60
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createGameCard() now renders additional progress details (e.g., highestLevel, maxPiggies, lowestDisplayTime), but the function JSDoc only documents progress.highScore. Please update the JSDoc for the progress parameter to include the additional supported fields so callers know what is displayed.

Copilot uses AI. Check for mistakes.
}

const button = document.createElement('button');
Expand Down
52 changes: 39 additions & 13 deletions app/components/gameCard.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
it('displays high score for Fast Piggie when provided', () => {
const manifest = {
id: 'fast-piggie',
name: 'Fast Piggie',
description: 'Test desc',
thumbnail: '/images/test.png',
};
const progress = { highScore: 42 };
const card = createGameCard(manifest, progress);
const scoreElem = card.querySelector('.game-high-score');
expect(scoreElem).not.toBeNull();
expect(scoreElem.textContent).toContain('42');
});
import { createGameCard } from './gameCard.js';

const validManifest = {
Expand Down Expand Up @@ -87,4 +74,43 @@ describe('createGameCard', () => {
const button = card.querySelector('button');
expect(button.getAttribute('aria-label')).toBeTruthy();
});

it('displays score stats for any game when provided', () => {
const manifest = {
id: 'orbit-sprite-memory',
name: 'Orbit Sprite Memory',
description: 'Test desc',
thumbnail: '/images/test.png',
};
const progress = { highScore: 42, highestLevel: 3 };
const card = createGameCard(manifest, progress);
const scoreElem = card.querySelector('.game-high-score');

expect(scoreElem).not.toBeNull();
expect(scoreElem.textContent).toContain('Top Score: 42');
expect(scoreElem.textContent).toContain('Max Level: 4');
});

it('displays detailed fast-piggie stats when provided', () => {
const manifest = {
id: 'fast-piggie',
name: 'Fast Piggie',
description: 'Test desc',
thumbnail: '/images/test.png',
};
const progress = {
highScore: 11,
maxLevel: 5,
maxPiggies: 9,
lowestDisplayTime: 550,
};
const card = createGameCard(manifest, progress);
const scoreElem = card.querySelector('.game-high-score');

expect(scoreElem).not.toBeNull();
expect(scoreElem.textContent).toContain('Top Score: 11');
expect(scoreElem.textContent).toContain('Max Level: 5');
expect(scoreElem.textContent).toContain('Max Piggies: 9');
expect(scoreElem.textContent).toContain('Lowest Display Time: 550ms');
});
});
Loading
Loading