Skip to content

Instantly share code, notes, and snippets.

@lmiller1990
Created September 29, 2022 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmiller1990/6070a4c1f110572376c5f61c14ae8c75 to your computer and use it in GitHub Desktop.
Save lmiller1990/6070a4c1f110572376c5f61c14ae8c75 to your computer and use it in GitHub Desktop.
import type { FunctionalComponent } from "vue";
export interface Timing {
window: string;
count: number;
}
export interface GameplayScoreProps {
percent: string;
timing: Timing[];
}
const TimingCount: FunctionalComponent<{ count: number }> = (props) => {
const str = props.count.toString().padStart(4, "0").split("");
let foundNonZero = false;
let jsx: JSX.Element[] = [];
for (const char of str) {
if (char !== "0") {
foundNonZero = true;
}
jsx.push(
<span
class={`${foundNonZero ? "text-white" : "text-stone-400"} font-mono`}
>
{char}
</span>
);
}
return jsx;
};
export const GameplayScore: FunctionalComponent<GameplayScoreProps> = (
props
) => {
return (
<div class="flex flex-col text-white text-2xl uppercase">
<div class="flex justify-end font-mono text-5xl">{props.percent}</div>
{props.timing.map((timing) => (
<div class="mt-5">
<div
class={`timing-${timing.window.toLowerCase()} flex justify-end`}
key={timing.window}
>
{timing.window}
</div>
<div class="flex justify-end">
<TimingCount count={timing.count} />
</div>
</div>
))}
</div>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment