|
|
@ -3,7 +3,7 @@ from flask_login import login_user, logout_user, current_user, login_required |
|
|
|
from sqlalchemy import and_ |
|
|
|
from sqlalchemy import and_ |
|
|
|
from app import app, db |
|
|
|
from app import app, db |
|
|
|
from app.models import Player, Game, Role, GamePlayer, Objective, ObjectiveMinimalEncoder, LocationEncoder |
|
|
|
from app.models import Player, Game, Role, GamePlayer, Objective, ObjectiveMinimalEncoder, LocationEncoder |
|
|
|
from app.forms import LoginForm, RegistrationForm, CreateGameForm, ObjectiveForm |
|
|
|
from app.forms import LoginForm, RegistrationForm, CreateGameForm, ObjectiveForm, PlayerAddForm, PlayerCreateForm |
|
|
|
import json |
|
|
|
import json |
|
|
|
import qrcode |
|
|
|
import qrcode |
|
|
|
from io import BytesIO |
|
|
|
from io import BytesIO |
|
|
@ -74,7 +74,7 @@ def game_dashboard(game_name): |
|
|
|
@app.route('/game/<game_name>/player/<player_name>') |
|
|
|
@app.route('/game/<game_name>/player/<player_name>') |
|
|
|
@login_required |
|
|
|
@login_required |
|
|
|
def game_player(game_name, player_name): |
|
|
|
def game_player(game_name, player_name): |
|
|
|
return redirect(url_for('indsex')) |
|
|
|
return redirect(url_for('index')) |
|
|
|
|
|
|
|
|
|
|
|
def is_game_owner(game): |
|
|
|
def is_game_owner(game): |
|
|
|
return current_user in [gameplayer.player for gameplayer in game.game_players if gameplayer.role == Role.owner] |
|
|
|
return current_user in [gameplayer.player for gameplayer in game.game_players if gameplayer.role == Role.owner] |
|
|
@ -98,6 +98,28 @@ def add_objective(game_name): |
|
|
|
return redirect(url_for('game_dashboard', game_name=game.name)) |
|
|
|
return redirect(url_for('game_dashboard', game_name=game.name)) |
|
|
|
return render_template('objective.html', title=f'Add Objective for {game_name}', form=form, objective=objective, owner=True) |
|
|
|
return render_template('objective.html', title=f'Add Objective for {game_name}', form=form, objective=objective, owner=True) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/game/<game_name>/addplayer', methods=['GET', 'POST']) |
|
|
|
|
|
|
|
@login_required |
|
|
|
|
|
|
|
def add_player(game_name): |
|
|
|
|
|
|
|
game = Game.query.filter_by(name=game_name).first_or_404() |
|
|
|
|
|
|
|
if not is_game_owner(game): abort(403) |
|
|
|
|
|
|
|
form_add = PlayerAddForm() |
|
|
|
|
|
|
|
form_create = PlayerCreateForm() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if form_add.submit_add.data and form_add.validate_on_submit(): |
|
|
|
|
|
|
|
player = Player.query.filter_by(form_add.name.data).first_or_404() |
|
|
|
|
|
|
|
game.game_players.append(GamePlayer(player=player, role=Role[form_create.role.data])) |
|
|
|
|
|
|
|
return redirect(url_for('game_dashboard', game_name=game.name)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if form_create.submit_create.data and form_create.validate_on_submit(): |
|
|
|
|
|
|
|
player = Player(name=form_create.name.data) |
|
|
|
|
|
|
|
player.set_auth_hash() |
|
|
|
|
|
|
|
game.game_players.append(GamePlayer(player=player, role=Role[form_create.role.data])) |
|
|
|
|
|
|
|
db.session.commit() |
|
|
|
|
|
|
|
return redirect(url_for('game_dashboard', game_name=game.name)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return render_template('add_player.html', title=f'Add Player for {game_name}', form_add=form_add, form_create=form_create, game=game) |
|
|
|
|
|
|
|
|
|
|
|
def generate_objective_qr_code(objective): |
|
|
|
def generate_objective_qr_code(objective): |
|
|
|
qr = qrcode.QRCode( |
|
|
|
qr = qrcode.QRCode( |
|
|
|
version=None, |
|
|
|
version=None, |
|
|
@ -136,6 +158,7 @@ def objective(objective_hash): |
|
|
|
objective.longitude = form.longitude.data |
|
|
|
objective.longitude = form.longitude.data |
|
|
|
objective.latitude = form.latitude.data |
|
|
|
objective.latitude = form.latitude.data |
|
|
|
db.session.commit() |
|
|
|
db.session.commit() |
|
|
|
|
|
|
|
return redirect(url_for('game_dashboard', game_name=objective.game.name)) |
|
|
|
return render_template('objective.html', title='Objective view', objective=objective, owner=owner, form=form, qrcode=qrcode) |
|
|
|
return render_template('objective.html', title='Objective view', objective=objective, owner=owner, form=form, qrcode=qrcode) |
|
|
|
|
|
|
|
|
|
|
|
@app.route('/objective/<objective_hash>/delete', methods=['GET']) |
|
|
|
@app.route('/objective/<objective_hash>/delete', methods=['GET']) |
|
|
|