managarten/games/mana-games/apps/web/src/scripts/stats-integration-template.js
Wuesteon 0ebfde0851 fix(ci): build shared packages before tests and fix formatting
- Add build:packages step to all test.yml jobs (fixes @manacore/shared-nestjs-auth not found)
- Handle missing coverage artifacts gracefully in test-coverage.yml
- Update .prettierignore to exclude apps-archived/ and problematic files
- Format all source files to pass CI checks

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-01 23:15:00 +01:00

77 lines
1.3 KiB
JavaScript

// Template für Stats-Integration in Spiele
// Dieses Template zeigt, wie man die Stats-Integration in ein Spiel einbaut
// 1. Game ID definieren (muss mit dem Slug in games.ts übereinstimmen)
const GAME_ID = 'dein-spiel-slug';
// 2. Beim Spielstart senden
window.addEventListener('load', () => {
window.parent.postMessage(
{
type: 'GAME_LOADED',
gameId: GAME_ID,
},
'*'
);
});
// 3. Bei Score-Updates senden
function updateScore(newScore) {
score = newScore;
// UI Update...
window.parent.postMessage(
{
type: 'GAME_EVENT',
gameId: GAME_ID,
event: 'SCORE_UPDATE',
data: { score: score },
},
'*'
);
}
// 4. Bei Game Over senden
function gameOver() {
// Game Over Logik...
window.parent.postMessage(
{
type: 'GAME_EVENT',
gameId: GAME_ID,
event: 'GAME_OVER',
data: { score: finalScore },
},
'*'
);
// Achievement Beispiele
if (score >= 100) {
window.parent.postMessage(
{
type: 'GAME_EVENT',
gameId: GAME_ID,
event: 'ACHIEVEMENT_UNLOCKED',
data: {
achievement: {
id: 'first-100',
name: 'Erste 100',
description: '100 Punkte erreicht!',
},
},
},
'*'
);
}
}
// 5. Optional: Bei Spielende/Verlassen
window.addEventListener('beforeunload', () => {
window.parent.postMessage(
{
type: 'GAME_ENDED',
gameId: GAME_ID,
},
'*'
);
});