better handling of non-gendered source objects
This commit is contained in:
parent
f9deefa15c
commit
e8aafa0dae
2 changed files with 27 additions and 14 deletions
|
|
@ -101,7 +101,7 @@ class GenderCharacter(DefaultCharacter):
|
||||||
super().at_object_creation()
|
super().at_object_creation()
|
||||||
self.db.gender = "ambiguous"
|
self.db.gender = "ambiguous"
|
||||||
|
|
||||||
def _get_pronoun(self, regex_match):
|
def _get_pronoun(self, regex_match, source=None):
|
||||||
"""
|
"""
|
||||||
Get pronoun from the pronoun marker in the text. This is used as
|
Get pronoun from the pronoun marker in the text. This is used as
|
||||||
the callable for the re.sub function.
|
the callable for the re.sub function.
|
||||||
|
|
@ -116,8 +116,10 @@ class GenderCharacter(DefaultCharacter):
|
||||||
- `|a`, `|A`: Absolute Possessive form: his, hers, its, His, Hers, Its, Theirs
|
- `|a`, `|A`: Absolute Possessive form: his, hers, its, His, Hers, Its, Theirs
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
if not source:
|
||||||
|
source = self
|
||||||
typ = regex_match.group()[1] # "s", "O" etc
|
typ = regex_match.group()[1] # "s", "O" etc
|
||||||
gender = self.attributes.get("gender", default="ambiguous")
|
gender = source.attributes.get("gender", default="ambiguous")
|
||||||
gender = gender if gender in ("male", "female", "neutral") else "ambiguous"
|
gender = gender if gender in ("male", "female", "neutral") else "ambiguous"
|
||||||
pronoun = _GENDER_PRONOUN_MAP[gender][typ.lower()]
|
pronoun = _GENDER_PRONOUN_MAP[gender][typ.lower()]
|
||||||
return pronoun.capitalize() if typ.isupper() else pronoun
|
return pronoun.capitalize() if typ.isupper() else pronoun
|
||||||
|
|
@ -147,14 +149,16 @@ class GenderCharacter(DefaultCharacter):
|
||||||
super().msg(from_obj=from_obj, session=session, **kwargs)
|
super().msg(from_obj=from_obj, session=session, **kwargs)
|
||||||
return
|
return
|
||||||
|
|
||||||
gender_source = from_obj if from_obj else self
|
|
||||||
|
|
||||||
if hasattr(gender_source, "_get_pronoun"):
|
|
||||||
try:
|
try:
|
||||||
if text and isinstance(text, tuple):
|
if text and isinstance(text, tuple):
|
||||||
text = (_RE_GENDER_PRONOUN.sub(gender_source._get_pronoun, text[0]), *text[1:])
|
text = (
|
||||||
|
_RE_GENDER_PRONOUN.sub(
|
||||||
|
lambda x: self._get_pronoun(x, source=from_obj), text[0]
|
||||||
|
),
|
||||||
|
*text[1:],
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
text = _RE_GENDER_PRONOUN.sub(gender_source._get_pronoun, text)
|
text = _RE_GENDER_PRONOUN.sub(lambda x: self._get_pronoun(x, source=from_obj), text)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
|
|
@ -54,3 +54,12 @@ class TestGenderSub(BaseEvenniaCommandTest):
|
||||||
self.assertIn("Test his gender", mock_msg.call_args.args)
|
self.assertIn("Test his gender", mock_msg.call_args.args)
|
||||||
masc.msg(txt, from_obj=fem)
|
masc.msg(txt, from_obj=fem)
|
||||||
self.assertIn("Test her gender", mock_msg.call_args.args)
|
self.assertIn("Test her gender", mock_msg.call_args.args)
|
||||||
|
|
||||||
|
def test_ungendered_source(self):
|
||||||
|
char = create_object(gendersub.GenderCharacter, key="Gendered", location=self.room1)
|
||||||
|
txt = "Test |p gender"
|
||||||
|
with patch(
|
||||||
|
"evennia.contrib.game_systems.gendersub.gendersub.DefaultCharacter.msg"
|
||||||
|
) as mock_msg:
|
||||||
|
char.msg(txt, from_obj=self.char1)
|
||||||
|
self.assertIn("Test their gender", mock_msg.call_args.args)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue