cleanup and bugfixing

This commit is contained in:
lunacb 2023-01-13 19:30:57 -05:00
parent d1f33e858a
commit 7e34080666
3 changed files with 34 additions and 23 deletions

16
lib/pronounsub/consts.py Normal file
View File

@ -0,0 +1,16 @@
import re
DEFAULT_SPECIFIC_NEUTRAL_PRONOUNS = {"s": "they", "o": "them", "p": "their", "a": "theirs"}
DEFAULT_SPECIFIC_PRONOUNS = [
{"s": "he", "o": "him", "p": "his", "a": "his"},
{"s": "she", "o": "her", "p": "her", "a": "hers"},
{"s": "it", "o": "it", "p": "its", "a": "its"},
{"s": "they", "o": "them", "p": "their", "a": "theirs"}
]
DEFAULT_CHARACTER_PRONOUNS = [ "they", "them" ]
PRONOUN_FORMS = [ "s", "o", "p", "a" ]
RE_GENDER_PRONOUN = re.compile(r"(?<!\|)\|(?!\|)[sSoOpPaA]")

View File

@ -1,10 +1,8 @@
import copy
from evennia import DefaultScript
from .consts import *
class PronounDbScript(DefaultScript):
def at_script_creation(self):
self.db.pronouns = [
{"s": "he", "o": "him", "p": "his", "a": "his"},
{"s": "she", "o": "her", "p": "her", "a": "hers"},
{"s": "it", "o": "it", "p": "its", "a": "its"},
{"s": "they", "o": "them", "p": "their", "a": "theirs"},
]
self.db.pronouns = copy.deepcopy(DEFAULT_SPECIFIC_PRONOUNS)

View File

@ -40,21 +40,18 @@ from evennia import InterruptCommand
from evennia.utils import logger
from evennia.utils.create import create_script
from evennia.utils.search import search_script
_PRONOUN_FORMS = [ "s", "o", "p", "a" ]
_RE_GENDER_PRONOUN = re.compile(r"(?<!\|)\|(?!\|)[sSoOpPaA]")
from .consts import *
# in-game command for setting the gender
def parse_specific_pronoun(pronoun):
specific = [ p.strip() for p in pronoun.split(",") ]
if len(specific) != len(_PRONOUN_FORMS):
if len(specific) != len(PRONOUN_FORMS):
return None
new = {}
for i in range(len(specific)):
new[_PRONOUN_FORMS[i]] = specific[i]
new[PRONOUN_FORMS[i]] = specific[i]
return new
@ -70,6 +67,7 @@ def get_pronoun_list():
def specific_pronoun_from_character(character, caller=None):
pronoun_list = get_pronoun_list()[:]
if caller != None:
# TODO: reorder
pronoun_list += caller.db.pronoun_specs
for pronoun in pronoun_list:
if character in pronoun.values():
@ -78,7 +76,7 @@ def specific_pronoun_from_character(character, caller=None):
return None
def stringify_specific_pronoun(spec):
return ",".join([ spec[form] for form in _PRONOUN_FORMS ])
return ",".join([ spec[form] for form in PRONOUN_FORMS ])
class PronounAdminCommand(Command):
"""
@ -115,7 +113,6 @@ class PronounAdminCommand(Command):
locks = "cmd:id(1) or perm(Admin)"
def parse(self):
from evennia import set_trace;set_trace()
caller = self.caller
args = self.args.strip().lower().split()
@ -314,11 +311,11 @@ class PronounCharacter(DefaultCharacter):
Called once when the object is created.
"""
super().at_object_creation()
self.db.pronouns = [ "they", "them" ]
self.db.pronouns = DEFAULT_CHARACTER_PRONOUNS[:]
self.db.pronoun_specs = []
def _stringify_pronouns(self):
pronouns = self.attributes.get("pronouns", default=[ "they", "them" ])
pronouns = self.attributes.get("pronouns", default=DEFAULT_CHARACTER_PRONOUNS[:])
return "/".join(pronouns)
def _get_pronoun(self, regex_match):
@ -338,7 +335,7 @@ class PronounCharacter(DefaultCharacter):
"""
typ = regex_match.group()[1] # "s", "O" etc
dup_specifics = []
for pronoun in self.attributes.get("pronouns", default=[ "they", "them" ]):
for pronoun in self.attributes.get("pronouns", default=DEFAULT_CHARACTER_PRONOUNS[:]):
specific = specific_pronoun_from_character(pronoun, self)
if specific != None:
dup_specifics.append(specific)
@ -348,10 +345,10 @@ class PronounCharacter(DefaultCharacter):
if not s in specifics:
specifics.append(s)
choice = random.choice(specifics)
gender = self.attributes.get("gender", default="ambiguous")
gender = gender if gender in ("male", "female", "neutral") else "ambiguous"
if len(specifics) == 0:
choice = DEFAULT_SPECIFIC_NEUTRAL_PRONOUNS
else:
choice = random.choice(specifics)
pronoun = choice[typ.lower()]
return pronoun.capitalize() if typ.isupper() else pronoun
@ -383,9 +380,9 @@ class PronounCharacter(DefaultCharacter):
try:
if text and isinstance(text, tuple):
text = (_RE_GENDER_PRONOUN.sub(self._get_pronoun, text[0]), *text[1:])
text = (RE_GENDER_PRONOUN.sub(self._get_pronoun, text[0]), *text[1:])
else:
text = _RE_GENDER_PRONOUN.sub(self._get_pronoun, text)
text = RE_GENDER_PRONOUN.sub(self._get_pronoun, text)
except TypeError:
pass
except Exception as e: