-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
20593a5
commit 8983ff0
Showing
4 changed files
with
147 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
import Layout from '../../layouts/Layout.astro' | ||
import {getRuns, getRun} from '../../../game/backend.js' | ||
import {getEnemiesStats} from '../../components/dungeon-stats.js' | ||
import '../../styles/typography.css' | ||
export const getStaticPaths = (async () => { | ||
const runs = await getRuns() | ||
return runs.map(run => { | ||
return { | ||
params: {id: run.id} | ||
} | ||
}) | ||
}) | ||
const {id} = Astro.params | ||
const run = await getRun(id) | ||
const state = run.gameState | ||
const date = new Intl.DateTimeFormat('en', { | ||
dateStyle: 'long', | ||
// timeStyle: 'short', | ||
hour12: false, | ||
}).format(new Date(state.createdAt)) | ||
const ms = state.endedAt - state.createdAt | ||
const hours = Math.floor(ms / (1000 * 60 * 60)) | ||
const minutes = Math.floor((ms % (1000 * 60 * 60)) / (1000 * 60)) | ||
const seconds = Math.floor((ms / 1000) % 60) | ||
const duration = `${hours > 0 ? hours + 'h ' : ''}${minutes}m ${seconds}s` | ||
// Not all runs have this data in the backend. | ||
let extraStats = false | ||
if (state.dungeon.graph) { | ||
extraStats = getEnemiesStats(state.dungeon) | ||
console.log(extraStats) | ||
} | ||
--- | ||
|
||
<Layout title="Statistics & Highscores"> | ||
<article class="Container"> | ||
<p><a class="Button" href="/stats">← Back to all runs</a></p> | ||
<h1>Slay the Web run no. {run.id}</h1> | ||
<div class="Box Box--text Box--full"> | ||
<p><em>{run.player}</em> made it to floor {state.dungeon.y} and {state.won ? 'won' : 'lost'} in {duration} on {date} with {state.player.currentHealth}/{state.player.maxHealth} health.</p> | ||
{extraStats && <p>You encountered {extraStats.encountered} monsters. And killed {extraStats.killed} of them.</p>} | ||
<p>Final deck had {state.deck.length} cards:</p> | ||
<ul> | ||
{state.deck.map(card => <li>{card}</li>)} | ||
</ul> | ||
|
||
</div> | ||
</article> | ||
</Layout> | ||
|