diff --git a/npc/generator/base.py b/npc/generator/base.py index e17ab44..6fee7c3 100644 --- a/npc/generator/base.py +++ b/npc/generator/base.py @@ -91,17 +91,12 @@ class BaseNPC: @property def names(self): if not self._names: - self._names = [str(x) for x in self.language.person()] + self._names = next(self.name_generator.name(1)) return self._names @property def full_name(self): - name = ' '.join([n.title() for n in self.names]) - if self.title: - name = self.title.title() + ' ' + name - if self.nickname: - name = f'{name} "{self.nickname}"' - return name + return self.names.fullname @property def pronouns(self): @@ -115,16 +110,11 @@ class BaseNPC: @property def title(self): - return self._title + return ' '.join(self.names.titles) @property def nickname(self): - if self._nickname is None and hasattr(self.language, 'nicknames'): - try: - self._nickname = random.choice(self.language.nicknames).capitalize() - except IndexError: - self._nickname = False - return self._nickname + return ', '.join(self.names.nicknames) @property def whereabouts(self): diff --git a/npc/generator/human.py b/npc/generator/human.py index 5f054b3..9bdf93e 100644 --- a/npc/generator/human.py +++ b/npc/generator/human.py @@ -1,8 +1,8 @@ -from npc.languages import common +from language.languages.common import common_name from npc.generator.base import BaseNPC class NPC(BaseNPC): ancestry = 'Human' - language = common.CommonPerson() + name_generator = common_name diff --git a/pyproject.toml b/pyproject.toml index 1671b0c..26c134f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,8 @@ description = "NPC tools for the telisar homebrew campaign setting" authors = ["evilchili "] license = "The Unlicense" packages = [ - { include = 'npc' } + { include = 'npc' }, + { include = 'language' }, ] [tool.poetry.dependencies] @@ -14,12 +15,36 @@ typer = "latest" rich = "latest" dice = "latest" +dnd-languages = { git = "https://github.com/evilchili/dnd-languages", branch = 'mainline' } + [tool.poetry.dev-dependencies] pytest = "latest" +black = "^23.3.0" +isort = "^5.12.0" +pyproject-autoflake = "^1.0.2" [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" +[tool.black] +line-length = 120 +target-version = ['py310'] + +[tool.isort] +multi_line_output = 3 +line_length = 120 +include_trailing_comma = true + +[tool.autoflake] +check = false # return error code if changes are needed +in-place = true # make changes to files instead of printing diffs +recursive = true # drill down directories recursively +remove-all-unused-imports = true # remove all unused imports (not just those from the standard library) +ignore-init-module-imports = true # exclude __init__.py when removing unused imports +remove-duplicate-keys = true # remove all duplicate keys in objects +remove-unused-variables = true # remove unused variables + [tool.poetry.scripts] npc = "npc.cli:app" +language-tool = "language.cli:app" diff --git a/test/test_languages.py b/test/test_languages.py new file mode 100644 index 0000000..0927be5 --- /dev/null +++ b/test/test_languages.py @@ -0,0 +1,20 @@ +import pytest +from language.types import WeightedSet +from language.languages.common import common + + +@pytest.mark.parametrize('values,expected_members,expected_weights', [ + ((('foo', 1.0), ('bar', 0.5)), ('foo', 'bar'), (1.0, 0.5)) +]) +def test_WeightedSet(values, expected_members, expected_weights): + + print(*values) + ws = WeightedSet(*values) + assert ws.members == expected_members + assert ws.weights == expected_weights + assert ws.random() + + +def test_common(): + for i in range(50000): + assert common.word() diff --git a/test/test_types.py b/test/test_types.py new file mode 100644 index 0000000..9b02267 --- /dev/null +++ b/test/test_types.py @@ -0,0 +1,22 @@ +from language import types + + +def test_subclassing(): + + class akak(types.Language): + clicks = types.WeightedSet(("k'", 1.0),) + + def get_grapheme_click(self) -> str: + return self.clicks.random() + + ak = akak( + name='ClickSpeak', + vowels=types.WeightedSet(('a', 1.0),), + consonants=types.WeightedSet(), + prefixes=None, + suffixes=None, + rules=set(), + minimum_grapheme_count=2, + syllables=types.SyllableSet((types.Syllable('vowel,click'), 1.0),), + ) + assert list(ak.word(2)) == ["ak'", "ak'"]