2021-07-24 17:16:15 -04:00
|
|
|
<script lang="ts">
|
|
|
|
|
import * as _ from "lodash";
|
|
|
|
|
import { format as formatDate } from "date-fns";
|
2021-07-25 01:52:33 -04:00
|
|
|
import { Button, Icon } from "sveltestrap";
|
2021-07-24 17:16:15 -04:00
|
|
|
|
2021-07-25 01:52:33 -04:00
|
|
|
import { kingdoms } from "./data";
|
|
|
|
|
|
|
|
|
|
export let rollResults: { value: string; icon: string; timestamp: string }[] = [];
|
2021-07-24 17:16:15 -04:00
|
|
|
let kingdom = "arpad";
|
|
|
|
|
let categories: string[];
|
|
|
|
|
|
2021-07-25 01:52:33 -04:00
|
|
|
function addResult(value: string, category: string) {
|
|
|
|
|
let icon = { male: "person-fill", female: "person", steading: "house-door-fill", mount: "bicycle" }[category] || "";
|
|
|
|
|
rollResults = [{ value, icon, timestamp: formatDate(new Date(), "P kk:mm:ss") }, ...rollResults];
|
2021-07-24 17:16:15 -04:00
|
|
|
}
|
|
|
|
|
|
2021-07-25 01:52:33 -04:00
|
|
|
function rollName(category: string) {
|
|
|
|
|
let values = kingdoms[kingdom][category];
|
|
|
|
|
|
|
|
|
|
addResult(_.sample(values), category);
|
2021-07-24 17:16:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$: categories = kingdoms[kingdom].categories;
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<main>
|
2021-07-25 01:52:33 -04:00
|
|
|
<h2>
|
2021-07-24 17:16:15 -04:00
|
|
|
<select bind:value={kingdom}>
|
|
|
|
|
{#each Object.keys(kingdoms) as k}
|
|
|
|
|
<option value={k}>{kingdoms[k].description}</option>
|
|
|
|
|
{/each}
|
|
|
|
|
</select>
|
2021-07-25 01:52:33 -04:00
|
|
|
</h2>
|
|
|
|
|
<h3>{kingdoms[kingdom].subtitle}</h3>
|
|
|
|
|
|
|
|
|
|
{#each categories as category}
|
|
|
|
|
<span class="btn">
|
|
|
|
|
<Button color="primary" on:click={() => rollName(category)}>Roll {_.capitalize(category)}</Button>
|
|
|
|
|
</span>
|
|
|
|
|
{/each}
|
2021-07-24 17:16:15 -04:00
|
|
|
|
|
|
|
|
{#each rollResults as result}
|
2021-07-25 01:52:33 -04:00
|
|
|
<h4>{result.timestamp}: <Icon name={result.icon} /> {result.value}</h4>
|
2021-07-24 17:16:15 -04:00
|
|
|
{/each}
|
|
|
|
|
</main>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
</style>
|