mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 12:09:51 +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',
|
position: 'absolute',
|
||||||
top: '50%',
|
top: '50%',
|
||||||
left: '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
|
<Box
|
||||||
|
|||||||
+27
-8
@@ -18,22 +18,42 @@ export function ReloadVisualizer({ stats }: StatsAcceptorProps) {
|
|||||||
const reloadCircle = useRef<HTMLDivElement>(null);
|
const reloadCircle = useRef<HTMLDivElement>(null);
|
||||||
const reloadCore = useRef<HTMLDivElement>(null);
|
const reloadCore = useRef<HTMLDivElement>(null);
|
||||||
const reloadGlow = useRef<HTMLDivElement>(null);
|
const reloadGlow = useRef<HTMLDivElement>(null);
|
||||||
|
const t = useRef(0);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let cancel = false;
|
let cancel = false;
|
||||||
|
let lastT = Date.now() / 1000;
|
||||||
|
const period =
|
||||||
|
stats.shellReload! +
|
||||||
|
(stats.intraClip ? stats.intraClip * (stats.shells - 1) : 0);
|
||||||
|
|
||||||
function frame() {
|
function frame() {
|
||||||
const now = Date.now() / 1000;
|
const now = Date.now() / 1000;
|
||||||
|
const dt = now - lastT;
|
||||||
|
t.current = (t.current + dt) % period;
|
||||||
|
|
||||||
const t = now % stats.shellReload!;
|
// clipReloadProgress.current =
|
||||||
const x = t / stats.shellReload!;
|
// (clipReloadProgress.current + dt / stats.shellReload!) % 1;
|
||||||
|
|
||||||
reloadUpdate.dispatch({
|
const reload =
|
||||||
reload: x,
|
t.current < stats.shellReload!
|
||||||
shells: Array(stats.shells).fill(x),
|
? 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);
|
if (!cancel) requestAnimationFrame(frame);
|
||||||
|
|
||||||
|
lastT = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
frame();
|
frame();
|
||||||
@@ -93,7 +113,6 @@ export function ReloadVisualizer({ stats }: StatsAcceptorProps) {
|
|||||||
style={{
|
style={{
|
||||||
transform: 'translate(-50%, -50%)',
|
transform: 'translate(-50%, -50%)',
|
||||||
borderRadius: '50%',
|
borderRadius: '50%',
|
||||||
background: Var('red-7'),
|
|
||||||
filter: 'blur(0.5rem)',
|
filter: 'blur(0.5rem)',
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@@ -110,7 +129,7 @@ export function ReloadVisualizer({ stats }: StatsAcceptorProps) {
|
|||||||
style={{
|
style={{
|
||||||
transform: 'translate(-50%, -50%)',
|
transform: 'translate(-50%, -50%)',
|
||||||
borderRadius: '50%',
|
borderRadius: '50%',
|
||||||
background: Var('red-7'),
|
background: Var('orange-7'),
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Box
|
<Box
|
||||||
|
|||||||
Reference in new issue
Block a user