From c4d3cd0172d0f503368dd81059a9a093b4ef67f0 Mon Sep 17 00:00:00 2001 From: Jiri Kalvoda Date: Sat, 17 Sep 2022 00:41:32 +0200 Subject: [PATCH] =?UTF-8?q?Startegick=C3=A1:=20Update=20grafick=C3=A9ho=20?= =?UTF-8?q?zobrazov=C3=A1tka?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/hra/db.py | 5 +++++ server/hra/web/game.py | 16 +++++++++++----- server/hra/web/pages.py | 4 ++-- server/static/occupy.css | 5 +++-- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/server/hra/db.py b/server/hra/db.py index 8710ec3..5c9307c 100644 --- a/server/hra/db.py +++ b/server/hra/db.py @@ -165,6 +165,11 @@ class Team(Base): game = relationship('Game', primaryjoin='Team.game_id == Game.game_id') user = relationship('User', primaryjoin='Team.user_id == User.id') + def print(self): + if self.user is None: + return f"{self.team_id}: -" + return f"{self.team_id}: {self.user.username}" + class State(Base): __tablename__ = 'states' diff --git a/server/hra/web/game.py b/server/hra/web/game.py index f4b3b83..d7fa833 100644 --- a/server/hra/web/game.py +++ b/server/hra/web/game.py @@ -10,7 +10,7 @@ import werkzeug.exceptions import wtforms from wtforms.fields import EmailField from wtforms.widgets import NumberInput -from typing import Optional, Any +from typing import Optional, Any, List import hra.config as config import hra.web.html as html @@ -42,12 +42,13 @@ class WLogic: @add_wlogic class Occupy(WLogic): - def view(self, state: db.State, team: Optional[db.Team]): + def view(self, state: db.State, team: Optional[db.Team], teams: List[db.Team]): s = state.get_state() if team is not None: s = self.logic.personalize_state(s, team.team_id, state.round) b = BasePage() b.h2(f"Hra {self.game.print()} kolo {state.round}") + b.p().b(_class=f"game_team_{team.team_id}")(f"Pohled týmu {team.print()}") with b.table(_class="game_table"): for i, row in enumerate(s["map"]): with b.tr(): @@ -58,6 +59,8 @@ class Occupy(WLogic): with b.td(): classes = [] with b.a(href=f"#cell_{i}_{j}"): + if x["protected_for_team"] is not None: + classes.append("game_protected") if x["hill"]: classes.append("game_hill") b(Markup(" ")) @@ -76,6 +79,7 @@ class Occupy(WLogic): for i, row in enumerate(s["map"]): for j, x in enumerate(row): occupied_by_team = x["occupied_by_team"] + protected_for_team = x["protected_for_team"] home_for_team = x["home_for_team"] members = x["members"] with b.div(id=f"cell_{i}_{j}", _class="game_tab"): @@ -84,13 +88,15 @@ class Occupy(WLogic): b.p().b("Pohoří") else: if occupied_by_team is not None: - b.p(_class=f"game_team_{occupied_by_team}").b(f"Obsazeno týmem: {occupied_by_team}") + b.p(_class=f"game_team_{occupied_by_team}").b(f"Obsazeno týmem: {teams[occupied_by_team].print()}") + if protected_for_team is not None: + b.p(_class=f"game_team_{protected_for_team}").b(f"Ochranné území týmu: {teams[protected_for_team].print()}") if home_for_team is not None: - b.p(_class=f"game_team_{home_for_team}").b(f"Domov týmu: {home_for_team}") + b.p(_class=f"game_team_{home_for_team}").b(f"Domov týmu: {teams[home_for_team].print()}") b.p().b(f"Počet osob: {len(members)}") with b.ul(): for m in members: - b.li(_class=f"game_team_{home_for_team}")(f"Voják {m['id']} týmu {m['team']}") + b.li(_class=f"game_team_{home_for_team}")(f"Voják {m['id']} týmu {teams[m['team']].print()}") b.wrap( diff --git a/server/hra/web/pages.py b/server/hra/web/pages.py index 0129239..7845c94 100644 --- a/server/hra/web/pages.py +++ b/server/hra/web/pages.py @@ -287,11 +287,11 @@ def web_game_step(game_id): return redirect(app.url_for(web_game.__name__, game_id=game_id)) -@app.route("/game//view", methods=['GET']) @app.route("/game//view/", methods=['GET']) def web_game_view(game_id, team_id=None): ses = db.get_session() game = ses.query(db.Game).filter_by(game_id=game_id).one_or_none() + teams = ses.query(db.Team).filter_by(game_id=game_id).order_by(db.Team.team_id).all() if game is None: raise werkzeug.exceptions.NotFound() if not right_for_game(game): @@ -314,7 +314,7 @@ def web_game_view(game_id, team_id=None): if state is None: raise werkzeug.exceptions.NotFound() - return wl.view(state, team) + return wl.view(state, team, teams) diff --git a/server/static/occupy.css b/server/static/occupy.css index 0af694c..d4b58c7 100644 --- a/server/static/occupy.css +++ b/server/static/occupy.css @@ -13,9 +13,10 @@ table.game_table tr td { text-align: end; } -td.game_home { - border: 4pt solid black; +td.game_protected { + border: medium solid black !important; } + td.game_hill { background-color: black; }