Startegická: Update grafického zobrazovátka
This commit is contained in:
parent
d07354c2c5
commit
c4d3cd0172
4 changed files with 21 additions and 9 deletions
|
@ -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'
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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/<int:game_id>/view", methods=['GET'])
|
||||
@app.route("/game/<int:game_id>/view/<int:team_id>", 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)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue