diff --git a/colors/scoreboard.json.example b/colors/scoreboard.json.example index ddff96ab..b016193b 100644 --- a/colors/scoreboard.json.example +++ b/colors/scoreboard.json.example @@ -124,10 +124,15 @@ "g": 255, "b": 255 }, - "strikeout": { + "play_result": { "r": 255, "g": 235, "b": 59 + }, + "strikeout": { + "r": 255, + "g": 0, + "b": 0 } }, "batter_count": { diff --git a/coordinates/w128h32.json.example b/coordinates/w128h32.json.example index 75e49010..bc916972 100644 --- a/coordinates/w128h32.json.example +++ b/coordinates/w128h32.json.example @@ -183,9 +183,10 @@ "append_pitcher_name": false }, "loop": 64, - "strikeout": { - "x": 84, - "y": 30 + "play_result": { + "x": 60, + "y": 30, + "desc_length": "short" } }, "pregame": { diff --git a/coordinates/w128h64.json.example b/coordinates/w128h64.json.example index 92c0feb2..babb6d54 100644 --- a/coordinates/w128h64.json.example +++ b/coordinates/w128h64.json.example @@ -145,9 +145,10 @@ "append_pitcher_name": false }, "loop": 68, - "strikeout": { - "x": 32, - "y": 60 + "play_result": { + "x": 16, + "y": 60, + "desc_length": "long" } }, "batter_count": { diff --git a/coordinates/w192h64.json.example b/coordinates/w192h64.json.example index 87cdd9dc..5334dc6a 100644 --- a/coordinates/w192h64.json.example +++ b/coordinates/w192h64.json.example @@ -145,9 +145,10 @@ "append_pitcher_name": false }, "loop": 68, - "strikeout": { - "x": 32, - "y": 60 + "play_result": { + "x": 16, + "y": 60, + "desc_length": "Long" } }, "batter_count": { diff --git a/coordinates/w32h32.json.example b/coordinates/w32h32.json.example index 7a71fad6..44598f71 100644 --- a/coordinates/w32h32.json.example +++ b/coordinates/w32h32.json.example @@ -163,9 +163,10 @@ "append_pitcher_name": false }, "loop": 16, - "strikeout": { + "play_result": { "x": 33, - "y": 33 + "y": 33, + "desc_length": "short" } }, "batter_count": { diff --git a/coordinates/w64h32.json.example b/coordinates/w64h32.json.example index 6c98341a..b8345e24 100644 --- a/coordinates/w64h32.json.example +++ b/coordinates/w64h32.json.example @@ -139,11 +139,13 @@ "append_pitcher_name": false }, "loop": 36, - "strikeout": { + "play_result": { "x": 15, "y": 29, - "font_name": "5x7" + "font_name": "5x7", + "desc_length": "short" } + }, "batter_count": { "x": 34, diff --git a/coordinates/w64h64.json.example b/coordinates/w64h64.json.example index 36c5ef64..f97c1b27 100644 --- a/coordinates/w64h64.json.example +++ b/coordinates/w64h64.json.example @@ -139,9 +139,10 @@ "append_pitcher_name": false }, "loop": 64, - "strikeout": { + "play_result": { "x": 31, - "y": 36 + "y": 36, + "desc_length": "short" } }, "pregame": { diff --git a/data/plays.py b/data/plays.py new file mode 100644 index 00000000..205a113d --- /dev/null +++ b/data/plays.py @@ -0,0 +1,61 @@ +SINGLE = "single" +DOUBLE = "double" +TRIPLE = "triple" +HOME_RUN = "home_run" + +WALK = "walk" +INTENTIONAL_WALK = "intent_walk" + +STRIKEOUT = "strikeout" +STRIKEOUT_LOOKING = "strikeout_looking" + +HITS = [ + SINGLE, + DOUBLE, + TRIPLE +] + +WALKS = [ + WALK, + INTENTIONAL_WALK +] + +STRIKEOUTS = [ + STRIKEOUT, + STRIKEOUT_LOOKING +] + +PLAY_RESULTS = { + SINGLE: { + "short": "1B", + "long": "Single" + }, + DOUBLE: { + "short": "2B", + "long": "Double" + }, + TRIPLE: { + "short": "3B", + "long": "Triple" + }, + HOME_RUN: { + "short": "HR", + "long": "Home Run" + }, + WALK: { + "short": "BB", + "long": "Walk" + }, + INTENTIONAL_WALK: { + "short": "IBB", + "long": "Int. Walk" + }, + STRIKEOUT: { + "short": "K", + "long": "K" + }, + STRIKEOUT_LOOKING: { + "short": "ꓘ", + "long": "ꓘ" + } +} \ No newline at end of file diff --git a/data/scoreboard/__init__.py b/data/scoreboard/__init__.py index 93ff5eb6..649d328a 100644 --- a/data/scoreboard/__init__.py +++ b/data/scoreboard/__init__.py @@ -5,6 +5,8 @@ from data.scoreboard.outs import Outs from data.scoreboard.pitches import Pitches from data.scoreboard.team import Team +from data import plays + class Scoreboard: @@ -41,6 +43,12 @@ def strikeout(self): def strikeout_looking(self): return self.play_result == "strikeout_looking" + + def hit(self): + return self.play_result in plays.HITS + + def walk(self): + return self.play_result in plays.WALKS def get_text_for_reason(self): if self.note: diff --git a/renderers/games/game.py b/renderers/games/game.py index cac05611..4773c4dc 100644 --- a/renderers/games/game.py +++ b/renderers/games/game.py @@ -6,26 +6,26 @@ from data.scoreboard.bases import Bases from data.scoreboard.inning import Inning from data.scoreboard.pitches import Pitches +from data.plays import PLAY_RESULTS + from renderers import scrollingtext from renderers.games import nohitter def render_live_game(canvas, layout: Layout, colors: Color, scoreboard: Scoreboard, text_pos, animation_time): pos = 0 - if scoreboard.inning.state == Inning.TOP or scoreboard.inning.state == Inning.BOTTOM: - pos = _render_at_bat( - canvas, - layout, - colors, - scoreboard.atbat, - text_pos, - scoreboard.strikeout(), - scoreboard.strikeout_looking(), - (animation_time // 6) % 2, - scoreboard.pitches, - ) + canvas, + layout, + colors, + scoreboard.atbat, + text_pos, + scoreboard.play_result, + (animation_time // 6) % 2, + scoreboard.pitches + + ) # Check if we're deep enough into a game and it's a no hitter or perfect game should_display_nohitter = layout.coords("nohitter")["innings_until_display"] @@ -38,6 +38,7 @@ def render_live_game(canvas, layout: Layout, colors: Color, scoreboard: Scoreboa _render_bases(canvas, layout, colors, scoreboard.bases, scoreboard.homerun(), (animation_time % 16) // 5) _render_inning_display(canvas, layout, colors, scoreboard.inning) + else: _render_inning_break(canvas, layout, colors, scoreboard.inning) _render_due_up(canvas, layout, colors, scoreboard.atbat) @@ -46,27 +47,33 @@ def render_live_game(canvas, layout: Layout, colors: Color, scoreboard: Scoreboa # --------------- at-bat --------------- -def _render_at_bat(canvas, layout, colors, atbat: AtBat, text_pos, strikeout, looking, animation, pitches: Pitches): +def _render_at_bat(canvas, layout, colors, atbat: AtBat, text_pos, play_result, animation, pitches: Pitches): plength = __render_pitcher_text(canvas, layout, colors, atbat.pitcher, pitches, text_pos) __render_pitch_text(canvas, layout, colors, pitches) __render_pitch_count(canvas, layout, colors, pitches) - if strikeout: + results = list(PLAY_RESULTS.keys()) + if play_result in results: if animation: - __render_strikeout(canvas, layout, colors, looking) + __render_play_result(canvas, layout, colors, play_result) return plength else: blength = __render_batter_text(canvas, layout, colors, atbat.batter, text_pos) return max(plength, blength) - -def __render_strikeout(canvas, layout, colors, looking): - coords = layout.coords("atbat.strikeout") - color = colors.graphics_color("atbat.strikeout") - font = layout.font("atbat.strikeout") - text = "ꓘ" if looking else "K" +def __render_play_result(canvas, layout, colors, play_result): + + coords = layout.coords("atbat.play_result") + if "strikeout" in play_result: + color = colors.graphics_color("atbat.strikeout") + else: + color = colors.graphics_color("atbat.play_result") + font = layout.font("atbat.play_result") + try: + text = PLAY_RESULTS[play_result][coords["desc_length"]] + except KeyError: + return # There's no text or coordinates to render graphics.DrawText(canvas, font["font"], coords["x"], coords["y"], color, text) - def __render_batter_text(canvas, layout, colors, batter, text_pos): coords = layout.coords("atbat.batter") color = colors.graphics_color("atbat.batter") @@ -242,6 +249,7 @@ def __fill_out_circle(canvas, out, color): # --------------- inning information --------------- def _render_inning_break(canvas, layout, colors, inning: Inning): + text_font = layout.font("inning.break.text") num_font = layout.font("inning.break.number") text_coords = layout.coords("inning.break.text") diff --git a/renderers/main.py b/renderers/main.py index c98ef020..bf7eb5ac 100644 --- a/renderers/main.py +++ b/renderers/main.py @@ -153,7 +153,7 @@ def __draw_game(self): self.data.scrolling_finished = True else: # draw a live game - if scoreboard.homerun() or scoreboard.strikeout(): + if scoreboard.homerun() or scoreboard.strikeout() or scoreboard.hit() or scoreboard.walk(): self.animation_time += 1 else: self.animation_time = 0