Skip to content

Commit

Permalink
Add relative positioning option for team records
Browse files Browse the repository at this point in the history
  • Loading branch information
ty-porter committed May 17, 2024
1 parent ce459d3 commit ed979cb
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 15 deletions.
3 changes: 2 additions & 1 deletion coordinates/w128h32.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@
},
"record": {
"enabled": false,
"position": "absolute",
"away": {
"font_name": "4x6",
"x": 19,
Expand Down Expand Up @@ -378,4 +379,4 @@
"y": 31
}
}
}
}
3 changes: 2 additions & 1 deletion coordinates/w128h64.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
},
"record": {
"enabled": false,
"position": "absolute",
"away": {
"x": 30,
"y": 13
Expand Down Expand Up @@ -359,4 +360,4 @@
"y": 63
}
}
}
}
3 changes: 2 additions & 1 deletion coordinates/w192h64.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
},
"record": {
"enabled": false,
"position": "absolute",
"away": {
"x": 30,
"y": 13
Expand Down Expand Up @@ -359,4 +360,4 @@
"y": 63
}
}
}
}
3 changes: 2 additions & 1 deletion coordinates/w32h32.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@
},
"record": {
"enabled": false,
"position": "absolute",
"away": {
"x": 4,
"y": 6
Expand Down Expand Up @@ -363,4 +364,4 @@
"y": 31
}
}
}
}
4 changes: 2 additions & 2 deletions coordinates/w64h32.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@
"desc_length": "short",
"enabled": true
}

},
"batter_count": {
"x": 34,
Expand Down Expand Up @@ -275,6 +274,7 @@
},
"record": {
"enabled": false,
"position": "absolute",
"away": {
"x": 15,
"y": 6
Expand Down Expand Up @@ -350,4 +350,4 @@
"y": 31
}
}
}
}
3 changes: 2 additions & 1 deletion coordinates/w64h64.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
},
"record": {
"enabled": false,
"position": "absolute",
"away": {
"font_name": "4x6",
"x": 18,
Expand Down Expand Up @@ -334,4 +335,4 @@
"y": 63
}
}
}
}
27 changes: 19 additions & 8 deletions renderers/games/teams.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from driver import graphics

ABSOLUTE = "absolute"
RELATIVE = "relative"

def render_team_banner(
canvas, layout, team_colors, home_team, away_team, full_team_names, short_team_names_for_runs_hits, show_score,
):
Expand Down Expand Up @@ -55,11 +58,11 @@ def render_team_banner(
canvas, full_team_names, short_team_names_for_runs_hits, [home_team, away_team]
)

__render_team_text(canvas, layout, away_colors, away_team, "away", use_full_team_names, default_colors)
__render_team_text(canvas, layout, home_colors, home_team, "home", use_full_team_names, default_colors)
away_name_end_pos = __render_team_text(canvas, layout, away_colors, away_team, "away", use_full_team_names, default_colors)
home_name_end_pos = __render_team_text(canvas, layout, home_colors, home_team, "home", use_full_team_names, default_colors)

__render_record_text(canvas, layout, away_colors, away_team, "away", default_colors)
__render_record_text(canvas, layout, home_colors, home_team, "home", default_colors)
__render_record_text(canvas, layout, away_colors, away_team, "away", default_colors, away_name_end_pos)
__render_record_text(canvas, layout, home_colors, home_team, "home", default_colors, home_name_end_pos)

if show_score:
# Number of characters in each score.
Expand Down Expand Up @@ -108,12 +111,14 @@ def __render_team_text(canvas, layout, colors, team, homeaway, full_team_names,
text_color_graphic = graphics.Color(text_color["r"], text_color["g"], text_color["b"])
coords = layout.coords("teams.name.{}".format(homeaway))
font = layout.font("teams.name.{}".format(homeaway))
team_text = "{:3s}".format(team.abbrev.upper())
team_text = "{:3s}".format(team.abbrev.upper()).strip()
if full_team_names:
team_text = "{:13s}".format(team.name)
team_text = "{:13s}".format(team.name).strip()
graphics.DrawText(canvas, font["font"], coords["x"], coords["y"], text_color_graphic, team_text)

def __render_record_text(canvas, layout, colors, team, homeaway, default_colors):
return (coords["x"] + (len(team_text) * font["size"]["width"]), coords["y"])

def __render_record_text(canvas, layout, colors, team, homeaway, default_colors, origin):
if "losses" not in team.record or "wins" not in team.record:
return
if not layout.coords("teams.record").get("enabled", False):
Expand All @@ -124,8 +129,14 @@ def __render_record_text(canvas, layout, colors, team, homeaway, default_colors)
coords = layout.coords("teams.record.{}".format(homeaway))
font = layout.font("teams.record.{}".format(homeaway))
record_text = "({}-{})".format(team.record["wins"], team.record["losses"])
graphics.DrawText(canvas, font["font"], coords["x"], coords["y"], text_color_graphic, record_text)

if layout.coords("teams.record").get("position", ABSOLUTE) != RELATIVE:
origin = (0, 0)

x = coords["x"] + origin[0]
y = coords["y"] + origin[1]

graphics.DrawText(canvas, font["font"], x, y, text_color_graphic, record_text)

def __render_score_component(canvas, layout, colors, homeaway, default_colors, coords, component_val, width_chars):
# The coords passed in are the rightmost pixel.
Expand Down

0 comments on commit ed979cb

Please sign in to comment.