Refactor out langauges
This commmit removes the languages code and takes a dependency on the rewritten module.
This commit is contained in:
parent
9888e35072
commit
2e5b5556a3
|
@ -91,17 +91,12 @@ class BaseNPC:
|
||||||
@property
|
@property
|
||||||
def names(self):
|
def names(self):
|
||||||
if not self._names:
|
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
|
return self._names
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def full_name(self):
|
def full_name(self):
|
||||||
name = ' '.join([n.title() for n in self.names])
|
return self.names.fullname
|
||||||
if self.title:
|
|
||||||
name = self.title.title() + ' ' + name
|
|
||||||
if self.nickname:
|
|
||||||
name = f'{name} "{self.nickname}"'
|
|
||||||
return name
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pronouns(self):
|
def pronouns(self):
|
||||||
|
@ -115,16 +110,11 @@ class BaseNPC:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def title(self):
|
def title(self):
|
||||||
return self._title
|
return ' '.join(self.names.titles)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def nickname(self):
|
def nickname(self):
|
||||||
if self._nickname is None and hasattr(self.language, 'nicknames'):
|
return ', '.join(self.names.nicknames)
|
||||||
try:
|
|
||||||
self._nickname = random.choice(self.language.nicknames).capitalize()
|
|
||||||
except IndexError:
|
|
||||||
self._nickname = False
|
|
||||||
return self._nickname
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def whereabouts(self):
|
def whereabouts(self):
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
from npc.languages import common
|
from language.languages.common import common_name
|
||||||
from npc.generator.base import BaseNPC
|
from npc.generator.base import BaseNPC
|
||||||
|
|
||||||
|
|
||||||
class NPC(BaseNPC):
|
class NPC(BaseNPC):
|
||||||
|
|
||||||
ancestry = 'Human'
|
ancestry = 'Human'
|
||||||
language = common.CommonPerson()
|
name_generator = common_name
|
||||||
|
|
|
@ -5,7 +5,8 @@ description = "NPC tools for the telisar homebrew campaign setting"
|
||||||
authors = ["evilchili <evilchili@gmail.com>"]
|
authors = ["evilchili <evilchili@gmail.com>"]
|
||||||
license = "The Unlicense"
|
license = "The Unlicense"
|
||||||
packages = [
|
packages = [
|
||||||
{ include = 'npc' }
|
{ include = 'npc' },
|
||||||
|
{ include = 'language' },
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
|
@ -14,12 +15,36 @@ typer = "latest"
|
||||||
rich = "latest"
|
rich = "latest"
|
||||||
dice = "latest"
|
dice = "latest"
|
||||||
|
|
||||||
|
dnd-languages = { git = "https://github.com/evilchili/dnd-languages", branch = 'mainline' }
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
pytest = "latest"
|
pytest = "latest"
|
||||||
|
black = "^23.3.0"
|
||||||
|
isort = "^5.12.0"
|
||||||
|
pyproject-autoflake = "^1.0.2"
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry-core>=1.0.0"]
|
requires = ["poetry-core>=1.0.0"]
|
||||||
build-backend = "poetry.core.masonry.api"
|
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]
|
[tool.poetry.scripts]
|
||||||
npc = "npc.cli:app"
|
npc = "npc.cli:app"
|
||||||
|
language-tool = "language.cli:app"
|
||||||
|
|
20
test/test_languages.py
Normal file
20
test/test_languages.py
Normal file
|
@ -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()
|
22
test/test_types.py
Normal file
22
test/test_types.py
Normal file
|
@ -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'"]
|
Loading…
Reference in New Issue
Block a user