Skip to content

Commit 528d5a6

Browse files
author
TonNom
committed
Sauvegarde avant rebase
1 parent 653f3f1 commit 528d5a6

8 files changed

Lines changed: 516 additions & 3 deletions

File tree

src/components/LinearProgressBar.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import {
99
const LinearProgressBar = (
1010
props: LinearProgressProps & { value: number; label: string }
1111
) => {
12-
if (props.value === 0) return null;
13-
1412
return (
1513
<Grid
1614
container

src/components/OpeningProgress.tsx

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import React, { useEffect, useState } from "react";
2+
import LinearProgressBar from "./LinearProgressBar";
3+
import { Button, Box } from "@mui/material";
4+
import { useTheme } from "@mui/material/styles";
5+
6+
// Props :
7+
// - total : nombre total de variations
8+
// - openingKey : identifiant unique de l'ouverture (ex: 'italian')
9+
// - mode : 'learning' | 'training'
10+
//
11+
// - currentVariationIndex : index de la variation en cours (optionnel, pour affichage)
12+
13+
interface OpeningProgressProps {
14+
total: number;
15+
openingKey: string;
16+
mode: "learning" | "training";
17+
// Liste des index de variations terminées
18+
completed: number[];
19+
onReset?: () => void;
20+
}
21+
22+
const getStorageKey = (openingKey: string, mode: string) => `${openingKey}-progress-${mode}`;
23+
24+
const OpeningProgress: React.FC<OpeningProgressProps> = ({
25+
total,
26+
openingKey,
27+
mode,
28+
completed,
29+
onReset,
30+
}) => {
31+
const [progress, setProgress] = useState<number[]>(completed);
32+
const theme = useTheme();
33+
34+
useEffect(() => {
35+
setProgress(completed);
36+
}, [completed]);
37+
38+
// Calcul du pourcentage
39+
const percent = total > 0 ? (progress.length / total) * 100 : 0;
40+
const label = `${progress.length} / ${total}`;
41+
42+
// Réinitialisation
43+
const handleReset = () => {
44+
localStorage.removeItem(getStorageKey(openingKey, mode));
45+
setProgress([]);
46+
onReset && onReset();
47+
};
48+
49+
return (
50+
<Box
51+
width={{ xs: "100%", sm: 320, md: 340 }}
52+
sx={{
53+
mt: { xs: 2, md: 3 },
54+
mb: { xs: 0, md: 1 },
55+
px: { xs: 0, sm: 1 },
56+
alignSelf: "flex-end",
57+
position: "relative",
58+
left: 0,
59+
bottom: 0,
60+
display: "flex",
61+
flexDirection: "row",
62+
alignItems: "center",
63+
gap: 1,
64+
}}
65+
>
66+
<Box minWidth={48}>
67+
<span style={{ fontSize: 14, color: theme.palette.text.secondary }}>{label}</span>
68+
</Box>
69+
<Box flex={1} minWidth={0}>
70+
<LinearProgressBar value={percent} label={""} />
71+
</Box>
72+
<Button
73+
size="small"
74+
variant="contained"
75+
color="primary"
76+
sx={{
77+
ml: 2,
78+
borderRadius: 2,
79+
textTransform: "none",
80+
fontWeight: 500,
81+
boxShadow: theme.shadows[1],
82+
minWidth: 0,
83+
px: 2,
84+
}}
85+
onClick={handleReset}
86+
>
87+
Réinitialiser
88+
</Button>
89+
</Box>
90+
);
91+
};
92+
93+
export default OpeningProgress;

src/components/board/index.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ import PlayerHeader from "./playerHeader";
2222
import { boardHueAtom, pieceSetAtom } from "./states";
2323
import tinycolor from "tinycolor2";
2424

25+
export interface TrainingFeedback {
26+
square: string; // ex: 'e4'
27+
icon: string; // chemin de l'icône
28+
alt: string; // texte alternatif
29+
}
30+
2531
export interface Props {
2632
id: string;
2733
canPlay?: Color | boolean;
@@ -34,6 +40,7 @@ export interface Props {
3440
showBestMoveArrow?: boolean;
3541
showPlayerMoveIconAtom?: PrimitiveAtom<boolean>;
3642
showEvaluationBar?: boolean;
43+
trainingFeedback?: TrainingFeedback;
3744
}
3845

3946
export default function Board({
@@ -48,6 +55,7 @@ export default function Board({
4855
showBestMoveArrow = false,
4956
showPlayerMoveIconAtom,
5057
showEvaluationBar = false,
58+
trainingFeedback,
5159
}: Props) {
5260
const boardRef = useRef<HTMLDivElement>(null);
5361
const game = useAtomValue(gameAtom);
@@ -239,12 +247,14 @@ export default function Board({
239247
clickedSquaresAtom,
240248
playableSquaresAtom,
241249
showPlayerMoveIconAtom,
250+
trainingFeedback, // nouvelle prop transmise
242251
});
243252
}, [
244253
currentPositionAtom,
245254
clickedSquaresAtom,
246255
playableSquaresAtom,
247256
showPlayerMoveIconAtom,
257+
trainingFeedback,
248258
]);
249259

250260
const customPieces = useMemo(

src/components/board/squareRenderer.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,19 @@ export interface Props {
1515
clickedSquaresAtom: PrimitiveAtom<Square[]>;
1616
playableSquaresAtom: PrimitiveAtom<Square[]>;
1717
showPlayerMoveIconAtom?: PrimitiveAtom<boolean>;
18+
trainingFeedback?: {
19+
square: string;
20+
icon: string;
21+
alt: string;
22+
};
1823
}
1924

2025
export function getSquareRenderer({
2126
currentPositionAtom,
2227
clickedSquaresAtom,
2328
playableSquaresAtom,
2429
showPlayerMoveIconAtom = atom(false),
30+
trainingFeedback,
2531
}: Props) {
2632
const squareRenderer = forwardRef<HTMLDivElement, CustomSquareProps>(
2733
(props, ref) => {
@@ -64,6 +70,25 @@ export function getSquareRenderer({
6470
{children}
6571
{highlightSquareStyle && <div style={highlightSquareStyle} />}
6672
{playableSquareStyle && <div style={playableSquareStyle} />}
73+
{/* Affichage de l’icône de feedback training si demandé et sur la bonne case */}
74+
{trainingFeedback && trainingFeedback.square === square && (
75+
<img
76+
src={trainingFeedback.icon}
77+
alt={trainingFeedback.alt}
78+
style={{
79+
position: "absolute",
80+
top: 0,
81+
right: 0,
82+
transform: "translate(35%,-35%)",
83+
width: 28,
84+
height: 28,
85+
zIndex: 120,
86+
pointerEvents: "none",
87+
opacity: 0.95,
88+
}}
89+
/>
90+
)}
91+
{/* Aucun affichage de message texte d'erreur ici, seulement l'icône */}
6792
{moveClassification && showPlayerMoveIcon && square === toSquare && (
6893
<Image
6994
src={`/icons/${moveClassification}.png`}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// italianGame.ts
2+
3+
export type Move = string;
4+
5+
export interface Variation {
6+
name: string;
7+
moves: Move[];
8+
}
9+
10+
export const italianGameVariations: Variation[] = [
11+
{
12+
name: "Giuoco Piano",
13+
moves: ["e4", "e5", "Nf3", "Nc6", "Bc4", "Bc5", "c3", "Nf6", "d3", "d6", "O-O", "O-O"],
14+
},
15+
{
16+
name: "Evans Gambit",
17+
moves: ["e4", "e5", "Nf3", "Nc6", "Bc4", "Bc5", "b4", "Bxb4", "c3", "Ba5", "d4", "exd4", "O-O"],
18+
},
19+
{
20+
name: "Two Knights Defense",
21+
moves: ["e4", "e5", "Nf3", "Nc6", "Bc4", "Nf6"],
22+
},
23+
{
24+
name: "Fried Liver Attack",
25+
moves: ["e4", "e5", "Nf3", "Nc6", "Bc4", "Nf6", "Ng5", "d5", "exd5", "Nxd5", "Nxf7", "Kxf7", "Qf3+", "Ke6", "Nc3"],
26+
},
27+
{
28+
name: "Traxler Counterattack",
29+
moves: ["e4", "e5", "Nf3", "Nc6", "Bc4", "Nf6", "Ng5", "Bc5"],
30+
},
31+
{
32+
name: "Lolli Attack",
33+
moves: ["e4", "e5", "Nf3", "Nc6", "Bc4", "Nf6", "Ng5", "d5", "exd5", "Nxd5", "d4"],
34+
},
35+
{
36+
name: "Scotch Gambit",
37+
moves: ["e4", "e5", "Nf3", "Nc6", "Bc4", "Nf6", "d4"],
38+
},
39+
{
40+
name: "Hungarian Defense",
41+
moves: ["e4", "e5", "Nf3", "Nc6", "Bc4", "Be7"],
42+
},
43+
{
44+
name: "Paris Defense",
45+
moves: ["e4", "e5", "Nf3", "Nc6", "Bc4", "d6"],
46+
},
47+
{
48+
name: "Rousseau Gambit",
49+
moves: ["e4", "e5", "Nf3", "Nc6", "Bc4", "f5"],
50+
},
51+
{
52+
name: "Blackburne Shilling Gambit",
53+
moves: ["e4", "e5", "Nf3", "Nc6", "Bc4", "Nd4"],
54+
},
55+
{
56+
name: "Jerome Gambit",
57+
moves: ["e4", "e5", "Nf3", "Nc6", "Bc4", "Bc5", "Bxf7+", "Kxf7", "Nxe5+", "Nxe5", "Qh5+"],
58+
},
59+
{
60+
name: "Rosentreter Gambit",
61+
moves: ["e4", "e5", "Nf3", "Nc6", "Bc4", "Bc5", "d4", "exd4", "c3"],
62+
},
63+
{
64+
name: "Neumann Gambit",
65+
moves: ["e4", "e5", "Nf3", "Nc6", "c3", "Nf6", "Bc4"],
66+
},
67+
{
68+
name: "Alexandre Gambit",
69+
moves: ["e4", "e5", "Nf3", "Nc6", "Bc4", "Bc5", "c3", "f5"],
70+
},
71+
{
72+
name: "Lucchini Gambit",
73+
moves: ["e4", "e5", "Nf3", "Nc6", "Bc4", "Bc5", "d3", "f5"],
74+
},
75+
{
76+
name: "Ponziani-Steinitz Gambit",
77+
moves: ["e4", "e5", "Nf3", "Nc6", "Bc4", "Nf6", "Ng5", "Nxe4"],
78+
},
79+
{
80+
name: "Kloss Gambit",
81+
moves: ["e4", "e5", "Nf3", "Nc6", "Bc4", "Nf6", "Ng5", "d5", "exd5", "Nb4"],
82+
},
83+
{
84+
name: "Fegatello Attack",
85+
moves: ["e4", "e5", "Nf3", "Nc6", "Bc4", "Nf6", "Ng5", "d5", "exd5", "Nxd5", "Nxf7", "Kxf7", "Qf3+", "Ke6", "Nc3"],
86+
},
87+
];

0 commit comments

Comments
 (0)