zenno/race: common component for calculator outputs

This commit is contained in:
2026-07-18 16:38:07 -04:00
parent cb54bbe414
commit b22c8307fd
4 changed files with 49 additions and 30 deletions
+32
View File
@@ -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 -3
View File
@@ -3,6 +3,7 @@
import * as race from '$lib/race'; import * as race from '$lib/race';
import * as accel from '$lib/racelib/accel'; import * as accel from '$lib/racelib/accel';
import type { Attachment } from 'svelte/attachments'; import type { Attachment } from 'svelte/attachments';
import CalcInfo from '../CalcInfo.svelte';
let rawPower = $state(1200); let rawPower = $state(1200);
let rawGuts = $state(1200); let rawGuts = $state(1200);
@@ -284,14 +285,13 @@
</form> </form>
{#snippet info(name: string, unit: string, val: number, val2?: number)} {#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"> <CalcInfo title={name} class="max-w-72 flex-1">
<span class="block">{name}</span>
{#if val2 == null} {#if val2 == null}
<span class="block text-xl">{val.toFixed(3)} {unit}</span> <span class="block text-xl">{val.toFixed(3)} {unit}</span>
{:else} {:else}
<span class="block text-xl">{val.toFixed(3)} &ndash; {val2.toFixed(3)} {unit}</span> <span class="block text-xl">{val.toFixed(3)} &ndash; {val2.toFixed(3)} {unit}</span>
{/if} {/if}
</div> </CalcInfo>
{/snippet} {/snippet}
<div class="mx-auto flex w-full flex-col place-items-center md:flex-row md:justify-center"> <div class="mx-auto flex w-full flex-col place-items-center md:flex-row md:justify-center">
+10 -10
View File
@@ -1,6 +1,7 @@
<script lang="ts"> <script lang="ts">
import { HORSE_LENGTH, speedGain } from '$lib/race'; import { HORSE_LENGTH, speedGain } from '$lib/race';
import type { Snippet } from 'svelte'; import type { Snippet } from 'svelte';
import CalcInfo from '../CalcInfo.svelte';
interface Props { interface Props {
children: Snippet; children: Snippet;
@@ -21,13 +22,12 @@
const text = $derived(gain.map(fmtp).join(' ')); const text = $derived(gain.map(fmtp).join(' '));
</script> </script>
<div <CalcInfo title={children} class="max-w-80 flex-1">
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" {text} L
> {#snippet additional()}
<div class="block">{@render children()}</div> <div class="flex flex-row">
<span class="block text-xl">{text} L</span> <span class="flex-1 text-xs">{fmtp(speed)} m/s</span>
<div class="flex flex-row"> <span class="flex-1 text-xs">{dur.toFixed(3)} s</span>
<span class="flex-1 text-xs">{fmtp(speed)} m/s</span> </div>
<span class="flex-1 text-xs">{dur.toFixed(3)} s</span> {/snippet}
</div> </CalcInfo>
</div>
+4 -17
View File
@@ -2,6 +2,7 @@
import type { ComputedSeries } from '$lib/chart'; import type { ComputedSeries } from '$lib/chart';
import { AptitudeLevel, inverseSpurtSpeed, RunningStyle, spurtSpeed, Stat } from '$lib/race'; import { AptitudeLevel, inverseSpurtSpeed, RunningStyle, spurtSpeed, Stat } from '$lib/race';
import StatChart from '$lib/StatChart.svelte'; import StatChart from '$lib/StatChart.svelte';
import CalcInfo from '../CalcInfo.svelte';
const aptsList = Object.entries(AptitudeLevel).filter(([, val]) => typeof val === 'number'); const aptsList = Object.entries(AptitudeLevel).filter(([, val]) => typeof val === 'number');
const stylesList = [ 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" /> <input type="checkbox" id="isCareer" role="switch" bind:checked={isCareer} class="min-h-6 min-w-6 align-middle" />
</div> </div>
</div> </div>
<span class="mt-8 block w-full text-center text-lg"> <CalcInfo title="Target Spurt Speed" class="mx-auto mt-8 max-w-md">{speed.toFixed(3)} m/s</CalcInfo>
Target spurt speed: {speed.toFixed(3)} m/s
</span>
{#each [[AptitudeLevel.A, aProf] as const, [AptitudeLevel.S, sProf] as const] as [level, inv] (level)} {#each [[AptitudeLevel.A, aProf] as const, [AptitudeLevel.S, sProf] as const] as [level, inv] (level)}
<div class="mx-auto max-w-3xl"> <div class="mx-auto max-w-3xl">
<span class="mt-8 block w-full"> <span class="mt-8 block w-full">
@@ -103,14 +102,7 @@
</span> </span>
<div class="flex flex-col md:flex-row"> <div class="flex flex-col md:flex-row">
{#each stylesList as [styleName, s] (s)} {#each stylesList as [styleName, s] (s)}
<div <CalcInfo title={styleName} class={['flex-1', { 'border-2': s === style }]}>{inv[s]}</CalcInfo>
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>
{/each} {/each}
</div> </div>
</div> </div>
@@ -127,12 +119,7 @@
</span> </span>
<div class="flex flex-col md:flex-row"> <div class="flex flex-col md:flex-row">
{#each skillProf as [v, inv] (v)} {#each skillProf as [v, inv] (v)}
<div class="m-2 flex-1 rounded-md border shadow-sm transition-shadow hover:shadow-md"> <CalcInfo title={`+${v.toFixed(2)}`} class="flex-1">{inv}</CalcInfo>
<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>
{/each} {/each}
</div> </div>
</div> </div>