Compare commits

...

1 Commits

Author SHA1 Message Date
Tim Van Baak 45ee56d09b Add character creation and signatures 2021-08-27 12:03:16 -07:00
4 changed files with 37 additions and 38 deletions

View File

@ -95,9 +95,6 @@ div.contentblock {
border-radius: 5px; border-radius: 5px;
word-break: break-word; word-break: break-word;
} }
div.contentblock h3 {
margin: 0.3em 0;
}
a.phantom { a.phantom {
color: #cc2200; color: #cc2200;
} }
@ -139,10 +136,21 @@ ul.blockitem-list li {
border-inline-start: 3px solid black; border-inline-start: 3px solid black;
padding-inline-start: 0.5em; padding-inline-start: 0.5em;
} }
ul.blockitem-list p { ul.blockitem-list * {
margin-block-start: 0.5em; margin-block-start: 0.5em;
margin-block-end: 0.5em; margin-block-end: 0.5em;
} }
ul.blockitem-list pre {
background-color: lightgray;
padding-block-start: 2px;
padding-block-end: 2px;
padding-inline-start: 2px;
padding-inline-end: 2px;
border: 1px solid gray;
border-radius: 2px;
font-size: smaller;
white-space: break-spaces;
}
div.dashboard-lexicon-unstarted { div.dashboard-lexicon-unstarted {
border-left-color: blue; border-left-color: blue;
} }

View File

@ -9,7 +9,7 @@
{% block sb_logo %}{% endblock %} {% block sb_logo %}{% endblock %}
{% block sb_characters %}<a {% block sb_characters %}<a
{% if current_page == "characters" %}class="current-page" {% if current_page == "characters" %}class="current-page"
{% else %}href="{{ url_for('lexicon.characters.characters', name=g.lexicon.name) }}" {% else %}href="{{ url_for('lexicon.characters.list', name=g.lexicon.name) }}"
{% endif %}>Characters</a>{% endblock %} {% endif %}>Characters</a>{% endblock %}
{% block sb_contents %}<a {% block sb_contents %}<a
{% if current_page == "contents" %}class="current-page" {% if current_page == "contents" %}class="current-page"

View File

@ -2,6 +2,7 @@ from typing import Optional
import uuid import uuid
from flask import Blueprint, render_template, url_for, g, flash from flask import Blueprint, render_template, url_for, g, flash
from flask_login import current_user
from werkzeug.utils import redirect from werkzeug.utils import redirect
from amanuensis.backend import charq from amanuensis.backend import charq
@ -17,8 +18,8 @@ bp = Blueprint("characters", __name__, url_prefix="/characters", template_folder
@bp.get('/') @bp.get('/')
@lexicon_param @lexicon_param
@player_required @player_required
def characters(name): def list(name):
return render_template('characters.jinja') return render_template('characters.jinja', name=name)
@bp.route('/edit/<character_id>', methods=['GET', 'POST']) @bp.route('/edit/<character_id>', methods=['GET', 'POST'])
@ -29,11 +30,11 @@ def edit(name, character_id):
char_uuid = uuid.UUID(character_id) char_uuid = uuid.UUID(character_id)
except: except:
flash("Character not found") flash("Character not found")
return redirect(url_for('lexicon.characters.characters', name=name)) return redirect(url_for('lexicon.characters.list', name=name))
character: Optional[Character] = charq.try_from_public_id(g.db, char_uuid) character: Optional[Character] = charq.try_from_public_id(g.db, char_uuid)
if not character: if not character:
flash("Character not found") flash("Character not found")
return redirect(url_for('lexicon.characters.characters', name=name)) return redirect(url_for('lexicon.characters.list', name=name))
form = CharacterCreateForm() form = CharacterCreateForm()
@ -50,38 +51,18 @@ def edit(name, character_id):
character.name = form.name.data character.name = form.name.data
character.signature = form.signature.data character.signature = form.signature.data
g.db.session.commit() g.db.session.commit()
return redirect(url_for('lexicon.characters.characters', name=name)) return redirect(url_for('lexicon.characters.list', name=name))
else: else:
# POST submitted invalid data # POST submitted invalid data
return render_template('characters.edit.jinja', character=character, form=form) return render_template('characters.edit.jinja', character=character, form=form)
# def create_character(name: str, form: LexiconCharacterForm): @bp.get('/new/')
# # Characters can't be created if the game has already started @lexicon_param
# if g.lexicon.status != LexiconModel.PREGAME: @player_required
# flash("Characters can't be added after the game has started") def new(name):
# return redirect(url_for('session.session', name=name)) dummy_name = f"{current_user.username}'s new character"
# # Characters can't be created beyond the per-player limit dummy_signature = "~"
# player_characters = get_player_characters(g.lexicon, current_user.uid) charq.create(g.db, g.lexicon.id, current_user.id, dummy_name, dummy_signature)
# if len(list(player_characters)) >= g.lexicon.cfg.join.chars_per_player: return redirect(url_for('lexicon.characters.list', name=name))
# flash("Can't create more characters")
# return redirect(url_for('session.session', name=name))
# if not form.is_submitted():
# # GET, populate with default values
# return render_template(
# 'session.character.jinja', form=form.for_new())
# if not form.validate():
# # POST with invalid data, return unchanged
# return render_template('session.character.jinja', form=form)
# # POST with valid data, create character
# char_name = form.characterName.data
# cid = create_character_in_lexicon(current_user, g.lexicon, char_name)
# with g.lexicon.ctx.edit_config() as cfg:
# cfg.character[cid].signature = form.defaultSignature.data
# flash('Character created')
# return redirect(url_for('session.session', name=name))

View File

@ -1,4 +1,5 @@
{% extends "lexicon.jinja" %} {% extends "lexicon.jinja" %}
{% set current_page = "characters" %}
{% block title %}Character | {{ lexicon_title }}{% endblock %} {% block title %}Character | {{ lexicon_title }}{% endblock %}
{% block main %} {% block main %}
@ -10,9 +11,18 @@
<span style="color:#ff0000">{{ message }}</span><br> <span style="color:#ff0000">{{ message }}</span><br>
{% endfor %} {% endfor %}
<ul class="blockitem-list"> <ul class="blockitem-list">
{% if characters|map(attribute="user_id")|select("equalto", current_user.id)|list|count < g.lexicon.character_limit %}
<li>
<h3><a href="{{ url_for('lexicon.characters.new', name=name) }}">Create a new character</a></h3>
<p>You have created {{ characters|map(attribute="user_id")|select("equalto", current_user.id)|list|count }} out of {{ g.lexicon.character_limit }} allowed characters.</p>
</li>
{% endif %}
{% for character in characters %} {% for character in characters %}
<li> <li>
<h3>{{ character.name }}</h3> <h3>{{ character.name }}</h3>
{% if character.user == current_user %}
<pre>{{ character.signature }}</pre>
{% endif %}
<p>Player: {{ character.user.username }}</p> <p>Player: {{ character.user.username }}</p>
{% if character.user == current_user %} {% if character.user == current_user %}
<p><a href="{{ url_for('lexicon.characters.edit', name=g.lexicon.name, character_id=character.public_id) }}">Edit this character</a></p> <p><a href="{{ url_for('lexicon.characters.edit', name=g.lexicon.name, character_id=character.public_id) }}">Edit this character</a></p>