diff --git a/package.json b/package.json index 44b856c..b729408 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "dependencies": { "@fortawesome/fontawesome-free": "^5.15.4", "@lingdocs/lingdocs-main": "^0.2.0", - "@lingdocs/pashto-inflector": "^2.4.9", + "@lingdocs/pashto-inflector": "^2.5.1", "@testing-library/jest-dom": "^5.11.4", "@testing-library/react": "^11.1.0", "@testing-library/user-event": "^12.1.10", diff --git a/src/games/games.tsx b/src/games/games.tsx index f48aeec..5b465b4 100644 --- a/src/games/games.tsx +++ b/src/games/games.tsx @@ -84,11 +84,18 @@ export const equativeGamePastSubjunctive = makeGameRecord( (id, link) => () => , ); -export const equativeGameAll = makeGameRecord( - 'Write the equative (summary)', - "equative-past-summary", +export const equativeGameAllIdentify = makeGameRecord( + "Identify the equative (all tenses)", + "equative-past-summary-identify", "/equatives/other-equatives", - (id, link) => () => , + (id, link) => () => , +); + +export const equativeGameAllProduce = makeGameRecord( + "Write the equative (all tenses)", + "equative-past-summary-produce", + "/equatives/other-equatives", + (id, link) => () => , ); const games: { chapter: string, items: GameRecord[] }[] = [ @@ -110,7 +117,8 @@ const games: { chapter: string, items: GameRecord[] }[] = [ equativeGamePast, equativeGameWouldBe, equativeGamePastSubjunctive, - equativeGameAll, + equativeGameAllIdentify, + equativeGameAllProduce, ], }, ]; diff --git a/src/games/sub-cores/EquativeGame.tsx b/src/games/sub-cores/EquativeGame.tsx index b818313..688ce7b 100644 --- a/src/games/sub-cores/EquativeGame.tsx +++ b/src/games/sub-cores/EquativeGame.tsx @@ -18,6 +18,7 @@ import { InlinePs, grammarUnits, } from "@lingdocs/pashto-inflector"; +import { psStringEquals } from "@lingdocs/pashto-inflector/dist/lib/p-text-helpers"; const kidsColor = "#017BFE"; @@ -52,9 +53,9 @@ const amount = 20; const timeLimit = 75; type Question = { - phrase: { ps: T.PsString, e?: string[] }, + EPS: T.EPSelectionComplete, + phrase: { ps: T.PsString[], e?: string[] }, equative: T.EquativeRendered, - tense: T.EquativeTense, }; const pronounTypes = [ @@ -67,7 +68,7 @@ const pronounTypes = [ [T.Person.ThirdPlurMale, T.Person.ThirdPlurFemale], ]; -export default function EquativeGame({ id, link, level }: { id: string, link: string, level: T.EquativeTense | "all" }) { +export default function EquativeGame({ id, link, level }: { id: string, link: string, level: T.EquativeTense | "allProduce" | "allIdentify" }) { function* questions (): Generator> { let pool = [...pronounTypes]; function makeRandPronoun(): T.PronounSelection { @@ -95,8 +96,7 @@ export default function EquativeGame({ id, link, level }: { id: string, link: st number: n.numberCanChange ? randFromArray(["singular", "plural"]) : n.number, }; } - for (let i = 0; i < amount; i++) { - console.log("one factory call"); + function makeRandomEPS(): T.EPSelectionComplete { const subj = randFromArray([ makeRandPronoun, makeRandPronoun, @@ -104,20 +104,29 @@ export default function EquativeGame({ id, link, level }: { id: string, link: st makeRandPronoun, ])(); const pred = randFromArray([...adjectives, ...locAdverbs]); - const tense = level === "all" ? randFromArray(tenses) : level; - const EPS = makeEPS(subj, pred, tense); - const rendered = renderEP(EPS); - const compiled = compileEP(rendered, true, { equative: true, ba: false, kidsSection: true }); + const tense = (level === "allIdentify" || level === "allProduce") + ? randFromArray(tenses) + : level; + return makeEPS(subj, pred, tense); + } + for (let i = 0; i < amount; i++) { + const EPS = makeRandomEPS(); + const EP = renderEP(EPS); + const compiled = compileEP( + EP, + true, + level === "allIdentify" ? undefined : { equative: true, kidsSection: true }, + ); const phrase = { - ps: compiled.ps[0], - e: compiled.e, + ps: compiled.ps, + e: level === "allIdentify" ? undefined : compiled.e, }; yield { progress: makeProgress(i, amount), question: { + EPS, phrase, - equative: rendered.equative, - tense, + equative: EP.equative, }, }; }; @@ -140,20 +149,60 @@ export default function EquativeGame({ id, link, level }: { id: string, link: st } callback(!correct ? makeCorrectAnswer(question) : true); } + const handleTenseIdentify = (tense: T.EquativeTense) => { + const renderedWAnswer = renderEP({ + ...question.EPS, + equative: { + ...question.EPS.equative, + tense, + }, + }); + const compiledWAnswer = compileEP(renderedWAnswer, true); + const wasCorrect = compiledWAnswer.ps.some(a => ( + question.phrase.ps.some(b => psStringEquals(a, b)) + )); + if (wasCorrect) { + return callback(wasCorrect); + } else { + callback(
+ {humanReadableTense(question.EPS.equative.tense)} +
) + } + } useEffect(() => { - if (level === "all") setWithBa(false); + if (level === "allProduce") setWithBa(false); }, [question]); return
-
- {/* @ts-ignore */} - - {question.phrase.e && question.phrase.e.map((e, i) => ( -
{e}
- ))} -
{humanReadableTense(question.tense)} equative
-
-
+ {level === "allIdentify" ? +
+ + {randFromArray(question.phrase.ps)} + +
+ :
+ + {/* @ts-ignore TODO: REMOVE AS P_INFLE */} + {modExs(question.phrase.ps, withBa)[0]} + + {question.phrase.e && question.phrase.e.map((e, i) => ( +
{e}
+ ))} +
{humanReadableTense(question.EPS.equative.tense)} equative
+
+ } + {level === "allIdentify" ?
+
+ {tenses.map(t =>
+ +
)} +
+
:
Enter to check
*/}
- - + } } function Instructions() { return
-

Fill in the blank with the correct {humanReadableTense(level)} equative in Pashto script

- {level === "all" &&
⚠ All tenses included...
} + {level === "allProduce" + ?

Fill in the blank with the correct {humanReadableTense(level)} equative in Pashto script

+ :

Identify a correct tense for each equative phrase you see

} + {level === "allProduce" &&
⚠ All tenses included...
}
} @@ -203,7 +253,7 @@ export default function EquativeGame({ id, link, level }: { id: string, link: st questions={questions} id={id} Display={Display} - timeLimit={level === "all" ? timeLimit * 1.4 : timeLimit} + timeLimit={level === "allProduce" ? timeLimit * 1.4 : timeLimit} Instructions={Instructions} /> }; @@ -239,8 +289,8 @@ function modExs(exs: T.PsString[], withBa: boolean): { p: JSX.Element, f: JSX.El }); } -function humanReadableTense(tense: T.EquativeTense | "all"): string { - return tense === "all" +function humanReadableTense(tense: T.EquativeTense | "allProduce"): string { + return tense === "allProduce" ? "" : tense === "pastSubjunctive" ? "past subjunctive"