Predicate some UI elements on game state

This commit is contained in:
Tim Van Baak 2020-04-29 21:55:07 -07:00
parent 00a871925e
commit 1f1465de6b
3 changed files with 19 additions and 3 deletions

View File

@ -8,7 +8,7 @@ from flask_login import current_user
# Module imports
from amanuensis.parser import filesafe_title
from amanuensis.models import ModelFactory, UserModel
from amanuensis.models import ModelFactory, UserModel, LexiconModel
def register_custom_filters(app):
@ -35,6 +35,13 @@ def register_custom_filters(app):
name=g.lexicon.cfg.name,
title=filesafe_title(title))
@app.context_processor
def lexicon_status():
return dict(
PREGAME=LexiconModel.PREGAME,
ONGOING=LexiconModel.ONGOING,
COMPLETE=LexiconModel.COMPLETE)
def lexicon_param(route):
"""Wrapper for loading a route's lexicon"""

View File

@ -9,6 +9,7 @@ from flask import (
from flask_login import login_required, current_user
from amanuensis.lexicon import player_can_join_lexicon, add_player_to_lexicon
from amanuensis.models import LexiconModel
from amanuensis.parser import filesafe_title
from amanuensis.server.helpers import (
lexicon_param,
@ -26,6 +27,10 @@ bp_lexicon = Blueprint('lexicon', __name__,
@lexicon_param
@login_required
def join(name):
if g.lexicon.status != LexiconModel.PREGAME:
flash("Can't join a game already in progress")
return redirect(url_for('home.home'))
if not g.lexicon.cfg.join.open:
flash("This game isn't open for joining")
return redirect(url_for('home.home'))

View File

@ -36,12 +36,14 @@
</li>
{% endfor %}
</ul>
{% if g.lexicon.status == ONGOING %}
{% if publish_form %}
<form id="publish-turn-form" action="" method="post" novalidate>
{{ publish_form.hidden_tag() }}
<p>{{ publish_form.submit() }}</p>
</form>
{% endif %}
{% endif %}
{% endblock %}
{% set template_content_blocks = template_content_blocks + [self.bl_editor()] %}
{% endif %}
@ -60,18 +62,20 @@
</li>
{% endfor %}
{%
if characters|count is lt(g.lexicon.cfg.join.chars_per_player)
and not g.lexicon.cfg.turn.current
if g.lexicon.status == PREGAME
and characters|count is lt(g.lexicon.cfg.join.chars_per_player)
%}
<li>
<a href="{{ url_for('session.character', name=g.lexicon.cfg.name) }}">Create a character</a>
</li>
{% endif %}
{% if g.lexicon.status == ONGOING %}
<li>
<a href="{{ url_for('session.editor', name=g.lexicon.cfg.name) }}">
Article editor
</a>
</li>
{% endif %}
</ul>
{% endblock %}
{% set template_content_blocks = template_content_blocks + [self.main()] %}