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 # Module imports
from amanuensis.parser import filesafe_title from amanuensis.parser import filesafe_title
from amanuensis.models import ModelFactory, UserModel from amanuensis.models import ModelFactory, UserModel, LexiconModel
def register_custom_filters(app): def register_custom_filters(app):
@ -35,6 +35,13 @@ def register_custom_filters(app):
name=g.lexicon.cfg.name, name=g.lexicon.cfg.name,
title=filesafe_title(title)) 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): def lexicon_param(route):
"""Wrapper for loading a route's lexicon""" """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 flask_login import login_required, current_user
from amanuensis.lexicon import player_can_join_lexicon, add_player_to_lexicon 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.parser import filesafe_title
from amanuensis.server.helpers import ( from amanuensis.server.helpers import (
lexicon_param, lexicon_param,
@ -26,6 +27,10 @@ bp_lexicon = Blueprint('lexicon', __name__,
@lexicon_param @lexicon_param
@login_required @login_required
def join(name): 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: if not g.lexicon.cfg.join.open:
flash("This game isn't open for joining") flash("This game isn't open for joining")
return redirect(url_for('home.home')) return redirect(url_for('home.home'))

View File

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