Add two getter methods to lex.gameloop
This commit is contained in:
parent
c47f9a7e5a
commit
7f76db7af7
|
@ -2,7 +2,10 @@ from .admin import (
|
||||||
valid_name,
|
valid_name,
|
||||||
create_lexicon,
|
create_lexicon,
|
||||||
load_all_lexicons)
|
load_all_lexicons)
|
||||||
from .gameloop import attempt_publish
|
from .gameloop import (
|
||||||
|
get_player_characters,
|
||||||
|
get_player_drafts,
|
||||||
|
attempt_publish)
|
||||||
from .setup import (
|
from .setup import (
|
||||||
player_can_join_lexicon,
|
player_can_join_lexicon,
|
||||||
add_player_to_lexicon,
|
add_player_to_lexicon,
|
||||||
|
@ -12,6 +15,8 @@ __all__ = [member.__name__ for member in [
|
||||||
valid_name,
|
valid_name,
|
||||||
create_lexicon,
|
create_lexicon,
|
||||||
load_all_lexicons,
|
load_all_lexicons,
|
||||||
|
get_player_characters,
|
||||||
|
get_player_drafts,
|
||||||
attempt_publish,
|
attempt_publish,
|
||||||
player_can_join_lexicon,
|
player_can_join_lexicon,
|
||||||
add_player_to_lexicon,
|
add_player_to_lexicon,
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
Submodule of functions for managing lexicon games during the core game
|
Submodule of functions for managing lexicon games during the core game
|
||||||
loop of writing and publishing articles.
|
loop of writing and publishing articles.
|
||||||
"""
|
"""
|
||||||
from typing import Iterable, Any
|
from typing import Iterable, Any, List
|
||||||
|
|
||||||
|
from amanuensis.config import ReadOnlyOrderedDict
|
||||||
from amanuensis.models import LexiconModel
|
from amanuensis.models import LexiconModel
|
||||||
from amanuensis.parser import (
|
from amanuensis.parser import (
|
||||||
parse_raw_markdown,
|
parse_raw_markdown,
|
||||||
|
@ -13,6 +14,37 @@ from amanuensis.parser import (
|
||||||
filesafe_title)
|
filesafe_title)
|
||||||
|
|
||||||
|
|
||||||
|
def get_player_characters(
|
||||||
|
lexicon: LexiconModel,
|
||||||
|
uid: str) -> Iterable[ReadOnlyOrderedDict]:
|
||||||
|
"""
|
||||||
|
Returns each character in the lexicon owned by the given player
|
||||||
|
"""
|
||||||
|
for character in lexicon.cfg.character.values():
|
||||||
|
if character.player == uid:
|
||||||
|
yield character
|
||||||
|
|
||||||
|
|
||||||
|
def get_player_drafts(
|
||||||
|
lexicon: LexiconModel,
|
||||||
|
uid: str) -> Iterable[ReadOnlyOrderedDict]:
|
||||||
|
"""
|
||||||
|
Returns each draft in the lexicon by a character owned by the
|
||||||
|
given player.
|
||||||
|
"""
|
||||||
|
characters = list(get_player_characters(lexicon, uid))
|
||||||
|
drafts: List[Any] = []
|
||||||
|
for filename in lexicon.ctx.draft.ls():
|
||||||
|
for character in characters:
|
||||||
|
if filename.startswith(character.cid):
|
||||||
|
drafts.append(filename)
|
||||||
|
break
|
||||||
|
for i in range(len(drafts)):
|
||||||
|
with lexicon.ctx.draft.read(drafts[i]) as draft:
|
||||||
|
drafts[i] = draft
|
||||||
|
return drafts
|
||||||
|
|
||||||
|
|
||||||
def attempt_publish(lexicon: LexiconModel) -> None:
|
def attempt_publish(lexicon: LexiconModel) -> None:
|
||||||
"""
|
"""
|
||||||
If the lexicon's publsh policy allows the current set of approved
|
If the lexicon's publsh policy allows the current set of approved
|
||||||
|
|
Loading…
Reference in New Issue