fixed bug w random pronoun picking at start

This commit is contained in:
lingdocs 2022-03-27 15:47:40 +05:00
parent e415dd67c5
commit 299aa0ca68
4 changed files with 38 additions and 35 deletions

View File

@ -19,9 +19,7 @@ function NPPicker({ np, onChange, counterPart, asObject }: { onChange: (nps: NPS
}
function handleNPTypeChange(ntp: NPType) {
if (ntp === "pronoun") {
const person = ((typeof counterPart === "object") && (counterPart.type === "pronoun"))
? randomPerson({ counterPart: counterPart.person })
: randomPerson();
const person = randomPerson({ counterPart });
const pronoun: PronounSelection = {
type: "pronoun",
person,

View File

@ -54,6 +54,7 @@ export function PhraseBuilder() {
const [subject, setSubject] = useState<NPSelection | undefined>(undefined);
const [verb, setVerb] = useState<VerbSelection | undefined>(undefined);
function handleSubjectChange(subject: NPSelection | undefined) {
// check for pronoun conflict
const objPronoun = (typeof verb?.object === "object" && verb.object.type === "pronoun")
? verb.object.person
: undefined;
@ -71,6 +72,7 @@ export function PhraseBuilder() {
function handleObjectChange(object: NPSelection | undefined) {
if (!verb) return;
if ((verb.object === "none") || (typeof verb.object === "number")) return;
// check for pronoun conflict
if (object?.type === "pronoun" && subject?.type === "pronoun" && isInvalidSubjObjCombo(object.person, subject.person)) {
alert("That combination of pronouns is not allowed");
return;

View File

@ -21,23 +21,12 @@ function VPDisplay({ VP }: { VP: VPSelection }) {
const [form, setForm] = useState<FormVersion>({ removeKing: false, shrinkServant: false });
// TODO: Possibly put the servant shrinking in here after the render
const result = compileVP(renderVP(VP), form);
// const servantShrinkable = VP.object && VP.object !== "none";
// const toggleForm = (f: "removeKing" | "shrinkServant") => () => {
// setForm(oForm => ({
// ...oForm,
// [f]: !oForm[f],
// }));
// }
const adjustable = VP.verb.transitivity === "transitive"
? "both"
: VP.verb.transitivity === "intransitive"
? "king"
// grammTrans
: isPastTense(VP.verb.tense)
? "servant"
: "king";
return <div className="text-center mt-2">
<AbbreviationFormSelector adjustable={adjustable} form={form} onChange={setForm} />
<AbbreviationFormSelector
adjustable={whatsAdjustable(VP)}
form={form}
onChange={setForm}
/>
{/* <button
onClick={toggleForm("removeKing")}
className={buttonClass(form.removeKing, "l")}
@ -69,6 +58,17 @@ function VPDisplay({ VP }: { VP: VPSelection }) {
</div>
}
function whatsAdjustable(VP: VPSelection): "both" | "king" | "servant" {
return VP.verb.transitivity === "transitive"
? "both"
: VP.verb.transitivity === "intransitive"
? "king"
// grammTrans
: isPastTense(VP.verb.tense)
? "servant"
: "king";
}
function VariationLayer({ vs }: { vs: T.PsString[] }) {
return <div className="mb-2">
{vs.map((r, i) => <div key={i}>

View File

@ -15,25 +15,28 @@ function getRandPers(): T.Person {
return Math.floor(Math.random() * 12);
}
export function randomPerson(a?: { old?: T.Person, counterPart?: T.Person | VerbObject }) {
export function randomPerson(a?: { prev?: T.Person, counterPart?: VerbObject | NPSelection }) {
// no restrictions, just get any person
if (!a) {
return getRandPers();
}
if (a.counterPart !== undefined && typeof a.counterPart === "object" && a.counterPart.type === "pronoun") {
// with counterpart pronoun
let newP = 0;
do {
newP = getRandPers();
} while (
isInvalidSubjObjCombo(a.counterPart.person, newP)
||
(newP === a.prev)
);
return newP;
}
// without counterpart pronoun, just previous
let newP = 0;
do {
newP = getRandPers();
} while (
a &&
(
((a.old !== undefined) && newP === a.old) ||
(a.counterPart && (
(
(typeof a.counterPart === "object")
&& a.counterPart.type === "pronoun"
&& isInvalidSubjObjCombo(a.counterPart.person, newP)
)
||
((typeof a?.counterPart === "number") && isInvalidSubjObjCombo(a.counterPart, newP))
))
)
);
} while (newP === a.prev);
return newP;
}