Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(coding): conding game implement #66

Merged
merged 3 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion public/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
"users_desc": "Voici la liste de tout les utilisateurs",
"email": "E-mail"
}
}
}
80 changes: 80 additions & 0 deletions src/modules/CodingGame.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"use client";

import { AnimatePresence, motion } from "framer-motion";
import { useCommandStore } from "@src/stores/useCommandStore";
import { Textarea } from "@src/ui/textarea";

export type CodingGameProps = React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> & {
consigne: string;
outpout: string;
code?: string;
};

export const CodingGame: React.FC<CodingGameProps> = ({ consigne, outpout, code }) => {
const { remove } = useCommandStore();

return (
<>
<div className="absolute left-[2.5%] top-8 flex h-[95%] w-[34%] flex-col items-center gap-2">
<motion.div
className="flex h-full w-full flex-wrap rounded-md border bg-black/80 p-8"
initial={{ opacity: 0, y: 200 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: 200 }}
transition={{ duration: 0.3 }}
onClick={remove}
>
<AnimatePresence>
{consigne.split("").map((char, i) => (
<motion.span
key={i}
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ delay: i * 0.05, duration: 0.01 }}
className="h-fit select-none text-lg text-white"
>
{char === " " ? "\u00A0" : char}
</motion.span>
))}
</AnimatePresence>
</motion.div>
</div>
<div className="absolute right-[2.5%] top-8 flex h-3/5 w-3/5 flex-col items-center gap-2">
<motion.div
className="flex h-full w-full flex-wrap rounded-md border bg-black/80 p-8"
initial={{ opacity: 0, y: 200 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: 200 }}
transition={{ duration: 0.3 }}
onClick={remove}
>
<Textarea placeholder={code} />
</motion.div>
</div>
<div className="absolute bottom-4 right-[2.5%] flex h-1/3 w-[60%] flex-col items-center gap-2">
<motion.div
className="flex h-full w-full flex-wrap rounded-md border bg-black/80 p-8"
initial={{ opacity: 0, y: 200 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: 200 }}
transition={{ duration: 0.3 }}
onClick={remove}
>
<AnimatePresence>
{outpout.split("").map((char, i) => (
<motion.span
key={i}
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ delay: i * 0.05, duration: 0.01 }}
className="h-fit select-none text-lg text-white"
>
{char === " " ? "\u00A0" : char}
</motion.span>
))}
</AnimatePresence>
</motion.div>
</div>
</>
);
};
2 changes: 2 additions & 0 deletions src/modules/scene/GameScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Suspense, useEffect, useRef } from "react";
import { CameraControls } from "@react-three/drei";
import { Canvas } from "@react-three/fiber";
import { AnimatePresence } from "framer-motion";
// import { CodingGame } from "@modules/CodingGame";
// import { CubeTextureLoader } from "three";
import { Dialog } from "@modules/Dialog";
import { LoadingScene } from "@modules/scene/LoadingScene";
Expand Down Expand Up @@ -44,6 +45,7 @@ export const GameScene: React.FC<GameSceneProps> = () => {
["1) is_even = num % 2 == 1", "2) is_even = num % 2 == 0"],
],
},
{ type: "coding", args: ["les consigne s'afficheront ici"] },
]);
}}
/>
Expand Down
8 changes: 8 additions & 0 deletions src/stores/useCommandStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ const commandHandler = (command: Command) => {
dialogStore.setOptions(options);
}
break;
case "coding":
{
const dialogStore = useDialogStore.getState();
dialogStore.setText(command.args[0] as string);
const options = command.args[1] as string[];
dialogStore.setOptions(options);
}
break;
default:
break;
}
Expand Down
20 changes: 20 additions & 0 deletions src/ui/textarea.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as React from "react";
import { cn } from "@lib/utils";

export type TextareaProps = object & React.TextareaHTMLAttributes<HTMLTextAreaElement>;

const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(({ className, ...props }, ref) => {
return (
<textarea
className={cn(
"flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
className,
)}
ref={ref}
{...props}
/>
);
});
Textarea.displayName = "Textarea";

export { Textarea };