mirror of
https://github.com/denismhz/solar-system.git
synced 2025-11-09 08:06:22 +01:00
reset
This commit is contained in:
parent
e1856aaafc
commit
48da123b72
|
|
@ -50,6 +50,14 @@ export const SharedPlanetState = () => {
|
|||
};
|
||||
customData.current["handleVisibility"] = handleVisibility;
|
||||
|
||||
let [resetB, setResetB] = useState(false);
|
||||
|
||||
const handleReset = () => {
|
||||
setSpeed(0);
|
||||
dateTime.current = new Date(Date.now());
|
||||
};
|
||||
customData.current["handleReset"] = handleReset;
|
||||
|
||||
//set speed (timeinterval between positions 60000ms*speed)
|
||||
const [speed, setSpeed] = useState(0);
|
||||
const updateSpeed = (newSpeed) => {
|
||||
|
|
@ -67,11 +75,8 @@ export const SharedPlanetState = () => {
|
|||
|
||||
//???????Why when i set the speed to 0 it doesnt immidiatly stop? good enough for know
|
||||
if (speedChanged.current) {
|
||||
console.log(oldState.length);
|
||||
setPosState(oldState.slice(0, posCounter));
|
||||
speedChanged.current = true;
|
||||
console.log(oldState.length);
|
||||
console.log("SPEEDUPDOWNLEFTRIGHT!");
|
||||
}
|
||||
|
||||
if (posCounter % 250 == 0 || speedChanged.current) {
|
||||
|
|
@ -88,21 +93,14 @@ export const SharedPlanetState = () => {
|
|||
);
|
||||
let response = await res.json();
|
||||
//console.log(response);
|
||||
if (speed > 0) {
|
||||
if (true) {
|
||||
setPosState(oldState.concat(response));
|
||||
|
||||
//console.log(dateTime.current);
|
||||
} else if (speed == 0) {
|
||||
//this requests every frame do a function
|
||||
//that requests every minute and clear intervall
|
||||
//when apead is changed to above 0
|
||||
setPosState([response]);
|
||||
posCounter = 0;
|
||||
}
|
||||
speedChanged.current = false;
|
||||
};
|
||||
fetchData();
|
||||
//console.log(speed);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -56,11 +56,20 @@ export const Earth = ({ positions, speed, getPosition, nameVis, iconVis }) => {
|
|||
group.current.userData.name = "Earth";
|
||||
group.current.userData.nearOvOp = 60;
|
||||
group.current.userData.scolor = "lightgreen";
|
||||
}, []);
|
||||
|
||||
function datas() {
|
||||
return group;
|
||||
}
|
||||
const fetchData = async () => {
|
||||
let res = await fetch(
|
||||
`http://127.0.0.1:8000/duration/earth` +
|
||||
`?date=${new Date(Date.now())}&speed=0`
|
||||
);
|
||||
let response = await res.json();
|
||||
if (speed == 0) setPos([response]);
|
||||
};
|
||||
fetchData();
|
||||
const interval = setInterval(() => {
|
||||
fetchData();
|
||||
}, 6000);
|
||||
return () => clearInterval(interval);
|
||||
}, [speed]);
|
||||
|
||||
useEffect(() => {
|
||||
console.log(speed);
|
||||
|
|
@ -69,11 +78,11 @@ export const Earth = ({ positions, speed, getPosition, nameVis, iconVis }) => {
|
|||
let currLinePoss = [];
|
||||
|
||||
useFrame(() => {
|
||||
//console.log(nameVis);
|
||||
clouds.current.rotation.y += 0.00025;
|
||||
earth.current.rotation.y += 0.00015;
|
||||
getPosition("earth", setPos, poss, group.current.userData.counter);
|
||||
console.log(poss);
|
||||
if (speed > 0)
|
||||
getPosition("earth", setPos, poss, group.current.userData.counter);
|
||||
//console.log(poss);
|
||||
if (true && group.current.userData.counter < poss.length) {
|
||||
group.current.position.set(
|
||||
Number(
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ export const ScreenOverlay = () => {
|
|||
};
|
||||
|
||||
const handleReset = () => {
|
||||
customData.current.handleReset();
|
||||
console.log("reset");
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue