|
|
@ -13,7 +13,7 @@ from sqlalchemy import and_ |
|
|
|
from app import db |
|
|
|
from app import db |
|
|
|
from app.main import bp |
|
|
|
from app.main import bp |
|
|
|
from app.utils import generate_qr_code, serve_pil_image |
|
|
|
from app.utils import generate_qr_code, serve_pil_image |
|
|
|
from app.models import User, Game, Role, GamePlayer, Objective, ObjectiveMinimalEncoder, \ |
|
|
|
from app.models import User, Game, Role, GamePlayer, GameState, Objective, ObjectiveMinimalEncoder,\ |
|
|
|
LocationEncoder, PlayerCaughtPlayer, Review, Location |
|
|
|
LocationEncoder, PlayerCaughtPlayer, Review, Location |
|
|
|
from app.main.forms import CreateGameForm, ObjectiveForm, PlayerAddForm, UserCreateForm, \ |
|
|
|
from app.main.forms import CreateGameForm, ObjectiveForm, PlayerAddForm, UserCreateForm, \ |
|
|
|
PlayerUpdateForm, CatchBunnyForm |
|
|
|
PlayerUpdateForm, CatchBunnyForm |
|
|
@ -36,9 +36,14 @@ def index(): |
|
|
|
@login_required |
|
|
|
@login_required |
|
|
|
def create_game(): |
|
|
|
def create_game(): |
|
|
|
form = CreateGameForm() |
|
|
|
form = CreateGameForm() |
|
|
|
|
|
|
|
form.state.choices = [(state.value, state.name) for state in GameState] |
|
|
|
|
|
|
|
|
|
|
|
if form.validate_on_submit(): |
|
|
|
if form.validate_on_submit(): |
|
|
|
game = Game(name=form.game_name.data, start_time=form.start_time.data, |
|
|
|
if Game.query.filter_by(name=form.game_name.data): |
|
|
|
end_time=form.end_time.data) |
|
|
|
flash('Please choose a different game name') |
|
|
|
|
|
|
|
return render_template('create_game.html', title='Create Game', form=form) |
|
|
|
|
|
|
|
game = Game(name=form.game_name.data, start_time=form.start_time.data, |
|
|
|
|
|
|
|
end_time=form.end_time.data, state=GameState(form.state.data)) |
|
|
|
game.players.append(GamePlayer(user=current_user, role=Role['owner'])) |
|
|
|
game.players.append(GamePlayer(user=current_user, role=Role['owner'])) |
|
|
|
db.session.add(game) |
|
|
|
db.session.add(game) |
|
|
|
db.session.commit() |
|
|
|
db.session.commit() |
|
|
@ -46,6 +51,43 @@ def create_game(): |
|
|
|
return redirect(url_for('main.game_dashboard', game_name=game.name)) |
|
|
|
return redirect(url_for('main.game_dashboard', game_name=game.name)) |
|
|
|
return render_template('create_game.html', title='Create Game', form=form) |
|
|
|
return render_template('create_game.html', title='Create Game', form=form) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/game/<game_name>/change_settings', methods=['GET', 'POST']) |
|
|
|
|
|
|
|
@login_required |
|
|
|
|
|
|
|
def change_game_settings(game_name): |
|
|
|
|
|
|
|
game = Game.query.filter_by(name=game_name).first_or_404() |
|
|
|
|
|
|
|
if not game.owned_by(current_user): |
|
|
|
|
|
|
|
abort(403) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
form = CreateGameForm() |
|
|
|
|
|
|
|
form.state.choices = [(state.value, state.name) for state in GameState] |
|
|
|
|
|
|
|
form.old_name = game.name |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if request.method == 'GET': |
|
|
|
|
|
|
|
form.state.default = game.state.value |
|
|
|
|
|
|
|
# pylint: disable=no-member |
|
|
|
|
|
|
|
form.process() |
|
|
|
|
|
|
|
form.game_name.data = game.name |
|
|
|
|
|
|
|
if game.start_time: |
|
|
|
|
|
|
|
form.start_time.data = game.start_time |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
form.start_time_disabled.data = True |
|
|
|
|
|
|
|
form.start_time.data = None |
|
|
|
|
|
|
|
if game.end_time: |
|
|
|
|
|
|
|
form.end_time.data = game.end_time |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
form.end_time_disabled.data = True |
|
|
|
|
|
|
|
form.end_time.data = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if form.validate_on_submit(): |
|
|
|
|
|
|
|
game.name = form.game_name.data |
|
|
|
|
|
|
|
game.start_time = form.start_time.data |
|
|
|
|
|
|
|
game.end_time = form.end_time.data |
|
|
|
|
|
|
|
game.state = GameState(form.state.data) |
|
|
|
|
|
|
|
db.session.commit() |
|
|
|
|
|
|
|
flash(f"'{game.name}' had been updated!") |
|
|
|
|
|
|
|
return redirect(url_for('main.game_dashboard', game_name=game.name)) |
|
|
|
|
|
|
|
return render_template('create_game.html', title='Chage Game Settings', form=form) |
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/game/<game_name>/delete') |
|
|
|
@bp.route('/game/<game_name>/delete') |
|
|
|
@login_required |
|
|
|
@login_required |
|
|
|
def delete_game(game_name): |
|
|
|
def delete_game(game_name): |
|
|
@ -89,6 +131,9 @@ def catch_bunny(game_name): |
|
|
|
if current_user.role_in_game(game) is not Role.hunter: |
|
|
|
if current_user.role_in_game(game) is not Role.hunter: |
|
|
|
flash('Only hunters can catch bunnies!') |
|
|
|
flash('Only hunters can catch bunnies!') |
|
|
|
abort(403) |
|
|
|
abort(403) |
|
|
|
|
|
|
|
if not game.is_active(): |
|
|
|
|
|
|
|
flash("Its not possible to catch a bunny before or after a game, or if the game is not in 'started' mode.") |
|
|
|
|
|
|
|
return redirect(url_for('main.game_dashboard', game_name=game.name)) |
|
|
|
|
|
|
|
|
|
|
|
game_bunnies = game.bunnies() |
|
|
|
game_bunnies = game.bunnies() |
|
|
|
form = CatchBunnyForm() |
|
|
|
form = CatchBunnyForm() |
|
|
@ -180,7 +225,6 @@ def add_player(game_name): |
|
|
|
if not game.owned_by(current_user): |
|
|
|
if not game.owned_by(current_user): |
|
|
|
abort(403) |
|
|
|
abort(403) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
form_add = PlayerAddForm() |
|
|
|
form_add = PlayerAddForm() |
|
|
|
form_add.role.choices = [(role.value, role.name) for role in Role] |
|
|
|
form_add.role.choices = [(role.value, role.name) for role in Role] |
|
|
|
form_create = UserCreateForm() |
|
|
|
form_create = UserCreateForm() |
|
|
@ -283,6 +327,9 @@ def objective_qrcode(objective_hash): |
|
|
|
def objective(objective_hash): |
|
|
|
def objective(objective_hash): |
|
|
|
objective = Objective.query.filter_by(hash=objective_hash).first_or_404() |
|
|
|
objective = Objective.query.filter_by(hash=objective_hash).first_or_404() |
|
|
|
if current_user.role_in_game(objective.game) == Role.bunny: |
|
|
|
if current_user.role_in_game(objective.game) == Role.bunny: |
|
|
|
|
|
|
|
if not objective.game.is_active(): |
|
|
|
|
|
|
|
flash("Its not find an objective before or after a game, or if the game is not in 'started' mode.") |
|
|
|
|
|
|
|
return redirect(url_for('main.game_dashboard', game_name=objective.game.name)) |
|
|
|
player = current_user.player_in(objective.game) |
|
|
|
player = current_user.player_in(objective.game) |
|
|
|
if not objective in player.found_objectives: |
|
|
|
if not objective in player.found_objectives: |
|
|
|
player.found_objectives.append(objective) |
|
|
|
player.found_objectives.append(objective) |
|
|
@ -345,4 +392,4 @@ def user_profile(username): |
|
|
|
user = User.query.filter_by(name=username).first_or_404() |
|
|
|
user = User.query.filter_by(name=username).first_or_404() |
|
|
|
if current_user != user: |
|
|
|
if current_user != user: |
|
|
|
abort(403) |
|
|
|
abort(403) |
|
|
|
return render_template('user_profile.html', user=user) |
|
|
|
return render_template('user_profile.html', user=user) |
|
|
|