Skip to content

Commit

Permalink
feature: add speed stat after game
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxencee committed Mar 22, 2024
1 parent b29b579 commit 8d3ede4
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
4 changes: 3 additions & 1 deletion client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import CosmeticPage from "./pages/flami/CosmeticPage";
import LegalNoticesPage from "./pages/legal/LegalNoticesPage";
import ThanksPage from "./pages/legal/ThanksPage";
import { useTheme } from "./hooks/useTheme";
import TrainFlami from "./pages/activities/TrainFlami";

const TOAST_LIMIT = 2;

Expand All @@ -47,8 +48,9 @@ const App = () => {
<Route path="profile" element={<ProfilePage />} />
<Route path="account" element={<AccountPage />} />
<Route path="badges" element={<AllBadgesPage />} />
<Route path="training" element={<TrainingPage />} />
<Route path="cosmetics" element={<CosmeticPage />} />
<Route path="training" element={<TrainingPage />} />
<Route path="flami/train/:time" element={<TrainFlami />} />
<Route path="legal-notices" element={<LegalNoticesPage />} />
<Route path="thanks" element={<ThanksPage />} />
</Route>
Expand Down
6 changes: 6 additions & 0 deletions client/src/components/game/scenes/Runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,5 +270,11 @@ export class Runner extends Phaser.Scene {
this.scrollSpeed = 0;
},
});

this.finishRace = () => null;

setTimeout(() => {
window.location.href = `/flami/train/${this.timerInterval}`;
}, 2000);
}
}
37 changes: 37 additions & 0 deletions client/src/pages/activities/TrainFlami.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { useEffect } from "react";
import { APIHandler } from "../../utils/api/api-handler";
import { GenericResponse } from "../../interfaces/api-response/generic-response";
import { useAuth } from "../../hooks/useAuth";
import toast from "react-hot-toast";
import { useNavigate } from "react-router";

const TrainFlami = () => {
let value = parseInt(location.pathname.substring(location.pathname.lastIndexOf('/') + 1));
const { token } = useAuth();
const navigate = useNavigate();

useEffect(() => {
APIHandler<GenericResponse>(
`/my/flami/training`,
false,
"PATCH",
{ worked_stat: 'speed' },
token
).then(() => {
toast.success("Ton Flami a gagné en vitesse !", {
style: {
background: "#3D3D3D",
color: "#FAFAFA",
borderRadius: "12px",
},
});
});
navigate("/");
}, [toast, token]);

return <>
FLAMI TRAINED STATS VITESSE ADD {value} / ?
</>;
};

export default TrainFlami;
7 changes: 6 additions & 1 deletion client/src/pages/activities/TrainingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ const TrainingPage = () => {
const [time, setTime] = useState<number>(0);
console.log(time);
setShowNav(false);
return <>{<RunnerGame setTime={setTime} />}</>;
return <>
{<h1 className="px-6 text-center text-alabaster-950 text-2xl absolute inset-x-0 top-28 z-500">Tape sur l'écran pour faire courir Flami !</h1>}
<div className="game-container fixed left-0">
{<RunnerGame setTime={setTime}/>}
</div>
</>;
};

export default TrainingPage;

0 comments on commit 8d3ede4

Please sign in to comment.