zenno/race: common component for calculator outputs
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte';
|
||||
import type { ClassValue } from 'svelte/elements';
|
||||
|
||||
interface Props {
|
||||
title: Snippet | string;
|
||||
children: Snippet;
|
||||
additional?: Snippet;
|
||||
class?: ClassValue | null;
|
||||
}
|
||||
|
||||
let { title, children, additional, class: className }: Props = $props();
|
||||
|
||||
const cl = $derived([
|
||||
'm-2 flex flex-col rounded-md border p-2 text-center shadow-sm transition-shadow hover:shadow-md',
|
||||
className,
|
||||
]);
|
||||
</script>
|
||||
|
||||
<div class={cl}>
|
||||
<span class="block">
|
||||
{#if typeof title === 'string'}
|
||||
{title}
|
||||
{:else}
|
||||
{@render title()}
|
||||
{/if}
|
||||
</span>
|
||||
<span class="block text-xl">
|
||||
{@render children()}
|
||||
</span>
|
||||
{@render additional?.()}
|
||||
</div>
|
||||
@@ -3,6 +3,7 @@
|
||||
import * as race from '$lib/race';
|
||||
import * as accel from '$lib/racelib/accel';
|
||||
import type { Attachment } from 'svelte/attachments';
|
||||
import CalcInfo from '../CalcInfo.svelte';
|
||||
|
||||
let rawPower = $state(1200);
|
||||
let rawGuts = $state(1200);
|
||||
@@ -284,14 +285,13 @@
|
||||
</form>
|
||||
|
||||
{#snippet info(name: string, unit: string, val: number, val2?: number)}
|
||||
<div class="m-2 max-w-72 flex-1 flex-col rounded-md border p-2 text-center shadow-sm transition-shadow hover:shadow-md">
|
||||
<span class="block">{name}</span>
|
||||
<CalcInfo title={name} class="max-w-72 flex-1">
|
||||
{#if val2 == null}
|
||||
<span class="block text-xl">{val.toFixed(3)} {unit}</span>
|
||||
{:else}
|
||||
<span class="block text-xl">{val.toFixed(3)} – {val2.toFixed(3)} {unit}</span>
|
||||
{/if}
|
||||
</div>
|
||||
</CalcInfo>
|
||||
{/snippet}
|
||||
|
||||
<div class="mx-auto flex w-full flex-col place-items-center md:flex-row md:justify-center">
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { HORSE_LENGTH, speedGain } from '$lib/race';
|
||||
import type { Snippet } from 'svelte';
|
||||
import CalcInfo from '../CalcInfo.svelte';
|
||||
|
||||
interface Props {
|
||||
children: Snippet;
|
||||
@@ -21,13 +22,12 @@
|
||||
const text = $derived(gain.map(fmtp).join(' – '));
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="m-2 flex h-full w-full max-w-80 flex-1 flex-col rounded-md border p-2 text-center shadow-sm transition-shadow hover:shadow-md"
|
||||
>
|
||||
<div class="block">{@render children()}</div>
|
||||
<span class="block text-xl">{text} L</span>
|
||||
<CalcInfo title={children} class="max-w-80 flex-1">
|
||||
{text} L
|
||||
{#snippet additional()}
|
||||
<div class="flex flex-row">
|
||||
<span class="flex-1 text-xs">{fmtp(speed)} m/s</span>
|
||||
<span class="flex-1 text-xs">{dur.toFixed(3)} s</span>
|
||||
</div>
|
||||
</div>
|
||||
{/snippet}
|
||||
</CalcInfo>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import type { ComputedSeries } from '$lib/chart';
|
||||
import { AptitudeLevel, inverseSpurtSpeed, RunningStyle, spurtSpeed, Stat } from '$lib/race';
|
||||
import StatChart from '$lib/StatChart.svelte';
|
||||
import CalcInfo from '../CalcInfo.svelte';
|
||||
|
||||
const aptsList = Object.entries(AptitudeLevel).filter(([, val]) => typeof val === 'number');
|
||||
const stylesList = [
|
||||
@@ -93,9 +94,7 @@
|
||||
<input type="checkbox" id="isCareer" role="switch" bind:checked={isCareer} class="min-h-6 min-w-6 align-middle" />
|
||||
</div>
|
||||
</div>
|
||||
<span class="mt-8 block w-full text-center text-lg">
|
||||
Target spurt speed: {speed.toFixed(3)} m/s
|
||||
</span>
|
||||
<CalcInfo title="Target Spurt Speed" class="mx-auto mt-8 max-w-md">{speed.toFixed(3)} m/s</CalcInfo>
|
||||
{#each [[AptitudeLevel.A, aProf] as const, [AptitudeLevel.S, sProf] as const] as [level, inv] (level)}
|
||||
<div class="mx-auto max-w-3xl">
|
||||
<span class="mt-8 block w-full">
|
||||
@@ -103,14 +102,7 @@
|
||||
</span>
|
||||
<div class="flex flex-col md:flex-row">
|
||||
{#each stylesList as [styleName, s] (s)}
|
||||
<div
|
||||
class={['m-2 flex-1 rounded-md border shadow-sm transition-shadow hover:shadow-md', s === style ? 'border-2' : null]}
|
||||
>
|
||||
<div class="h-full w-full flex-col text-center">
|
||||
<span class="block text-lg">{styleName}</span>
|
||||
<span class="block text-2xl">{inv[s]}</span>
|
||||
</div>
|
||||
</div>
|
||||
<CalcInfo title={styleName} class={['flex-1', { 'border-2': s === style }]}>{inv[s]}</CalcInfo>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
@@ -127,12 +119,7 @@
|
||||
</span>
|
||||
<div class="flex flex-col md:flex-row">
|
||||
{#each skillProf as [v, inv] (v)}
|
||||
<div class="m-2 flex-1 rounded-md border shadow-sm transition-shadow hover:shadow-md">
|
||||
<div class="h-full w-full flex-col text-center">
|
||||
<span class="block text-lg">+{v.toFixed(2)}</span>
|
||||
<span class="block text-2xl">{inv}</span>
|
||||
</div>
|
||||
</div>
|
||||
<CalcInfo title={`+${v.toFixed(2)}`} class="flex-1">{inv}</CalcInfo>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user