Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative team records positioning #538

Merged
merged 2 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions coordinates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ You can edit these coordinates to display parts of the scoreboard in any way you
## Example
If you have a 64x32 board, copy `w64h32.json.example` to a new file called `w64h32.json`, then edit the coordinates in that file as you see fit. Your customized coordinates will always take precedence.

>!WARNING
> **DO NOT** remove `.example` files! **Copy** the files instead.
>
> These are checked by the software to determine which matrix dimensions are supported. If you remove the file, the scoreboard may fail to start.

## Fonts
Any scoreboard element that prints text can accept a `"font_name"` attribute. Supported fonts need to be named with `<width>x<height>.bdf` (or `<width>x<height>B.bdf` for bold fonts). The font loader will search `assets/` first for the specified font and then it will fall back to searching `matrix/fonts/` if one was not found.

Expand All @@ -19,13 +24,18 @@ The layout can have a couple of different states where things are rendered diffe
* `spacing` is the number of pixels between the runs/hits and hits/errors.

## Pitch Data
* `enabled` (true/false) turn feature on/off
* `enabled` (true/false) Turn feature on/off
* `mph` (true/false) When rendering pitch speed add mph after (99 mph)
* `desc_length` (short/long) The short or long pitch type description, you can change both the short and long description to your liking in data/pitches as long as you do not change the index value.

## Play Result
* `enabled` (true/false) turn feature on/off
* `desc_length` (short/long) The short or long play result description. You can change both the short and long description to your liking in data/plays.
* `enabled` (true/false) Turn feature on/off
* `desc_length` (short/long) The short or long play result description.

## Team Records During Games
Team records can be displayed on the team banner during most game states, such as pregame, live, and postgame.
* `enabled` (true/false) Turn feature on/off
* `position` (absolute/relative) Defines origin of the text. When `absolute`, the origin is always `(0, 0)`. When `relative`, the origin is relative to the end of the team name in the banner.

## Updates
The software develops and releases features with full support for the default layouts, so custom layouts may look unsatisfactory if you update to later versions of the scoreboard. If you as a user decide to create a custom layout file, you are responsible for tweaking the coordinates to your liking with each update.
Expand All @@ -34,5 +44,5 @@ The software develops and releases features with full support for the default la
A couple of things are not completely implemented or have some implementation details you should understand.

* `bases` currently requires an even `size` value to be rendered correctly
* Not all options are enabled on all board sizes by default. For example pitch count and pitch type are not enabled by default on boards smaller than 64x64. Options are "disabled" by forcing them to render outside the board, by setting X and Y coordinates less than 0 or greater than the height or width of the board.
* Not all options are enabled on all board sizes by default. For example pitch count and pitch type are not enabled by default on boards smaller than 64x64. Options are "disabled" by forcing them to render outside the board, by setting X and Y coordinates less than 0 or greater than the height or width of the board.

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
Loading