From 83b0c6abc3278c90864dea645e350f3cc9680cad Mon Sep 17 00:00:00 2001 From: tresabhi <43380238+tresabhi@users.noreply.github.com> Date: Tue, 29 Apr 2025 16:23:22 -0500 Subject: [PATCH] feat: persistent shells --- .../ReloadVisualizer/components/Shell.tsx | 2 +- .../components/ReloadVisualizer/index.tsx | 35 ++++++++++++++----- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/packages/website/src/components/Tankopedia/CharacteristicsSection/components/Characteristics/components/ReloadVisualizer/components/Shell.tsx b/packages/website/src/components/Tankopedia/CharacteristicsSection/components/Characteristics/components/ReloadVisualizer/components/Shell.tsx index 512cdd5df..9ff3b8a10 100644 --- a/packages/website/src/components/Tankopedia/CharacteristicsSection/components/Characteristics/components/ReloadVisualizer/components/Shell.tsx +++ b/packages/website/src/components/Tankopedia/CharacteristicsSection/components/Characteristics/components/ReloadVisualizer/components/Shell.tsx @@ -34,7 +34,7 @@ export function Shell({ index, stats }: ShellProps & StatsAcceptorProps) { position: 'absolute', top: '50%', left: '50%', - transform: `translate(-50%, -50%) rotate(${7 * (index - (stats.shells - 1) / 2) + 135}deg)`, + transform: `translate(-50%, -50%) rotate(${135 - 7 * (index - (stats.shells - 1) / 2)}deg)`, }} > (null); const reloadCore = useRef(null); const reloadGlow = useRef(null); + const t = useRef(0); useEffect(() => { let cancel = false; + let lastT = Date.now() / 1000; + const period = + stats.shellReload! + + (stats.intraClip ? stats.intraClip * (stats.shells - 1) : 0); function frame() { const now = Date.now() / 1000; + const dt = now - lastT; + t.current = (t.current + dt) % period; - const t = now % stats.shellReload!; - const x = t / stats.shellReload!; + // clipReloadProgress.current = + // (clipReloadProgress.current + dt / stats.shellReload!) % 1; - reloadUpdate.dispatch({ - reload: x, - shells: Array(stats.shells).fill(x), - }); + const reload = + t.current < stats.shellReload! + ? t.current / stats.shellReload! + : ((t.current - stats.shellReload!) % stats.intraClip!) / + stats.intraClip!; + const shells = + t.current < stats.shellReload! + ? Array(stats.shells).fill(reload) + : times(stats.shells, (index) => + index < (t.current - stats.shellReload!) / stats.intraClip! + ? 0 + : 1, + ); + + reloadUpdate.dispatch({ reload, shells }); if (!cancel) requestAnimationFrame(frame); + + lastT = now; } frame(); @@ -93,7 +113,6 @@ export function ReloadVisualizer({ stats }: StatsAcceptorProps) { style={{ transform: 'translate(-50%, -50%)', borderRadius: '50%', - background: Var('red-7'), filter: 'blur(0.5rem)', }} /> @@ -110,7 +129,7 @@ export function ReloadVisualizer({ stats }: StatsAcceptorProps) { style={{ transform: 'translate(-50%, -50%)', borderRadius: '50%', - background: Var('red-7'), + background: Var('orange-7'), }} >