mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
feat: persistent shells
This commit is contained in:
1 parent
bf1621001b
commit
83b0c6abc3
2 files changed
+28
-9
No files matched your search
+1
-1
@@ -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)`,
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
|
||||
+27
-8
@@ -18,22 +18,42 @@ export function ReloadVisualizer({ stats }: StatsAcceptorProps) {
|
||||
const reloadCircle = useRef<HTMLDivElement>(null);
|
||||
const reloadCore = useRef<HTMLDivElement>(null);
|
||||
const reloadGlow = useRef<HTMLDivElement>(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'),
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
|
||||
Reference in new issue
Block a user