괄호 안의 항을 2, 3, 4 항으로 설정하는 기능 추가
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
generateVariableParenthesisSession,
|
||||
gradeVariableParenthesisAnswer,
|
||||
} from "@/lib/engine/variable-parenthesis";
|
||||
import type { VariableParenthesisTermCount } from "@/lib/engine/variable-parenthesis";
|
||||
import type {
|
||||
VariableGradeResult,
|
||||
VariableParenthesisProblem,
|
||||
@@ -14,44 +15,59 @@ export interface VariableGameSession {
|
||||
problems: VariableParenthesisProblem[];
|
||||
currentIndex: number;
|
||||
results: (VariableGradeResult | null)[];
|
||||
termCount: VariableParenthesisTermCount;
|
||||
}
|
||||
|
||||
export type VariableProblemCount = 5 | 10;
|
||||
export type VariableMaxTermCount = VariableParenthesisTermCount;
|
||||
|
||||
interface VariableGameState {
|
||||
session: VariableGameSession | null;
|
||||
selectedProblemCount: VariableProblemCount;
|
||||
selectedMaxTermCount: VariableMaxTermCount;
|
||||
setProblemCount: (count: VariableProblemCount) => void;
|
||||
initSession: (count?: VariableProblemCount) => void;
|
||||
setMaxTermCount: (count: VariableMaxTermCount) => void;
|
||||
initSession: (
|
||||
count?: VariableProblemCount,
|
||||
maxTermCount?: VariableMaxTermCount,
|
||||
) => void;
|
||||
submitAnswer: (answer: VariableUserAnswer) => void;
|
||||
nextProblem: () => void;
|
||||
resetSession: () => void;
|
||||
}
|
||||
|
||||
const DEFAULT_SESSION_COUNT: VariableProblemCount = 10;
|
||||
const DEFAULT_MAX_TERM_COUNT: VariableMaxTermCount = 2;
|
||||
|
||||
function createSession(
|
||||
count: VariableProblemCount = DEFAULT_SESSION_COUNT,
|
||||
maxTermCount: VariableMaxTermCount = DEFAULT_MAX_TERM_COUNT,
|
||||
): VariableGameSession {
|
||||
const problems = generateVariableParenthesisSession(count);
|
||||
const problems = generateVariableParenthesisSession(count, maxTermCount);
|
||||
|
||||
return {
|
||||
problems,
|
||||
currentIndex: 0,
|
||||
results: problems.map(() => null),
|
||||
termCount: maxTermCount,
|
||||
};
|
||||
}
|
||||
|
||||
export const useVariableGameStore = create<VariableGameState>((set, get) => ({
|
||||
session: null,
|
||||
selectedProblemCount: DEFAULT_SESSION_COUNT,
|
||||
selectedMaxTermCount: DEFAULT_MAX_TERM_COUNT,
|
||||
setProblemCount: (count) => {
|
||||
set({ selectedProblemCount: count });
|
||||
},
|
||||
initSession: (count) => {
|
||||
setMaxTermCount: (count) => {
|
||||
set({ selectedMaxTermCount: count });
|
||||
},
|
||||
initSession: (count, maxTermCount) => {
|
||||
const selectedProblemCount = count ?? get().selectedProblemCount;
|
||||
const selectedMaxTermCount = maxTermCount ?? get().selectedMaxTermCount;
|
||||
|
||||
set({ session: createSession(selectedProblemCount) });
|
||||
set({ session: createSession(selectedProblemCount, selectedMaxTermCount) });
|
||||
},
|
||||
submitAnswer: (answer) => {
|
||||
const { session } = get();
|
||||
@@ -85,6 +101,11 @@ export const useVariableGameStore = create<VariableGameState>((set, get) => ({
|
||||
});
|
||||
},
|
||||
resetSession: () => {
|
||||
set({ session: createSession(get().selectedProblemCount) });
|
||||
set({
|
||||
session: createSession(
|
||||
get().selectedProblemCount,
|
||||
get().selectedMaxTermCount,
|
||||
),
|
||||
});
|
||||
},
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user