mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-25 03:29:51 +01:00
feat: simplier hiding
This commit is contained in:
1 parent
fb47ab3e64
commit
4165533838
3 files changed
+19
-74
No files matched your search
@@ -15,7 +15,7 @@ const [modelDefinitions, provisionDefinitions] = await Promise.all([
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
export function Background() {
|
export function Background() {
|
||||||
const state = GuessEphemeral.use((state) => state.guessState);
|
const guessState = GuessEphemeral.use((state) => state.guessState);
|
||||||
const tank = GuessEphemeral.use((state) => state.tank);
|
const tank = GuessEphemeral.use((state) => state.tank);
|
||||||
const mutateDuel = Duel.useMutation();
|
const mutateDuel = Duel.useMutation();
|
||||||
const mutateTankopediaEphemeral = TankopediaEphemeral.useMutation();
|
const mutateTankopediaEphemeral = TankopediaEphemeral.useMutation();
|
||||||
@@ -39,19 +39,16 @@ export function Background() {
|
|||||||
top="0"
|
top="0"
|
||||||
left="0"
|
left="0"
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: Var(`${state ? 'jade' : 'tomato'}-3`),
|
transitionDuration: '2s',
|
||||||
}}
|
backgroundColor: Var(
|
||||||
>
|
guessState === null
|
||||||
<Box
|
? 'accent-2'
|
||||||
width="100%"
|
: guessState
|
||||||
height="100%"
|
? 'jade-3'
|
||||||
style={{
|
: 'tomato-3',
|
||||||
opacity: state === null ? 1 : 0,
|
),
|
||||||
transitionDuration: '200ms',
|
|
||||||
backgroundColor: Var('cyan-3'),
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Box>
|
|
||||||
|
|
||||||
<Box
|
<Box
|
||||||
className="guess-background"
|
className="guess-background"
|
||||||
|
|||||||
@@ -1,75 +1,26 @@
|
|||||||
import { Canvas, invalidate } from '@react-three/fiber';
|
import { Canvas } from '@react-three/fiber';
|
||||||
import { type QuicklimeCallback, Quicklime } from 'quicklime';
|
|
||||||
import { useCallback, useEffect, useRef } from 'react';
|
|
||||||
import { Fog } from 'three';
|
|
||||||
import { Controls } from '../../../../../components/Tankopedia/HeroSection/components/TankSandbox/components/Control';
|
import { Controls } from '../../../../../components/Tankopedia/HeroSection/components/TankSandbox/components/Control';
|
||||||
import { Lighting } from '../../../../../components/Tankopedia/HeroSection/components/TankSandbox/components/Lighting';
|
import { Lighting } from '../../../../../components/Tankopedia/HeroSection/components/TankSandbox/components/Lighting';
|
||||||
import { TankModel } from '../../../../../components/Tankopedia/HeroSection/components/TankSandbox/components/TankModel';
|
import { TankModel } from '../../../../../components/Tankopedia/HeroSection/components/TankSandbox/components/TankModel';
|
||||||
import { Var } from '../../../../../core/radix/var';
|
import { GuessEphemeral } from '../../../../../stores/guessEphemeral';
|
||||||
import { TankopediaDisplay } from '../../../../../stores/tankopediaPersistent/constants';
|
import { TankopediaDisplay } from '../../../../../stores/tankopediaPersistent/constants';
|
||||||
|
|
||||||
const nearConcealed = -45;
|
const BRIGHTNESS = 2 ** -5;
|
||||||
const farConcealed = 22;
|
const CONTRAST = 2 ** 2;
|
||||||
const nearRevealed = 25;
|
|
||||||
const farRevealed = 25;
|
|
||||||
const animationDuration = 1;
|
|
||||||
|
|
||||||
export const revealEvent = new Quicklime<boolean>();
|
|
||||||
|
|
||||||
export function GuessRenderer() {
|
export function GuessRenderer() {
|
||||||
const fog = useRef(new Fog('black', nearConcealed, farConcealed));
|
const guessState = GuessEphemeral.use((state) => state.guessState);
|
||||||
const reveal = useCallback((show: boolean) => {
|
const isRevealed = guessState !== null;
|
||||||
if (!show) {
|
|
||||||
fog.current.near = nearConcealed;
|
|
||||||
fog.current.far = farConcealed;
|
|
||||||
invalidate();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const t0 = Date.now() / 1000;
|
|
||||||
|
|
||||||
function frame() {
|
|
||||||
const t = Date.now() / 1000;
|
|
||||||
const x = (t - t0) / animationDuration;
|
|
||||||
const y = Math.sqrt(x);
|
|
||||||
const near = nearConcealed * (1 - y) + nearRevealed * y;
|
|
||||||
const far = farConcealed * (1 - y) + farRevealed * y;
|
|
||||||
|
|
||||||
fog.current.near = near;
|
|
||||||
fog.current.far = far;
|
|
||||||
|
|
||||||
invalidate();
|
|
||||||
|
|
||||||
if (y < 1) {
|
|
||||||
requestAnimationFrame(frame);
|
|
||||||
} else {
|
|
||||||
fog.current.near = nearRevealed;
|
|
||||||
fog.current.far = farRevealed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
requestAnimationFrame(frame);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const handleRevealEvent: QuicklimeCallback<boolean> = ({ data }) => {
|
|
||||||
reveal(data);
|
|
||||||
};
|
|
||||||
|
|
||||||
revealEvent.on(handleRevealEvent);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
revealEvent.off(handleRevealEvent);
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Canvas
|
<Canvas
|
||||||
style={{
|
style={{
|
||||||
filter: `drop-shadow(0 0 1rem ${Var('black-a11')})`,
|
filter: `grayscale(${isRevealed ? 0 : 1}) contrast(${isRevealed ? 1 : CONTRAST}) brightness(${isRevealed ? 1 : BRIGHTNESS})`,
|
||||||
|
// filter: `drop-shadow(0 0 1rem ${Var('black-a11')})`,
|
||||||
|
transitionDuration: isRevealed ? '2s' : undefined,
|
||||||
|
transitionProperty: 'filter',
|
||||||
}}
|
}}
|
||||||
camera={{ position: [-5, 5, -5] }}
|
camera={{ position: [-5, 5, -5] }}
|
||||||
scene={{ fog: fog.current }}
|
|
||||||
>
|
>
|
||||||
<Controls distanceScale={2} zoomable={false} />
|
<Controls distanceScale={2} zoomable={false} />
|
||||||
<Lighting display={TankopediaDisplay.Model} />
|
<Lighting display={TankopediaDisplay.Model} />
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import { awaitableTankDefinitions } from '../../../../../core/awaitables/tankDef
|
|||||||
import { awaitableTankNames } from '../../../../../core/awaitables/tankNames';
|
import { awaitableTankNames } from '../../../../../core/awaitables/tankNames';
|
||||||
import { useLocale } from '../../../../../hooks/useLocale';
|
import { useLocale } from '../../../../../hooks/useLocale';
|
||||||
import { GuessEphemeral } from '../../../../../stores/guessEphemeral';
|
import { GuessEphemeral } from '../../../../../stores/guessEphemeral';
|
||||||
import { revealEvent } from './GuessRenderer';
|
|
||||||
|
|
||||||
const { go } = fuzzysort;
|
const { go } = fuzzysort;
|
||||||
|
|
||||||
@@ -167,7 +166,6 @@ export function Guesser() {
|
|||||||
console.log('what');
|
console.log('what');
|
||||||
const correct = selected!.id === tank.id;
|
const correct = selected!.id === tank.id;
|
||||||
|
|
||||||
revealEvent.dispatch(true);
|
|
||||||
mutateGuessEphemeral((draft) => {
|
mutateGuessEphemeral((draft) => {
|
||||||
draft.guessState = correct;
|
draft.guessState = correct;
|
||||||
draft.totalGuesses++;
|
draft.totalGuesses++;
|
||||||
@@ -177,7 +175,6 @@ export function Guesser() {
|
|||||||
const id = Number(ids[Math.floor(Math.random() * ids.length)]);
|
const id = Number(ids[Math.floor(Math.random() * ids.length)]);
|
||||||
const tank = tankDefinitions.tanks[id];
|
const tank = tankDefinitions.tanks[id];
|
||||||
|
|
||||||
revealEvent.dispatch(false);
|
|
||||||
mutateGuessEphemeral((draft) => {
|
mutateGuessEphemeral((draft) => {
|
||||||
if (!input.current) return;
|
if (!input.current) return;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user