Browse Source

Implement hide/publish/pause/resume game, fix database boolean default

testing
Burathar 4 years ago
parent
commit
4089777f88
  1. 10
      app/main/routes.py
  2. 8
      app/models/game.py
  3. 2
      app/models/game_state.py
  4. 2
      app/models/notification_player.py
  5. 3
      app/templates/edit_game.html
  6. 2
      documentation/gamestate.txt
  7. 13
      migrations/versions/7a3183ce450a_replace_gamestate_with_hidden_and_paused.py

10
app/main/routes.py

@ -104,7 +104,7 @@ def publish_game(game_name):
game.hidden = False game.hidden = False
db.session.commit() db.session.commit()
flash(f"Game '{game.name}' has been published!") flash(f"Game '{game.name}' has been published!")
return redirect(url_for('main.index')) return redirect(url_for('main.game_dashboard', game_name=game.name))
@bp.route('/game/<game_name>/hide') @bp.route('/game/<game_name>/hide')
@login_required @login_required
@ -113,7 +113,7 @@ def hide_game(game_name):
game.hidden = True game.hidden = True
db.session.commit() db.session.commit()
flash(f"Game '{game.name}' has been hidden!") flash(f"Game '{game.name}' has been hidden!")
return redirect(url_for('main.index')) return redirect(url_for('main.game_dashboard', game_name=game.name))
@bp.route('/game/<game_name>/pause') @bp.route('/game/<game_name>/pause')
@login_required @login_required
@ -122,7 +122,7 @@ def pause_game(game_name):
game.paused = True game.paused = True
db.session.commit() db.session.commit()
flash(f"Game '{game.name}' has been paused!") flash(f"Game '{game.name}' has been paused!")
return redirect(url_for('main.index')) return redirect(url_for('main.game_dashboard', game_name=game.name))
@bp.route('/game/<game_name>/unpause') @bp.route('/game/<game_name>/unpause')
@bp.route('/game/<game_name>/resume') @bp.route('/game/<game_name>/resume')
@ -131,8 +131,8 @@ def resume_game(game_name):
game = get_game_if_owner(game_name) game = get_game_if_owner(game_name)
game.paused = False game.paused = False
db.session.commit() db.session.commit()
flash(f"Game '{game.name}' has been paused!") flash(f"Game '{game.name}' has been resumed!")
return redirect(url_for('main.index')) return redirect(url_for('main.game_dashboard', game_name=game.name))
@bp.route('/game/<game_name>/dashboard') @bp.route('/game/<game_name>/dashboard')

8
app/models/game.py

@ -11,8 +11,8 @@ class Game(db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(64), index=True, unique=True, nullable=False) name = db.Column(db.String(64), index=True, unique=True, nullable=False)
#state = db.Column(db.Enum(GameState), server_default=GameState(1).name, nullable=False) #state = db.Column(db.Enum(GameState), server_default=GameState(1).name, nullable=False)
hidden = db.Column(db.Boolean, server_default='True', nullable=False) hidden = db.Column(db.Boolean, server_default='1', nullable=False)
paused = db.Column(db.Boolean, server_default='False', nullable=False) paused = db.Column(db.Boolean, server_default='0', nullable=False)
start_time = db.Column(db.DateTime) start_time = db.Column(db.DateTime)
end_time = db.Column(db.DateTime) end_time = db.Column(db.DateTime)
players = db.relationship( players = db.relationship(
@ -71,7 +71,7 @@ class Game(db.Model):
for pcp in pcps if pcp.review == Review.none] for pcp in pcps if pcp.review == Review.none]
def is_active(self): def is_active(self):
return self.get_state == GameState.active return self.get_state() == GameState.active
def get_state(self): def get_state(self):
now = datetime.utcnow() now = datetime.utcnow()
@ -85,7 +85,7 @@ class Game(db.Model):
end = (self.end_time or datetime.max).replace(tzinfo=None) end = (self.end_time or datetime.max).replace(tzinfo=None)
if start < now < end: # During Game if start < now < end: # During Game
if self.paused: if self.paused:
return GameState.interrupted return GameState.paused
return GameState.active return GameState.active
if now > end: # After Game if now > end: # After Game

2
app/models/game_state.py

@ -4,6 +4,6 @@ class GameState(Enum):
hidden = 1 hidden = 1
published = 2 published = 2
active = 3 active = 3
interrupted = 4 paused = 4
finished = 5 finished = 5

2
app/models/notification_player.py

@ -4,7 +4,7 @@ class NotificationPlayer(db.Model):
__tablename__ = 'notification_player' __tablename__ = 'notification_player'
notification_id = db.Column(db.Integer, db.ForeignKey('notification.id'), primary_key=True, nullable=False) notification_id = db.Column(db.Integer, db.ForeignKey('notification.id'), primary_key=True, nullable=False)
game_player_id = db.Column(db.Integer, db.ForeignKey('game_player.id'), primary_key=True, nullable=False) game_player_id = db.Column(db.Integer, db.ForeignKey('game_player.id'), primary_key=True, nullable=False)
been_shown = db.Column(db.Boolean, server_default='True', nullable=False) been_shown = db.Column(db.Boolean, server_default='0', nullable=False)
notification = db.relationship('Notification', back_populates='notification_recipients') notification = db.relationship('Notification', back_populates='notification_recipients')
recipient = db.relationship('GamePlayer', back_populates='player_notifications') recipient = db.relationship('GamePlayer', back_populates='player_notifications')

3
app/templates/edit_game.html

@ -10,7 +10,7 @@
{% block app_content %} {% block app_content %}
<h1>{{ title }}</h1> <h1>{{ title }}</h1>
<div class="col-md-4 col-sm-6 col-xs-8"> <div class="col-md-5 col-sm-6 col-xs-8">
<hr> <hr>
<form action="" method="post" class="form" role="form"> <form action="" method="post" class="form" role="form">
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
@ -48,7 +48,6 @@
<button class="btn btn-success">Hide Game</button> <button class="btn btn-success">Hide Game</button>
</a> </a>
{% endif %} {% endif %}
{% if game.paused %} {% if game.paused %}
<a href="{{ url_for('main.resume_game', game_name=game.name) }}"> <a href="{{ url_for('main.resume_game', game_name=game.name) }}">
<button class="btn btn-primary">Resume Game</button> <button class="btn btn-primary">Resume Game</button>

2
documentation/gamestate.txt

@ -4,5 +4,5 @@ This is an attribute of the Game class. It will be implemented as an enum contai
hidden = 1 hidden = 1
published = 2 published = 2
active = 3 active = 3
interrupted = 4 paused = 4
finished = 5 finished = 5

13
migrations/versions/d87b14d6a90c_add_pcp_review.py → migrations/versions/7a3183ce450a_replace_gamestate_with_hidden_and_paused.py

@ -1,8 +1,8 @@
"""add pcp review """replace gamestate with hidden and paused
Revision ID: d87b14d6a90c Revision ID: 7a3183ce450a
Revises: Revises:
Create Date: 2020-07-21 21:47:51.061829 Create Date: 2020-07-29 10:55:07.589462
""" """
from alembic import op from alembic import op
@ -10,7 +10,7 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'd87b14d6a90c' revision = '7a3183ce450a'
down_revision = None down_revision = None
branch_labels = None branch_labels = None
depends_on = None depends_on = None
@ -21,7 +21,8 @@ def upgrade():
op.create_table('game', op.create_table('game',
sa.Column('id', sa.Integer(), nullable=False), sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=64), nullable=False), sa.Column('name', sa.String(length=64), nullable=False),
sa.Column('state', sa.Enum('hidden', 'published', 'active', 'interrupted', 'finished', name='gamestate'), server_default='hidden', nullable=False), sa.Column('hidden', sa.Boolean(), server_default='1', nullable=False),
sa.Column('paused', sa.Boolean(), server_default='0', nullable=False),
sa.Column('start_time', sa.DateTime(), nullable=True), sa.Column('start_time', sa.DateTime(), nullable=True),
sa.Column('end_time', sa.DateTime(), nullable=True), sa.Column('end_time', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id') sa.PrimaryKeyConstraint('id')
@ -79,7 +80,7 @@ def upgrade():
op.create_table('notification_player', op.create_table('notification_player',
sa.Column('notification_id', sa.Integer(), nullable=False), sa.Column('notification_id', sa.Integer(), nullable=False),
sa.Column('game_player_id', sa.Integer(), nullable=False), sa.Column('game_player_id', sa.Integer(), nullable=False),
sa.Column('been_shown', sa.Boolean(), server_default='True', nullable=False), sa.Column('been_shown', sa.Boolean(), server_default='0', nullable=False),
sa.ForeignKeyConstraint(['game_player_id'], ['game_player.id'], ), sa.ForeignKeyConstraint(['game_player_id'], ['game_player.id'], ),
sa.ForeignKeyConstraint(['notification_id'], ['notification.id'], ), sa.ForeignKeyConstraint(['notification_id'], ['notification.id'], ),
sa.PrimaryKeyConstraint('notification_id', 'game_player_id') sa.PrimaryKeyConstraint('notification_id', 'game_player_id')
Loading…
Cancel
Save