Compare commits

...

2 Commits

Author SHA1 Message Date
Tim Van Baak 8ca037f257 Add character creation and signatures 2021-08-27 11:53:37 -07:00
Tim Van Baak eec039c09a Add character limit cli 2021-08-27 08:19:29 -07:00
5 changed files with 40 additions and 38 deletions

View File

@ -49,6 +49,7 @@ def command_create(args):
@add_argument("--no-public", dest="public", action="store_const", const=False)
@add_argument("--join", dest="join", action="store_const", const=True)
@add_argument("--no-join", dest="join", action="store_const", const=False)
@add_argument("--char-limit", type=int, default=None)
def command_edit(args):
"""
Update a lexicon's configuration.
@ -66,6 +67,9 @@ def command_edit(args):
elif args.join == False:
values["joinable"] = False
if args.char_limit:
values["character_limit"] = args.char_limit
result = db(update(Lexicon).where(Lexicon.name == args.name).values(**values))
LOG.info(f"Updated {result.rowcount} lexicons")
db.session.commit()

View File

@ -95,9 +95,6 @@ div.contentblock {
border-radius: 5px;
word-break: break-word;
}
div.contentblock h3 {
margin: 0.3em 0;
}
a.phantom {
color: #cc2200;
}
@ -139,10 +136,21 @@ ul.blockitem-list li {
border-inline-start: 3px solid black;
padding-inline-start: 0.5em;
}
ul.blockitem-list p {
ul.blockitem-list * {
margin-block-start: 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 {
border-left-color: blue;
}

View File

@ -9,7 +9,7 @@
{% block sb_logo %}{% endblock %}
{% block sb_characters %}<a
{% 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 %}
{% block sb_contents %}<a
{% if current_page == "contents" %}class="current-page"

View File

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

View File

@ -10,9 +10,18 @@
<span style="color:#ff0000">{{ message }}</span><br>
{% endfor %}
<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 %}
<li>
<h3>{{ character.name }}</h3>
{% if character.user == current_user %}
<pre>{{ character.signature }}</pre>
{% endif %}
<p>Player: {{ character.user.username }}</p>
{% 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>