Skip to content

Commit

Permalink
Test animation skip for cutscene when forwarding
Browse files Browse the repository at this point in the history
  • Loading branch information
miku448 committed Mar 1, 2025
1 parent 8969e2f commit ad58e98
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions apps/interactor/src/components/common/TextFormatter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { setDisplayingLastSentence } from '../../state/slices/settingsSlice';
interface TextFormatterProps {
text: string;
children?: React.ReactNode;
noAnimation?: boolean;
}

interface TextElement {
Expand Down Expand Up @@ -139,12 +140,12 @@ const useAnimatedText = (text: string) => {
return { displayedText, isAnimationComplete, skipAnimation };
};

export const TextFormatterStatic: React.FC<TextFormatterProps> = ({ text, children }) => {
export const TextFormatterStatic: React.FC<TextFormatterProps> = ({ text, children, noAnimation }) => {
const fontSize = useAppSelector((state) => state.settings.text.fontSize);
const textFormatterDiv = useRef<HTMLDivElement>(null);
const [userScrolled, setUserScrolled] = useState(false);

const { displayedText, isAnimationComplete } = useAnimatedText(text);
const { displayedText, isAnimationComplete, skipAnimation } = useAnimatedText(text);

const elements = useMemo(() => {
const parsedElements = parseTextElements(displayedText);
Expand All @@ -163,6 +164,13 @@ export const TextFormatterStatic: React.FC<TextFormatterProps> = ({ text, childr
});
}, [displayedText]);

useEffect(() => {
if (noAnimation) {
console.log('skipping animation');
skipAnimation();
}
}, [noAnimation, skipAnimation]);

useEffect(() => {
if (textFormatterDiv.current) {
if (textFormatterDiv.current.scrollHeight <= textFormatterDiv.current.clientHeight) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export const CutsceneDisplayer = ({ onEndDisplay }: { onEndDisplay: () => void }
}}
>
<TextFormatterStatic
noAnimation={index < currentTextIndex}
text={textItem.type === 'description' ? textItem.content : `"${textItem.content}"`}
/>
</div>
Expand Down

0 comments on commit ad58e98

Please sign in to comment.