Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ty-porter authored Jul 16, 2023
2 parents f8d6c28 + c5160bc commit ae4887c
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 9 deletions.
Binary file added assets/mlb-w128h32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions coordinates/w128h32.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions coordinates/w128h64.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions coordinates/w192h64.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions coordinates/w32h32.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions coordinates/w64h32.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions coordinates/w64h64.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 8 additions & 5 deletions data/config/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 7 additions & 1 deletion data/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,"
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions data/scoreboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion data/scoreboard/team.py
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions renderers/games/teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit ae4887c

Please sign in to comment.