From 45f901fb62e749b6390bc5eb2b344bfd1dc524b8 Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Sat, 3 Sep 2022 15:40:28 +0400 Subject: [PATCH] refactor to clean up game creation and dont have the study button on the in chapter appearance --- src/games/GameCore.tsx | 7 +- src/games/GameDisplay.tsx | 2 +- src/games/GamesBrowser.tsx | 4 +- src/games/games.tsx | 303 +++++++++++++------------ src/games/sub-cores/EquativeGame.tsx | 3 +- src/games/sub-cores/GenderGame.tsx | 13 +- src/games/sub-cores/UnisexNounGame.tsx | 3 +- src/games/sub-cores/VerbGame.tsx | 8 +- src/types/game-types.d.ts | 10 +- 9 files changed, 193 insertions(+), 160 deletions(-) diff --git a/src/games/GameCore.tsx b/src/games/GameCore.tsx index 82c5ce3..81d841d 100644 --- a/src/games/GameCore.tsx +++ b/src/games/GameCore.tsx @@ -26,7 +26,8 @@ const errorVibration = 200; const maxStrikes = 2; -function GameCore({ questions, Display, timeLimit, Instructions, studyLink, id }:{ +function GameCore({ inChapter, questions, Display, timeLimit, Instructions, studyLink, id }:{ + inChapter: boolean, id: string, studyLink: string, Instructions: (props: { opts?: Types.TextOptions }) => JSX.Element, @@ -200,9 +201,9 @@ function GameCore({ questions, Display, timeLimit, Instructions, studyLink, i
- + {!inChapter && - + }
diff --git a/src/games/GameDisplay.tsx b/src/games/GameDisplay.tsx index eeac3c3..d554e63 100644 --- a/src/games/GameDisplay.tsx +++ b/src/games/GameDisplay.tsx @@ -15,7 +15,7 @@ function GameDisplay({ record: { title, Game, id } }: { record: GameRecord }) {

{completed ? "✅" : ""}

- + ; } diff --git a/src/games/GamesBrowser.tsx b/src/games/GamesBrowser.tsx index e19aeb3..88c9cd5 100644 --- a/src/games/GamesBrowser.tsx +++ b/src/games/GamesBrowser.tsx @@ -48,7 +48,7 @@ function ChapterDisplay({ chapter, user, handleClick, expanded }: { - {chapter.items.map(({ id, title, Game, studyLink }) => { + {chapter.items.map(({ id, title, Game }) => { const done = user && user.tests.some(t => t.id === id); const open = opened === id; return
@@ -64,7 +64,7 @@ function ChapterDisplay({ chapter, user, handleClick, expanded }: {
- + })} diff --git a/src/games/games.tsx b/src/games/games.tsx index a02d979..bb9e0ec 100644 --- a/src/games/games.tsx +++ b/src/games/games.tsx @@ -3,152 +3,151 @@ import VerbGame from "./sub-cores/VerbGame"; import GenderGame from "./sub-cores/GenderGame"; import UnisexNounGame from "./sub-cores/UnisexNounGame"; -function makeGameRecord( - title: string, - id: string, - studyLink: string, - game: (id: string, link: string) => () => JSX.Element, -): GameRecord { - return { - title, - studyLink, - id, - Game: game(id, studyLink), - } -} +// NOUNS +export const nounGenderGame1 = makeGameRecord({ + title: "Identify Noun Genders - Level 1", + id: "gender-nouns-1", + link: "/nouns/nouns-gender#gender-by-ending", + level: 1, + SubCore: GenderGame, +}); +export const nounGenderGame2 = makeGameRecord({ + title: "Identify Noun Genders - Level 2", + id: "gender-nouns-2", + link: "/nouns/nouns-gender#exceptions", + level: 2, + SubCore: GenderGame, +}); +export const unisexNounGame = makeGameRecord({ + title: "Changing genders on unisex nouns", + id: "unisex-nouns-1", + link: "/nouns/nouns-unisex/", + level: undefined, + SubCore: UnisexNounGame, +}); -export const presentVerbGame = makeGameRecord( - "Write the present verb", - "present-verbs-write", - "/verbs/present-verbs/", - (id, link) => () => -); -export const subjunctiveVerbGame = makeGameRecord( - "Write the subjunctive verb", - "subjunctive-verbs-write", - "/verbs/subjunctive-verbs/", - (id, link) => () => -); -export const futureVerbGame = makeGameRecord( - "Write the future verb", - "future-verbs-write", - "/verbs/future-verbs/", - (id, link) => () => -); -export const imperativeVerbGame = makeGameRecord( - "Write the imperative verb", - "imperative-verbs-write", - "/verbs/imperative-verbs/", - (id, link) => () => -); -export const intransitivePerfectivePastVerbGame = makeGameRecord( - "Write the intransitive simple past verb", - "intransitive-perfective-past-verbs-write", - "/verbs/past-verbs/#past-tense-with-transitive-verbs-", - (id, link) => () => -); -export const intransitiveImperfectivePastVerbGame = makeGameRecord( - "Write the intransitive continuous past verb", - "transitive-imperfective-past-verbs-write", - "/verbs/past-verbs/#past-tense-with-transitive-verbs-", - (id, link) => () => -); +// EQUATIVES +export const equativeGamePresent = makeGameRecord({ + title: "Write the present equative", + id: "equative-present", + link: "/equatives/present-equative/", + level: "present", + SubCore: EquativeGame, +}); +export const equativeGameHabitual = makeGameRecord({ + title: "Write the habitual equative", + id: "equative-habitual", + link: "/equatives/habitual-equative/", + level: "habitual", + SubCore: EquativeGame, +}); +export const equativeGameSubjunctive = makeGameRecord({ + title: "Write the subjunctive equative", + id: "equative-subjunctive", + link: "/equatives/other-equatives/#subjunctive-equative", + level: "subjunctive", + SubCore: EquativeGame, +}); +export const equativeGameFuture = makeGameRecord({ + title: "Write the future equative", + id: "equative-future", + link: "/equatives/other-equatives/#future-equative", + level: "future", + SubCore: EquativeGame, +}); +export const equativeGamePast = makeGameRecord({ + title: "Write the past equative", + id: "equative-past", + link: "/equatives/other-equatives/#past-equative", + level: "past", + SubCore: EquativeGame, +}); +export const equativeGameWouldBe = makeGameRecord({ + title: 'Write the "would be" equative', + id: "equative-would-be", + link: "/equatives/other-equatives/#would-be-equative", + level: "wouldBe", + SubCore: EquativeGame, +}); +export const equativeGamePastSubjunctive = makeGameRecord({ + title: 'Write the past subjunctive equative', + id: "equative-past-subjunctive", + link: "/equatives/other-equatives/#past-subjunctive", + level: "pastSubjunctive", + SubCore: EquativeGame, +}); +export const equativeGameWouldHaveBeen = makeGameRecord({ + title: 'Write the "would have been" equative', + id: "equative-would-have-been", + link: "/equatives/other-equatives/#wold-have-been-equative", + level: "wouldHaveBeen", + SubCore: EquativeGame, +}); +export const equativeGameAllIdentify = makeGameRecord({ + title: "Identify the equative (all tenses)", + id: "equative-past-summary-identify", + link: "/equatives/other-equatives", + level: "allIdentify", + SubCore: EquativeGame, +}); +export const equativeGameSituations = makeGameRecord({ + title: "Choose the right equative for the situation", + id: "equative-past-situations", + link: "/equatives/other-equatives", + level: "situations", + SubCore: EquativeGame, +}); +export const equativeGameAllProduce = makeGameRecord({ + title: "Write the equative (all tenses)", + id: "equative-past-summary-produce", + link: "/equatives/other-equatives", + level: "allProduce", + SubCore: EquativeGame, +}); -export const nounGenderGame1 = makeGameRecord( - "Identify Noun Genders - Level 1", - "gender-nouns-1", - "/nouns/nouns-gender#gender-by-ending", - (id, link) => () => , -); -export const nounGenderGame2 = makeGameRecord( - "Identify Noun Genders - Level 2", - "gender-nouns-2", - "/nouns/nouns-gender#exceptions", - (id, link) => () => , -); -export const unisexNounGame = makeGameRecord( - "Changing genders on unisex nouns", - "unisex-nouns-1", - "/nouns/nouns-unisex/", - (id, link) => () => , -); - -export const equativeGamePresent = makeGameRecord( - "Write the present equative", - "equative-present", - "/equatives/present-equative/", - (id, link) => () => , -); - -export const equativeGameHabitual = makeGameRecord( - "Write the habitual equative", - "equative-habitual", - "/equatives/habitual-equative/", - (id, link) => () => , -); - -export const equativeGameSubjunctive = makeGameRecord( - "Write the subjunctive equative", - "equative-subjunctive", - "/equatives/other-equatives/#subjunctive-equative", - (id, link) => () => , -); - -export const equativeGameFuture = makeGameRecord( - "Write the future equative", - "equative-future", - "/equatives/other-equatives/#future-equative", - (id, link) => () => , -); - -export const equativeGamePast = makeGameRecord( - "Write the past equative", - "equative-past", - "/equatives/other-equatives/#past-equative", - (id, link) => () => , -); - -export const equativeGameWouldBe = makeGameRecord( - 'Write the "would be" equative', - "equative-would-be", - "/equatives/other-equatives/#would-be-equative", - (id, link) => () => , -); - -export const equativeGamePastSubjunctive = makeGameRecord( - 'Write the past subjunctive equative', - "equative-past-subjunctive", - "/equatives/other-equatives/#past-subjunctive", - (id, link) => () => , -); - -export const equativeGameWouldHaveBeen = makeGameRecord( - 'Write the "would have been" equative', - "equative-would-have-been", - "/equatives/other-equatives/#wold-have-been-equative", - (id, link) => () => , -); - -export const equativeGameAllIdentify = makeGameRecord( - "Identify the equative (all tenses)", - "equative-past-summary-identify", - "/equatives/other-equatives", - (id, link) => () => , -); - -export const equativeGameSituations = makeGameRecord( - "Choose the right equative for the situation", - "equative-past-situations", - "/equatives/other-equatives", - (id, link) => () => , -); - -export const equativeGameAllProduce = makeGameRecord( - "Write the equative (all tenses)", - "equative-past-summary-produce", - "/equatives/other-equatives", - (id, link) => () => , -); +// VERBS +export const presentVerbGame = makeGameRecord({ + title: "Write the present verb", + id: "present-verbs-write", + link: "/verbs/present-verbs/", + level: "presentVerb", + SubCore: VerbGame, +}); +export const subjunctiveVerbGame = makeGameRecord({ + title: "Write the subjunctive verb", + id: "subjunctive-verbs-write", + link: "/verbs/subjunctive-verbs/", + level: "subjunctiveVerb", + SubCore: VerbGame, +}); +export const futureVerbGame = makeGameRecord({ + title: "Write the future verb", + id: "future-verbs-write", + link: "/verbs/future-verbs/", + level: "futureVerb", + SubCore: VerbGame, +}); +export const imperativeVerbGame = makeGameRecord({ + title: "Write the imperative verb", + id: "imperative-verbs-write", + link: "/verbs/imperative-verbs/", + level: "imperative", + SubCore: VerbGame, +}); +export const intransitivePerfectivePastVerbGame = makeGameRecord({ + title: "Write the intransitive simple past verb", + id: "intransitive-perfective-past-verbs-write", + link: "/verbs/past-verbs/#past-tense-with-transitive-verbs-", + level: "intransitivePerfectivePast", + SubCore: VerbGame, +}); +export const intransitiveImperfectivePastVerbGame = makeGameRecord({ + title: "Write the intransitive continuous past verb", + id: "transitive-imperfective-past-verbs-write", + link: "/verbs/past-verbs/#past-tense-with-transitive-verbs-", + level: "intransitiveImperfectivePast", + SubCore: VerbGame, +}); const games: { chapter: string, items: GameRecord[] }[] = [ { @@ -189,3 +188,19 @@ const games: { chapter: string, items: GameRecord[] }[] = [ ]; export default games; + +function makeGameRecord({ title, id, link, level, SubCore }:{ + title: string, + id: string, + link: string, + level: T, + SubCore: GameSubCore, +}): GameRecord { + return { + title, + id, + Game: ({ inChapter }: { inChapter: boolean }) => ( + + ), + } +} diff --git a/src/games/sub-cores/EquativeGame.tsx b/src/games/sub-cores/EquativeGame.tsx index 4ee7dfb..91d9327 100644 --- a/src/games/sub-cores/EquativeGame.tsx +++ b/src/games/sub-cores/EquativeGame.tsx @@ -189,7 +189,7 @@ const pronounTypes = [ [T.Person.ThirdPlurMale, T.Person.ThirdPlurFemale], ]; -export default function EquativeGame({ id, link, level }: { id: string, link: string, level: T.EquativeTense | "allProduce" | "allIdentify" | "situations" }) { +export default function EquativeGame({ inChapter, id, link, level }: { inChapter: boolean, id: string, link: string, level: T.EquativeTense | "allProduce" | "allIdentify" | "situations" }) { function* questions (): Generator> { let pool = [...pronounTypes]; let situationPool = [...situations]; @@ -414,6 +414,7 @@ export default function EquativeGame({ id, link, level }: { id: string, link: st } return = { }; const amount = 35; +type Question = T.DictionaryEntry; -export default function GenderGame({level, id, link }: { level: 1 | 2, id: string, link: string }) { - function* questions () { +export default function GenderGame({level, id, link, inChapter }: { + inChapter: boolean, + level: 1 | 2, id: string, + link: string, +}) { + function* questions (): Generator> { const wordPool = {...types}; const exceptionsPool = {...exceptions}; console.log(exceptionsPool); @@ -108,8 +113,7 @@ export default function GenderGame({level, id, link }: { level: 1 | 2, id: strin }; } } - - function Display({ question, callback }: QuestionDisplayProps) { + function Display({ question, callback }: QuestionDisplayProps) { function check(gender: T.Gender) { const nounGender: T.Gender = nounNotIn(mascNouns)(question) ? "fem" : "masc"; const correct = gender === nounGender; @@ -146,6 +150,7 @@ export default function GenderGame({level, id, link }: { level: 1 | 2, id: strin } return > { let pool = { ...types }; for (let i = 0; i < amount; i++) { @@ -129,6 +129,7 @@ export default function UnisexNounGame({ id, link }: { id: string, link: string } return = ({ id, link, level, inChapter }: { + inChapter: boolean, id: string, link: string, level: VerbGameLevel, - }) { + }) => { function* questions (): Generator> { const personPool = makePool(level === "imperative" ? secondPersons @@ -248,6 +249,7 @@ export default function VerbGame({ id, link, level }: { } return }; +export default VerbGame; + function QuestionDisplay({ question, userAnswer }: { question: Question, userAnswer: { withBa: boolean, answer: string }, diff --git a/src/types/game-types.d.ts b/src/types/game-types.d.ts index e083dd9..9bdf607 100644 --- a/src/types/game-types.d.ts +++ b/src/types/game-types.d.ts @@ -8,6 +8,13 @@ type Current = { question: T, }; +type GameSubCore = (props: { + inChapter: boolean, + id: string, + level: T, + link: string; +}) => JSX.Element; + type QuestionGenerator = Generator, void, unknown>; type QuestionDisplayProps = { @@ -18,6 +25,5 @@ type QuestionDisplayProps = { type GameRecord = { title: string, id: string, - studyLink: string, - Game: () => JSX.Element, + Game: (props: { inChapter: boolean }) => JSX.Element, };