diff --git a/assets/mlb-w128h32.png b/assets/mlb-w128h32.png new file mode 100644 index 00000000..5a8ebe4a Binary files /dev/null and b/assets/mlb-w128h32.png differ diff --git a/coordinates/w128h32.json.example b/coordinates/w128h32.json.example index 4324094b..df1e5c60 100644 --- a/coordinates/w128h32.json.example +++ b/coordinates/w128h32.json.example @@ -292,6 +292,19 @@ "y": 10 } }, + "record": { + "enabled": false, + "away": { + "font_name": "4x6", + "x": 19, + "y": 7 + }, + "home": { + "font_name": "4x6", + "x": 19, + "y": 17 + } + }, "runs": { "runs_hits_errors": { "show": false, diff --git a/coordinates/w128h64.json.example b/coordinates/w128h64.json.example index 6aa5f343..babb6d54 100644 --- a/coordinates/w128h64.json.example +++ b/coordinates/w128h64.json.example @@ -272,6 +272,17 @@ "y": 29 } }, + "record": { + "enabled": false, + "away": { + "x": 30, + "y": 13 + }, + "home": { + "x": 30, + "y": 29 + } + }, "runs": { "runs_hits_errors": { "show": true, diff --git a/coordinates/w192h64.json.example b/coordinates/w192h64.json.example index eaf05fc7..5334dc6a 100644 --- a/coordinates/w192h64.json.example +++ b/coordinates/w192h64.json.example @@ -272,6 +272,17 @@ "y": 29 } }, + "record": { + "enabled": false, + "away": { + "x": 30, + "y": 13 + }, + "home": { + "x": 30, + "y": 29 + } + }, "runs": { "runs_hits_errors": { "show": true, diff --git a/coordinates/w32h32.json.example b/coordinates/w32h32.json.example index da1604d0..4192694e 100644 --- a/coordinates/w32h32.json.example +++ b/coordinates/w32h32.json.example @@ -279,6 +279,17 @@ "y": 13 } }, + "record": { + "enabled": false, + "away": { + "x": 4, + "y": 6 + }, + "home": { + "x": 4, + "y": 13 + } + }, "runs": { "runs_hits_errors": { "show": false, diff --git a/coordinates/w64h32.json.example b/coordinates/w64h32.json.example index 4a25e93d..b37f3519 100644 --- a/coordinates/w64h32.json.example +++ b/coordinates/w64h32.json.example @@ -265,6 +265,17 @@ "y": 7 } }, + "record": { + "enabled": false, + "away": { + "x": 15, + "y": 6 + }, + "home": { + "x": 15, + "y": 13 + } + }, "runs": { "runs_hits_errors": { "show": true, diff --git a/coordinates/w64h64.json.example b/coordinates/w64h64.json.example index 93fe3d10..e48f2a77 100644 --- a/coordinates/w64h64.json.example +++ b/coordinates/w64h64.json.example @@ -248,6 +248,19 @@ "y": 10 } }, + "record": { + "enabled": false, + "away": { + "font_name": "4x6", + "x": 18, + "y": 7 + }, + "home": { + "font_name": "4x6", + "x": 18, + "y": 17 + } + }, "runs": { "runs_hits_errors": { "show": false, diff --git a/data/config/layout.py b/data/config/layout.py index 89a8134f..88fdef50 100644 --- a/data/config/layout.py +++ b/data/config/layout.py @@ -36,14 +36,17 @@ def font(self, keypath): def coords(self, keypath): try: - d = self.__find_at_keypath(keypath) + coord_dict = self.__find_at_keypath(keypath) except KeyError as e: raise e - if self.state in AVAILABLE_OPTIONAL_KEYS: - if self.state in d: - return d[self.state] - return d + if not isinstance(coord_dict, dict) or not self.state in AVAILABLE_OPTIONAL_KEYS: + return coord_dict + + if self.state in coord_dict: + return coord_dict[self.state] + + return coord_dict def set_state(self, new_state=None): if new_state in AVAILABLE_OPTIONAL_KEYS: diff --git a/data/game.py b/data/game.py index ef7da6c8..9996bec4 100644 --- a/data/game.py +++ b/data/game.py @@ -10,7 +10,7 @@ API_FIELDS = ( "gameData,game,id,datetime,dateTime,officialDate,flags,noHitter,perfectGame,status,detailedState,abstractGameState," - + "reason,probablePitchers,teams,home,away,abbreviation,teamName,players,id,boxscoreName,fullName,liveData,plays," + + "reason,probablePitchers,teams,home,away,abbreviation,teamName,record,wins,losses,players,id,boxscoreName,fullName,liveData,plays," + "currentPlay,result,eventType,playEvents,isPitch,pitchData,startSpeed,details,type,code,description,decisions," + "winner,loser,save,id,linescore,outs,balls,strikes,note,inningState,currentInning,currentInningOrdinal,offense," + "batter,inHole,onDeck,first,second,third,defense,pitcher,boxscore,teams,runs,players,seasonStats,pitching,wins," @@ -88,6 +88,12 @@ def home_name(self): def home_abbreviation(self): return self._current_data["gameData"]["teams"]["home"]["abbreviation"] + + def home_record(self): + return self._current_data["gameData"]["teams"]["home"]["record"] or {} + + def away_record(self): + return self._current_data["gameData"]["teams"]["away"]["record"] or {} def pregame_weather(self): try: diff --git a/data/scoreboard/__init__.py b/data/scoreboard/__init__.py index 78f71918..649d328a 100644 --- a/data/scoreboard/__init__.py +++ b/data/scoreboard/__init__.py @@ -17,10 +17,10 @@ class Scoreboard: def __init__(self, game: Game): self.away_team = Team( - game.away_abbreviation(), game.away_score(), game.away_name(), game.away_hits(), game.away_errors() + game.away_abbreviation(), game.away_score(), game.away_name(), game.away_hits(), game.away_errors(), game.away_record() ) self.home_team = Team( - game.home_abbreviation(), game.home_score(), game.home_name(), game.home_hits(), game.home_errors() + game.home_abbreviation(), game.home_score(), game.home_name(), game.home_hits(), game.home_errors(), game.home_record() ) self.inning = Inning(game) self.bases = Bases(game) diff --git a/data/scoreboard/team.py b/data/scoreboard/team.py index 08510776..535808ce 100644 --- a/data/scoreboard/team.py +++ b/data/scoreboard/team.py @@ -1,7 +1,8 @@ class Team: - def __init__(self, abbrev, runs, name, hits, errors): + def __init__(self, abbrev, runs, name, hits, errors, record): self.abbrev = abbrev self.runs = runs self.name = name self.hits = hits self.errors = errors + self.record = record diff --git a/renderers/games/teams.py b/renderers/games/teams.py index fc3d6ea5..5d7bb78f 100644 --- a/renderers/games/teams.py +++ b/renderers/games/teams.py @@ -58,6 +58,9 @@ def render_team_banner( __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) + __render_record_text(canvas, layout, away_colors, away_team, "away", default_colors) + __render_record_text(canvas, layout, home_colors, home_team, "home", default_colors) + if show_score: # Number of characters in each score. score_spacing = { @@ -110,6 +113,19 @@ def __render_team_text(canvas, layout, colors, team, homeaway, full_team_names, team_text = "{:13s}".format(team.name) 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): + if "losses" not in team.record or "wins" not in team.record: + return + if not layout.coords("teams.record").get("enabled", False): + return + + text_color = colors.get("text", default_colors["text"]) + text_color_graphic = graphics.Color(text_color["r"], text_color["g"], text_color["b"]) + 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) + def __render_score_component(canvas, layout, colors, homeaway, default_colors, coords, component_val, width_chars): # The coords passed in are the rightmost pixel.