fixed bug w random pronoun picking at start
This commit is contained in:
parent
e415dd67c5
commit
299aa0ca68
|
@ -19,9 +19,7 @@ function NPPicker({ np, onChange, counterPart, asObject }: { onChange: (nps: NPS
|
||||||
}
|
}
|
||||||
function handleNPTypeChange(ntp: NPType) {
|
function handleNPTypeChange(ntp: NPType) {
|
||||||
if (ntp === "pronoun") {
|
if (ntp === "pronoun") {
|
||||||
const person = ((typeof counterPart === "object") && (counterPart.type === "pronoun"))
|
const person = randomPerson({ counterPart });
|
||||||
? randomPerson({ counterPart: counterPart.person })
|
|
||||||
: randomPerson();
|
|
||||||
const pronoun: PronounSelection = {
|
const pronoun: PronounSelection = {
|
||||||
type: "pronoun",
|
type: "pronoun",
|
||||||
person,
|
person,
|
||||||
|
|
|
@ -54,6 +54,7 @@ export function PhraseBuilder() {
|
||||||
const [subject, setSubject] = useState<NPSelection | undefined>(undefined);
|
const [subject, setSubject] = useState<NPSelection | undefined>(undefined);
|
||||||
const [verb, setVerb] = useState<VerbSelection | undefined>(undefined);
|
const [verb, setVerb] = useState<VerbSelection | undefined>(undefined);
|
||||||
function handleSubjectChange(subject: NPSelection | undefined) {
|
function handleSubjectChange(subject: NPSelection | undefined) {
|
||||||
|
// check for pronoun conflict
|
||||||
const objPronoun = (typeof verb?.object === "object" && verb.object.type === "pronoun")
|
const objPronoun = (typeof verb?.object === "object" && verb.object.type === "pronoun")
|
||||||
? verb.object.person
|
? verb.object.person
|
||||||
: undefined;
|
: undefined;
|
||||||
|
@ -71,6 +72,7 @@ export function PhraseBuilder() {
|
||||||
function handleObjectChange(object: NPSelection | undefined) {
|
function handleObjectChange(object: NPSelection | undefined) {
|
||||||
if (!verb) return;
|
if (!verb) return;
|
||||||
if ((verb.object === "none") || (typeof verb.object === "number")) 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)) {
|
if (object?.type === "pronoun" && subject?.type === "pronoun" && isInvalidSubjObjCombo(object.person, subject.person)) {
|
||||||
alert("That combination of pronouns is not allowed");
|
alert("That combination of pronouns is not allowed");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -21,23 +21,12 @@ function VPDisplay({ VP }: { VP: VPSelection }) {
|
||||||
const [form, setForm] = useState<FormVersion>({ removeKing: false, shrinkServant: false });
|
const [form, setForm] = useState<FormVersion>({ removeKing: false, shrinkServant: false });
|
||||||
// TODO: Possibly put the servant shrinking in here after the render
|
// TODO: Possibly put the servant shrinking in here after the render
|
||||||
const result = compileVP(renderVP(VP), form);
|
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">
|
return <div className="text-center mt-2">
|
||||||
<AbbreviationFormSelector adjustable={adjustable} form={form} onChange={setForm} />
|
<AbbreviationFormSelector
|
||||||
|
adjustable={whatsAdjustable(VP)}
|
||||||
|
form={form}
|
||||||
|
onChange={setForm}
|
||||||
|
/>
|
||||||
{/* <button
|
{/* <button
|
||||||
onClick={toggleForm("removeKing")}
|
onClick={toggleForm("removeKing")}
|
||||||
className={buttonClass(form.removeKing, "l")}
|
className={buttonClass(form.removeKing, "l")}
|
||||||
|
@ -69,6 +58,17 @@ function VPDisplay({ VP }: { VP: VPSelection }) {
|
||||||
</div>
|
</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[] }) {
|
function VariationLayer({ vs }: { vs: T.PsString[] }) {
|
||||||
return <div className="mb-2">
|
return <div className="mb-2">
|
||||||
{vs.map((r, i) => <div key={i}>
|
{vs.map((r, i) => <div key={i}>
|
||||||
|
|
|
@ -15,25 +15,28 @@ function getRandPers(): T.Person {
|
||||||
return Math.floor(Math.random() * 12);
|
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;
|
let newP = 0;
|
||||||
do {
|
do {
|
||||||
newP = getRandPers();
|
newP = getRandPers();
|
||||||
} while (
|
} while (newP === a.prev);
|
||||||
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))
|
|
||||||
))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
return newP;
|
return newP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue