finalize
This commit is contained in:
1 parent
24580680a0
commit
e3eb20efb9
5 files changed
+123
-97
No files matched your search
@@ -1,59 +1,63 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import React, { Dispatch, SetStateAction, useEffect, useRef, useState } from 'react';
|
||||
import 'aframe';
|
||||
import 'mind-ar/dist/mindar-image-aframe.prod.js';
|
||||
|
||||
const TARGET_CONFIG = [
|
||||
{ targetIndex: 2, videoId: 'video0', videoSrc: '/res/tour/riddle_7/videos/Oswin der Stallknecht.mp4' },
|
||||
{ targetIndex: 1, videoId: 'video1', videoSrc: '/res/tour/riddle_7/videos/Mara die Kräuterfrau.mp4' },
|
||||
{ targetIndex: 0, videoId: 'video2', videoSrc: '/res/tour/riddle_7/videos/Edmund der Schreiber.mp4' },
|
||||
{ targetIndex: 3, videoId: 'video3', videoSrc: '/res/tour/riddle_7/videos/Sir Garrick die Torwache.mp4' },
|
||||
{ targetIndex: 2, videoId: 'video0', videoSrc: '/res/tour/riddle_7/videos/Oswin der Stallknecht.mp4', name: 'Oswin' },
|
||||
{ targetIndex: 1, videoId: 'video1', videoSrc: '/res/tour/riddle_7/videos/Mara die Kräuterfrau.mp4', name: 'Mara' },
|
||||
{ targetIndex: 0, videoId: 'video2', videoSrc: '/res/tour/riddle_7/videos/Edmund der Schreiber.mp4', name: 'Edmund' },
|
||||
{ targetIndex: 3, videoId: 'video3', videoSrc: '/res/tour/riddle_7/videos/Sir Garrick die Torwache.mp4', name: 'Sir Garrick' },
|
||||
];
|
||||
|
||||
export default function Riddle_7_AR_View() {
|
||||
interface Riddle_7_AR_View_Props {
|
||||
setShowNextButton?: Dispatch<SetStateAction<boolean>>
|
||||
};
|
||||
|
||||
export default function Riddle_7_AR_View({
|
||||
setShowNextButton
|
||||
}: Riddle_7_AR_View_Props) {
|
||||
const sceneRef = useRef(null);
|
||||
const targetsRef = useRef([]);
|
||||
const videosRef = useRef({});
|
||||
const lostTimesRef = useRef({});
|
||||
const cooldownRef = useRef({});
|
||||
const activeVideoRef = useRef(null);
|
||||
|
||||
const TARGET_HEIGHT = 1;
|
||||
const [activeVideo, setActiveVideo] = useState(null);
|
||||
|
||||
const [videoDimensions, setVideoDimensions] = useState({});
|
||||
const [hasInteracted, setHasInteracted] = useState(false);
|
||||
useEffect(() => {
|
||||
activeVideoRef.current = activeVideo;
|
||||
}, [activeVideo]);
|
||||
|
||||
useEffect(() => {
|
||||
const sceneEl = sceneRef.current;
|
||||
if (!sceneEl) return;
|
||||
|
||||
const arSystem = sceneEl.systems['mindar-image-system'];
|
||||
|
||||
sceneEl.addEventListener('renderstart', () => {
|
||||
arSystem.start();
|
||||
});
|
||||
const handleRenderStart = () => {
|
||||
if (arSystem) {
|
||||
arSystem.start();
|
||||
}
|
||||
};
|
||||
|
||||
sceneEl.addEventListener('renderstart', handleRenderStart);
|
||||
|
||||
targetsRef.current.forEach((targetEl, index) => {
|
||||
if (!targetEl) return;
|
||||
|
||||
const videoEl = videosRef.current[index];
|
||||
|
||||
const handleTargetFound = () => {
|
||||
if (videoEl) {
|
||||
const lostTime = lostTimesRef.current[index];
|
||||
if (lostTime && Date.now() - lostTime > 10000) {
|
||||
videoEl.currentTime = 0;
|
||||
}
|
||||
lostTimesRef.current[index] = null;
|
||||
if (activeVideoRef.current || cooldownRef.current[index]) return;
|
||||
|
||||
videoEl.play().catch((err) => {
|
||||
console.log(`Autoplay blocked on target ${index}:`, err);
|
||||
});
|
||||
const targetConfig = TARGET_CONFIG.find((t) => t.targetIndex === index);
|
||||
if (targetConfig) {
|
||||
setShowNextButton(false);
|
||||
setActiveVideo(targetConfig);
|
||||
}
|
||||
};
|
||||
|
||||
const handleTargetLost = () => {
|
||||
if (videoEl) {
|
||||
videoEl.pause();
|
||||
lostTimesRef.current[index] = Date.now();
|
||||
}
|
||||
cooldownRef.current[index] = false;
|
||||
};
|
||||
|
||||
targetEl.addEventListener('targetFound', handleTargetFound);
|
||||
@@ -61,41 +65,39 @@ export default function Riddle_7_AR_View() {
|
||||
});
|
||||
|
||||
return () => {
|
||||
if (sceneEl) {
|
||||
sceneEl.removeEventListener('renderstart', handleRenderStart);
|
||||
}
|
||||
if (arSystem) {
|
||||
try {
|
||||
arSystem.stop();
|
||||
arSystem.stop();
|
||||
} catch (error) {
|
||||
console.warn('MindAR stopped after DOM teardown:', error);
|
||||
console.warn('MindAR stopped after DOM teardown:', error);
|
||||
}
|
||||
}
|
||||
}}, []);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const handleLoadedMetadata = (index, videoEl) => {
|
||||
if (videoEl) {
|
||||
const aspect = videoEl.videoWidth / videoEl.videoHeight;
|
||||
setVideoDimensions((prev) => ({
|
||||
...prev,
|
||||
[index]: {
|
||||
width: TARGET_HEIGHT * aspect,
|
||||
height: TARGET_HEIGHT,
|
||||
},
|
||||
}));
|
||||
const handleCloseFullscreen = () => {
|
||||
if (activeVideo) {
|
||||
setShowNextButton(true);
|
||||
cooldownRef.current[activeVideo.targetIndex] = true;
|
||||
setActiveVideo(null);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
position: 'fixed',
|
||||
top: 0,
|
||||
left: 0,
|
||||
width: '100vw',
|
||||
height: '100vh',
|
||||
overflow: 'hidden',
|
||||
backgroundColor: '#000',
|
||||
}}
|
||||
style={{
|
||||
position: 'fixed',
|
||||
top: 0,
|
||||
left: 0,
|
||||
width: '100vw',
|
||||
height: '100vh',
|
||||
overflow: 'hidden',
|
||||
backgroundColor: '#000',
|
||||
}}
|
||||
>
|
||||
|
||||
<a-scene
|
||||
ref={sceneRef}
|
||||
mindar-image="imageTargetSrc: /res/tour/riddle_7/targets.mind; autoStart: false; uiLoading: no; uiError: no; uiScanning: no; filterMinCF: 0.0001; filterBeta: 0.001;"
|
||||
@@ -106,48 +108,71 @@ export default function Riddle_7_AR_View() {
|
||||
device-orientation-permission-ui="enabled: false"
|
||||
style={{ width: '100%', height: '100%' }}
|
||||
>
|
||||
<a-assets>
|
||||
{TARGET_CONFIG.map((target) => (
|
||||
<video
|
||||
key={target.videoId}
|
||||
id={target.videoId}
|
||||
ref={(el) => (videosRef.current[target.targetIndex] = el)}
|
||||
src={target.videoSrc}
|
||||
preload="auto"
|
||||
loop
|
||||
crossOrigin="anonymous"
|
||||
playsInline
|
||||
onLoadedMetadata={(e) =>
|
||||
handleLoadedMetadata(target.targetIndex, e.target)
|
||||
}
|
||||
></video>
|
||||
))}
|
||||
</a-assets>
|
||||
|
||||
<a-camera position="0 0 0" look-controls="enabled: false"></a-camera>
|
||||
|
||||
{TARGET_CONFIG.map((target) => {
|
||||
const dims = videoDimensions[target.targetIndex] || {
|
||||
width: 1,
|
||||
height: TARGET_HEIGHT,
|
||||
};
|
||||
return (
|
||||
{TARGET_CONFIG.map((target) => (
|
||||
<a-entity
|
||||
key={target.targetIndex}
|
||||
ref={(el) => (targetsRef.current[target.targetIndex] = el)}
|
||||
mindar-image-target={`targetIndex: ${target.targetIndex}`}
|
||||
>
|
||||
<a-video
|
||||
src={`#${target.videoId}`}
|
||||
width={dims.width}
|
||||
height={dims.height}
|
||||
position="0 0 0"
|
||||
rotation="0 0 0"
|
||||
></a-video>
|
||||
</a-entity>
|
||||
);
|
||||
})}
|
||||
key={target.targetIndex}
|
||||
ref={(el) => (targetsRef.current[target.targetIndex] = el)}
|
||||
mindar-image-target={`targetIndex: ${target.targetIndex}`}
|
||||
></a-entity>
|
||||
))}
|
||||
</a-scene>
|
||||
|
||||
{activeVideo && (
|
||||
<div
|
||||
style={{
|
||||
position: 'fixed',
|
||||
top: 0,
|
||||
left: 0,
|
||||
width: '100vw',
|
||||
height: '100vh',
|
||||
backgroundColor: '#000',
|
||||
zIndex: 9999,
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
}}
|
||||
>
|
||||
<button
|
||||
onClick={handleCloseFullscreen}
|
||||
style={{
|
||||
position: 'absolute',
|
||||
top: '20px',
|
||||
left: '20px',
|
||||
zIndex: 10001,
|
||||
backgroundColor: 'transparent',
|
||||
border: 'none',
|
||||
width: '48px',
|
||||
height: '48px',
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
cursor: 'pointer',
|
||||
outline: 'none',
|
||||
}}
|
||||
aria-label="Close video"
|
||||
>
|
||||
<img src="/icons/kreuz.svg" alt="Close" style={{ width: '40px', height: '40px' }} />
|
||||
</button>
|
||||
|
||||
<video
|
||||
src={activeVideo.videoSrc}
|
||||
controls
|
||||
autoPlay
|
||||
playsInline
|
||||
style={{
|
||||
position: "absolute",
|
||||
top: "0",
|
||||
left: "0",
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
objectFit: 'contain',
|
||||
zIndex: 10000,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
}
|
||||
@@ -30,6 +30,7 @@ export default function Riddle_7({
|
||||
dismissHint,
|
||||
}: RiddleScreenControls) {
|
||||
|
||||
const [ showNextButton, setShowNextButton ] = useState(true);
|
||||
const [ selection, setSelection ] = useState(-1);
|
||||
|
||||
const pages = [
|
||||
@@ -81,11 +82,11 @@ export default function Riddle_7({
|
||||
(
|
||||
<div key={2}>
|
||||
<div className={styles["content"]}>
|
||||
<Riddle_7_AR_View />
|
||||
</div>
|
||||
<div className={styles["buttons"]}>
|
||||
<OldButton red={false} disabled={false} onAction={() => setPage(3)}>URTEIL SPRECHEN</OldButton>
|
||||
<Riddle_7_AR_View setShowNextButton={setShowNextButton}/>
|
||||
</div>
|
||||
{ showNextButton ? <div className={styles["buttons"]}>
|
||||
<OldButton red={false} disabled={false} onAction={() => setPage(3)} style={{zIndex: 9998}}>URTEIL SPRECHEN</OldButton>
|
||||
</div> : null }
|
||||
</div>
|
||||
),
|
||||
(
|
||||
|
||||
@@ -31,6 +31,7 @@ export default function Tour() {
|
||||
const riddleData: Riddle[] = useMemo(() => {
|
||||
return getRiddleData();
|
||||
}, [riddleDataStr]);
|
||||
//const riddleData: Riddle[] = [{"id":1,"name":"Der Hüter des Tores","step":0,"latitude":49.089155,"longitude":9.281336,"points":500,"failPenaltyPoints":0,"skipPenaltyPoints":0,"requiredDistance":40,"hints":[]},{"id":2,"name":"Das Schwert im Stein","step":1,"latitude":49.088559,"longitude":9.281426,"points":500,"failPenaltyPoints":0,"skipPenaltyPoints":0,"requiredDistance":25,"hints":[]},{"id":3,"name":"Die Stimme des neuen Königs","step":2,"latitude":49.089056,"longitude":9.282916,"points":1000,"failPenaltyPoints":250,"skipPenaltyPoints":250,"requiredDistance":40,"hints":[]},{"id":4,"name":"Stimmen am Wegesrand","step":3,"latitude":49.089822,"longitude":9.28523,"points":1000,"failPenaltyPoints":100,"skipPenaltyPoints":100,"requiredDistance":25,"hints":[{"id":1,"hint":"Genauer hinzuhören wird euch vermutlich nicht weiterbringen. Vielleicht müsst ihr vielmehr verändern, wie ihr das Gehörte betrachtet – oder was ihr mit einer Tonaufnahme auf eurem Smartphone anstellen könnt.","penaltyPoints":150,"hintOrder":0},{"id":2,"hint":"Die Bauern sprechen nicht unverständlich; ihr hört ihre Worte nur in der falschen Richtung. Nehmt die Tonspur auf und findet einen Weg, sie in umgekehrter Reihenfolge abzuspielen.","penaltyPoints":300,"hintOrder":1}]},{"id":5,"name":"Jenseits der bekannten Wege","step":4,"latitude":49.089916,"longitude":9.285864,"points":1000,"failPenaltyPoints":500,"skipPenaltyPoints":500,"requiredDistance":25,"hints":[{"id":3,"hint":"Der Name des unbekannten Ortes ist vor Ort bereits sichtbar. Haltet Ausschau nach einem prominent platzierten Holzschild in der Nähe des unbekannten Gebietes; dort findet ihr die Lösung, die ihr eingeben müsst.","penaltyPoints":300,"hintOrder":0}]},{"id":6,"name":"Die Prüfung der Stille","step":5,"latitude":49.092468,"longitude":9.285891,"points":500,"failPenaltyPoints":0,"skipPenaltyPoints":500,"requiredDistance":20,"hints":[]},{"id":7,"name":"Lancelots Urteil","step":6,"latitude":49.093505,"longitude":9.282669,"points":1500,"failPenaltyPoints":750,"skipPenaltyPoints":750,"requiredDistance":25,"hints":[{"id":4,"hint":"Nicht nur das, was ihr am Tatort findet, kann einen Verdächtigen überführen; auch das, was dort fehlt, kann entscheidend sein. Oswin, der Stallknecht, war draußen im Regen und im Matsch unterwegs, doch der Boden vor der aufgebrochenen Truhe ist trocken und sauber.\n\nWelche Spuren hätten dort zu finden sein müssen, wenn Oswin tatsächlich der Täter gewesen wäre?","penaltyPoints":100,"hintOrder":0},{"id":5,"hint":"An der aufgebrochenen Schatulle befindet sich eine besonders auffällige Spur: Blut. Zwei der vier Verdächtigen haben eine verletzte Hand.\n\nKonzentriert euch auf diese beiden und vergleicht ihre Aussagen besonders genau mit dem übrigen Beweismaterial. Eine Verletzung allein beweist nichts, doch zusammen mit den anderen Spuren kann sie entscheidend sein.","penaltyPoints":200,"hintOrder":1}]},{"id":8,"name":"Merlins Prüfung","step":7,"latitude":49.089782,"longitude":9.281705,"points":2000,"failPenaltyPoints":500,"skipPenaltyPoints":500,"requiredDistance":25,"hints":[{"id":6,"hint":"Wenn ihr nicht weiterkommt, betrachtet nicht nur das nächste passende Symbol, sondern auch, wie sich der Würfel durch jeden Zug dreht. Der scheinbar direkte Weg kann in eine Sackgasse führen.\n\nPlant mehrere Züge voraus und denkt daran: Die dicken Linien dürfen niemals überquert werden.","penaltyPoints":200,"hintOrder":0}]},{"id":9,"name":"Die Tafelrunde","step":8,"latitude":49.089098,"longitude":9.282348,"points":2000,"failPenaltyPoints":1000,"skipPenaltyPoints":1000,"requiredDistance":25,"hints":[]}];
|
||||
|
||||
useEffect(() => {
|
||||
fetchRiddleData().then((riddleData) => {
|
||||
|
||||
Reference in new issue
Block a user