From 4705a39c41e1835c45ec1e28db1c740432a96d03 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Thu, 30 Apr 2020 01:49:19 -0700 Subject: [PATCH] Add article index to editor info --- amanuensis/lexicon/gameloop.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/amanuensis/lexicon/gameloop.py b/amanuensis/lexicon/gameloop.py index 5d4d9c0..af91509 100644 --- a/amanuensis/lexicon/gameloop.py +++ b/amanuensis/lexicon/gameloop.py @@ -89,6 +89,9 @@ def title_constraint_analysis( # E: This article has already been written and addendums are disabled elif not lexicon.cfg.article.addendum.allowed: errors.append('Article already exists') + # I: This article's index + index = get_index_for_title(lexicon, title) + infos.append(f'Article index: {index}') # The article does not sort under the player's assigned index pass # The article's title is new, but its index is full @@ -174,6 +177,26 @@ def index_match(index, title) -> bool: raise ValueError(f'Unknown index type: "{index.type}"') +def get_index_for_title(lexicon: LexiconModel, title: str): + """ + Returns the index pattern for the given title. + """ + index_specs = lexicon.cfg.article.index.list + index_by_pri: dict = {} + for index in index_specs: + if index.pri not in index_by_pri: + index_by_pri[index.pri] = [] + index_by_pri[index.pri].append(index) + index_eval_order = [ + index + for pri in sorted(index_by_pri.keys(), reverse=True) + for index in index_by_pri[pri]] + for index in index_eval_order: + if index_match(index, title): + return index.pattern + return "&c" + + def sort_by_index_spec(articles, index_specs, key=None): """ Sorts a list under the appropriate index in the given index