diff --git a/src/main.jsx b/src/main.jsx index 526c642..ac70799 100644 --- a/src/main.jsx +++ b/src/main.jsx @@ -6,7 +6,9 @@ import './css/global.css'; import HomePage from './pages/homePage.jsx'; import WarningPage from './pages/warningPage.jsx'; import NamePage from './pages/namePage.jsx'; -import Animation from './pages/components/testAnimation_onefile.jsx'; +import Animation from './pages/components/animation.jsx'; +import IntroductionPage from './pages/introductionPage.jsx'; + createRoot(document.getElementById('root')).render( @@ -16,6 +18,8 @@ createRoot(document.getElementById('root')).render( } /> } /> } /> + } /> + } /> diff --git a/src/pages/components/animation.jsx b/src/pages/components/animation.jsx new file mode 100644 index 0000000..ff3f5e6 --- /dev/null +++ b/src/pages/components/animation.jsx @@ -0,0 +1,79 @@ +import React, { useEffect, useState } from 'react'; +import JSZip from 'jszip'; + +const Animation = ({src="src/assets/mainCharacters/M_Porsche_cross_arm.zip" ,animationWidth="500px"}) => { + const [images, setImages] = useState([]); + const [currentFrame, setCurrentFrame] = useState(0); + const [loading, setLoading] = useState(true); + const frameRate = 1000/24; + + useEffect(() => { + const loadImages = async () => { + const zip = new JSZip(); + try { + const response = await fetch(src); + if (!response.ok) { + throw new Error('Network response was not ok'); + } + const data = await response.arrayBuffer(); + const zipContent = await zip.loadAsync(data); + + const imgPromises = []; + zipContent.forEach((relativePath, file) => { + if (file.name.endsWith('.webp')) { + imgPromises.push( + file.async('base64').then(base64 => { + return `data:image/webp;base64,${base64}`; + }) + ); + } + }); + + const imgUrls = await Promise.all(imgPromises); + + if (imgUrls.length === 0) { + console.error('No images found in the ZIP file.'); + } + + setImages(imgUrls); + } catch (error) { + console.error('Error loading images:', error); + } finally { + setLoading(false); + } + }; + + loadImages(); + + }, []); + + useEffect(() => { + if (images.length > 0) { + const interval = setInterval(() => { + setCurrentFrame((prevFrame) => (prevFrame + 1) % images.length); + }, frameRate); + + return () => clearInterval(interval); + } + }, [images]); + + if (loading) { + return
Loading...
; + } else { + return ( +
+ {images.length > 0 ? ( + {`Animation + ) : ( +
No images to display.
+ )} +
+ ); + } +}; + +export default Animation; diff --git a/src/pages/components/testAnimation_manyfiles.jsx b/src/pages/components/testAnimation_manyfiles.jsx index 5063aa1..cb86fbb 100644 --- a/src/pages/components/testAnimation_manyfiles.jsx +++ b/src/pages/components/testAnimation_manyfiles.jsx @@ -42,4 +42,5 @@ const CharacterAnimation = () => { ); }; + export default CharacterAnimation; diff --git a/src/pages/components/testAnimation_onefile.jsx b/src/pages/components/testAnimation_onefile.jsx index 5e99722..9dca1db 100644 --- a/src/pages/components/testAnimation_onefile.jsx +++ b/src/pages/components/testAnimation_onefile.jsx @@ -1,7 +1,7 @@ import React, { useEffect, useState } from 'react'; import JSZip from 'jszip'; -const Animation = () => { +const TestAnimation = () => { const [images, setImages] = useState([]); const [currentFrame, setCurrentFrame] = useState(0); const [loading, setLoading] = useState(true); @@ -11,7 +11,7 @@ const Animation = () => { const loadImages = async () => { const zip = new JSZip(); try { - const response = await fetch('src/assets/characters/M_Porsche_cross_arm.zip'); + const response = await fetch('src/assets/mainCharacters/M_Porsche_cross_arm.zip'); if (!response.ok) { throw new Error('Network response was not ok'); } @@ -78,4 +78,4 @@ const Animation = () => { } }; -export default Animation; +export default TestAnimation; diff --git a/src/pages/introductionPage.jsx b/src/pages/introductionPage.jsx new file mode 100644 index 0000000..0391c63 --- /dev/null +++ b/src/pages/introductionPage.jsx @@ -0,0 +1,58 @@ +import { useState } from 'react' +import '../css/global.css' +import BlackButton from './components/customButton' +import Animation from './components/animation.jsx'; + +function IntroductionPage() { + return( +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ +
+ +
+
+ ) +} + +export default IntroductionPage diff --git a/src/pages/namePage.jsx b/src/pages/namePage.jsx index 94ec2f7..735db28 100644 --- a/src/pages/namePage.jsx +++ b/src/pages/namePage.jsx @@ -29,7 +29,7 @@ function NamePage() { name==''? <> : - + } )