From db2b95b1daf2352594e968e53499d287892b8589 Mon Sep 17 00:00:00 2001 From: jimcreel Date: Fri, 14 Jul 2023 18:00:46 -0700 Subject: [PATCH 01/12] renders play result for hits and walks --- colors/scoreboard.json.example | 10 ++++++++ coordinates/w64h32.json.example | 10 ++++++++ data/scoreboard/__init__.py | 12 +++++++++ renderers/games/game.py | 43 ++++++++++++++++++++++++--------- renderers/main.py | 2 +- 5 files changed, 64 insertions(+), 13 deletions(-) diff --git a/colors/scoreboard.json.example b/colors/scoreboard.json.example index ddff96ab..6dc30961 100644 --- a/colors/scoreboard.json.example +++ b/colors/scoreboard.json.example @@ -128,6 +128,16 @@ "r": 255, "g": 235, "b": 59 + }, + "hit": { + "r": 255, + "g": 235, + "b": 59 + }, + "walk": { + "r": 255, + "g": 235, + "b": 59 } }, "batter_count": { diff --git a/coordinates/w64h32.json.example b/coordinates/w64h32.json.example index d36bd9e6..93a01aff 100644 --- a/coordinates/w64h32.json.example +++ b/coordinates/w64h32.json.example @@ -143,6 +143,16 @@ "x": 15, "y": 29, "font_name": "5x7" + }, + "hit": { + "x": 15, + "y": 29, + "font_name": "5x7" + }, + "walk": { + "x": 15, + "y": 29, + "font_name": "5x7" } }, "batter_count": { diff --git a/data/scoreboard/__init__.py b/data/scoreboard/__init__.py index 6ac59f6d..88b2c4cf 100644 --- a/data/scoreboard/__init__.py +++ b/data/scoreboard/__init__.py @@ -41,6 +41,18 @@ def strikeout(self): def strikeout_looking(self): return self.play_result == "strikeout_looking" + + def single(self): + return self.play_result == "single" + + def double(self): + return self.play_result == "double" + + def triple(self): + return self.play_result == "triple" + + def walk(self): + return self.play_result == "walk" def get_text_for_reason(self): if self.note: diff --git a/renderers/games/game.py b/renderers/games/game.py index cac05611..7953cdcd 100644 --- a/renderers/games/game.py +++ b/renderers/games/game.py @@ -9,13 +9,12 @@ from renderers import scrollingtext from renderers.games import nohitter - +PLAY_RESULT_UPDATES = ["single", "double", "triple", "walk", "home_run", "strikeout", "strikeout_looking"] 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( + pos = _render_at_bat( canvas, layout, colors, @@ -23,21 +22,24 @@ def render_live_game(canvas, layout: Layout, colors: Color, scoreboard: Scoreboa text_pos, scoreboard.strikeout(), scoreboard.strikeout_looking(), + scoreboard.play_result, (animation_time // 6) % 2, - scoreboard.pitches, + 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"] - if scoreboard.inning.number > should_display_nohitter: - if layout.state_is_nohitter(): - nohitter.render_nohit_text(canvas, layout, colors) + should_display_nohitter = layout.coords("nohitter")["innings_until_display"] + if scoreboard.inning.number > should_display_nohitter: + if layout.state_is_nohitter(): + nohitter.render_nohit_text(canvas, layout, colors) _render_count(canvas, layout, colors, scoreboard.pitches) _render_outs(canvas, layout, colors, scoreboard.outs) _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,18 +48,36 @@ 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, strikeout, looking, 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: - if animation: + if play_result and play_result in PLAY_RESULT_UPDATES: + if animation and strikeout: __render_strikeout(canvas, layout, colors, looking) + else: + __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_play_result(canvas, layout, colors, play_result): + text = "" + if play_result == "single": + text = "1B" + elif play_result == "double": + text = "2B" + elif play_result == "triple": + text = "3B" + elif play_result == "walk": + text = "BB" + elif play_result == "home_run": + text = "HR" + coords = layout.coords("atbat.strikeout") + color = colors.graphics_color("atbat.strikeout") + font = layout.font("atbat.strikeout") + graphics.DrawText(canvas, font["font"], coords["x"], coords["y"], color, text) def __render_strikeout(canvas, layout, colors, looking): coords = layout.coords("atbat.strikeout") @@ -66,7 +86,6 @@ def __render_strikeout(canvas, layout, colors, looking): text = "ꓘ" if looking else "K" 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") diff --git a/renderers/main.py b/renderers/main.py index c98ef020..dd4dd5e0 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.single() or scoreboard.double() or scoreboard.triple() or scoreboard.walk(): self.animation_time += 1 else: self.animation_time = 0 From 31ecbc9db16beb9d8835d9671ce7dc6aee68383a Mon Sep 17 00:00:00 2001 From: jimcreel Date: Fri, 14 Jul 2023 22:03:12 -0700 Subject: [PATCH 02/12] replaced __render_strikeout with __render_play_result --- renderers/games/game.py | 108 ++++++++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 42 deletions(-) diff --git a/renderers/games/game.py b/renderers/games/game.py index 7953cdcd..b2c94b78 100644 --- a/renderers/games/game.py +++ b/renderers/games/game.py @@ -9,30 +9,66 @@ from renderers import scrollingtext from renderers.games import nohitter -PLAY_RESULT_UPDATES = ["single", "double", "triple", "walk", "home_run", "strikeout", "strikeout_looking"] +PLAY_RESULT_UPDATES = ["single", "double", "triple", "walk", "intent_walk", "home_run", "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" + }, + "intent_walk": { + "short": "IBB", + "long": "Int. Walk" + }, + "strikeout": { + "short": "K", + "long": "K" + }, + "strikeout_looking": { + "short": "ꓘ", + "long" : "ꓘ" + } + +} + 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(), - scoreboard.play_result, - (animation_time // 6) % 2, - scoreboard.pitches - - ) + pos = _render_at_bat( + canvas, + layout, + colors, + scoreboard.atbat, + text_pos, + scoreboard.strikeout(), + scoreboard.strikeout_looking(), + 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"] - if scoreboard.inning.number > should_display_nohitter: - if layout.state_is_nohitter(): - nohitter.render_nohit_text(canvas, layout, colors) + should_display_nohitter = layout.coords("nohitter")["innings_until_display"] + if scoreboard.inning.number > should_display_nohitter: + if layout.state_is_nohitter(): + nohitter.render_nohit_text(canvas, layout, colors) _render_count(canvas, layout, colors, scoreboard.pitches) _render_outs(canvas, layout, colors, scoreboard.outs) @@ -48,14 +84,13 @@ 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, play_result, animation, pitches: Pitches): +def _render_at_bat(canvas, layout, colors, atbat: AtBat, text_pos, strikeout, looking, 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 play_result and play_result in PLAY_RESULT_UPDATES: - if animation and strikeout: - __render_strikeout(canvas, layout, colors, looking) - else: + if play_result in PLAY_RESULT_UPDATES: + if animation: + if looking: play_result += "_looking" __render_play_result(canvas, layout, colors, play_result) return plength else: @@ -64,26 +99,14 @@ def _render_at_bat(canvas, layout, colors, atbat: AtBat, text_pos, strikeout, lo def __render_play_result(canvas, layout, colors, play_result): text = "" - if play_result == "single": - text = "1B" - elif play_result == "double": - text = "2B" - elif play_result == "triple": - text = "3B" - elif play_result == "walk": - text = "BB" - elif play_result == "home_run": - text = "HR" - coords = layout.coords("atbat.strikeout") - color = colors.graphics_color("atbat.strikeout") - font = layout.font("atbat.strikeout") - graphics.DrawText(canvas, font["font"], coords["x"], coords["y"], color, text) - -def __render_strikeout(canvas, layout, colors, looking): - coords = layout.coords("atbat.strikeout") + if layout.width > 64: + text = PLAY_RESULTS[play_result]["long"] + else: + text = PLAY_RESULTS[play_result]["short"] + print(text) + coords = layout.coords("atbat.batter") if layout.width > 64 else layout.coords("atbat.strikeout") color = colors.graphics_color("atbat.strikeout") font = layout.font("atbat.strikeout") - text = "ꓘ" if looking else "K" graphics.DrawText(canvas, font["font"], coords["x"], coords["y"], color, text) def __render_batter_text(canvas, layout, colors, batter, text_pos): @@ -261,6 +284,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") From 88f81bbbcd80fdfc8f08ab29a07d5960db04a287 Mon Sep 17 00:00:00 2001 From: jimcreel Date: Fri, 14 Jul 2023 22:04:05 -0700 Subject: [PATCH 03/12] condensed scoreboard methods to catch all hits in one --- data/scoreboard/__init__.py | 12 +++--------- renderers/main.py | 2 +- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/data/scoreboard/__init__.py b/data/scoreboard/__init__.py index 88b2c4cf..7e50cd17 100644 --- a/data/scoreboard/__init__.py +++ b/data/scoreboard/__init__.py @@ -42,17 +42,11 @@ def strikeout(self): def strikeout_looking(self): return self.play_result == "strikeout_looking" - def single(self): - return self.play_result == "single" - - def double(self): - return self.play_result == "double" - - def triple(self): - return self.play_result == "triple" + def hit(self): + return self.play_result == "single" or self.play_result == "double" or self.play_result == "triple" def walk(self): - return self.play_result == "walk" + return self.play_result == "walk" or self.play_result == "intent_walk" def get_text_for_reason(self): if self.note: diff --git a/renderers/main.py b/renderers/main.py index dd4dd5e0..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() or scoreboard.single() or scoreboard.double() or scoreboard.triple() or scoreboard.walk(): + if scoreboard.homerun() or scoreboard.strikeout() or scoreboard.hit() or scoreboard.walk(): self.animation_time += 1 else: self.animation_time = 0 From 943b0a336e0eb6658b13233383369c7fe6a7875b Mon Sep 17 00:00:00 2001 From: jimcreel Date: Sat, 15 Jul 2023 09:30:01 -0700 Subject: [PATCH 04/12] enabled short and long play descriptions in coords files. render all play results through the play_result method --- coordinates/w128h32.json.example | 5 +- coordinates/w128h64.json.example | 5 +- coordinates/w192h64.json.example | 5 +- coordinates/w32h32.json.example | 5 +- coordinates/w64h32.json.example | 5 +- coordinates/w64h64.json.example | 5 +- renderers/games/game.py | 90 +++++++++++++++----------------- 7 files changed, 61 insertions(+), 59 deletions(-) diff --git a/coordinates/w128h32.json.example b/coordinates/w128h32.json.example index d3c59047..61fb3716 100644 --- a/coordinates/w128h32.json.example +++ b/coordinates/w128h32.json.example @@ -183,9 +183,10 @@ "append_pitcher_name": false }, "loop": 64, - "strikeout": { + "play_result": { "x": 84, - "y": 30 + "y": 30, + "desc_length": "Short" } }, "pregame": { diff --git a/coordinates/w128h64.json.example b/coordinates/w128h64.json.example index 52fe6f11..ed8535c6 100644 --- a/coordinates/w128h64.json.example +++ b/coordinates/w128h64.json.example @@ -145,9 +145,10 @@ "append_pitcher_name": false }, "loop": 68, - "strikeout": { + "play_result": { "x": 32, - "y": 60 + "y": 60, + "desc_length": "Long" } }, "batter_count": { diff --git a/coordinates/w192h64.json.example b/coordinates/w192h64.json.example index 9a10db27..3e9fe786 100644 --- a/coordinates/w192h64.json.example +++ b/coordinates/w192h64.json.example @@ -145,9 +145,10 @@ "append_pitcher_name": false }, "loop": 68, - "strikeout": { + "play_result": { "x": 32, - "y": 60 + "y": 60, + "desc_length": "Long" } }, "batter_count": { diff --git a/coordinates/w32h32.json.example b/coordinates/w32h32.json.example index f872886a..da1604d0 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 93a01aff..fe8f6a2a 100644 --- a/coordinates/w64h32.json.example +++ b/coordinates/w64h32.json.example @@ -139,10 +139,11 @@ "append_pitcher_name": false }, "loop": 36, - "strikeout": { + "play_result": { "x": 15, "y": 29, - "font_name": "5x7" + "font_name": "5x7", + "desc_length": "Short" }, "hit": { "x": 15, diff --git a/coordinates/w64h64.json.example b/coordinates/w64h64.json.example index bde2213a..93fe3d10 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/renderers/games/game.py b/renderers/games/game.py index b2c94b78..a3411fc5 100644 --- a/renderers/games/game.py +++ b/renderers/games/game.py @@ -6,46 +6,49 @@ from data.scoreboard.bases import Bases from data.scoreboard.inning import Inning from data.scoreboard.pitches import Pitches + from renderers import scrollingtext from renderers.games import nohitter PLAY_RESULT_UPDATES = ["single", "double", "triple", "walk", "intent_walk", "home_run", "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" - }, - "intent_walk": { - "short": "IBB", - "long": "Int. Walk" - }, - "strikeout": { - "short": "K", - "long": "K" - }, - "strikeout_looking": { - "short": "ꓘ", - "long" : "ꓘ" - } +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" + }, + "intent_walk": { + "short": "IBB", + "long": "Int. Walk" + }, + "strikeout": { + "short": "K", + "long": "K" + }, + "strikeout_looking": { + "short": "ꓘ", + "long" : "ꓘ" + } + } + -} + def render_live_game(canvas, layout: Layout, colors: Color, scoreboard: Scoreboard, text_pos, animation_time): pos = 0 @@ -56,8 +59,6 @@ def render_live_game(canvas, layout: Layout, colors: Color, scoreboard: Scoreboa colors, scoreboard.atbat, text_pos, - scoreboard.strikeout(), - scoreboard.strikeout_looking(), scoreboard.play_result, (animation_time // 6) % 2, scoreboard.pitches @@ -84,13 +85,12 @@ 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, play_result, 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 play_result in PLAY_RESULT_UPDATES: if animation: - if looking: play_result += "_looking" __render_play_result(canvas, layout, colors, play_result) return plength else: @@ -98,15 +98,11 @@ def _render_at_bat(canvas, layout, colors, atbat: AtBat, text_pos, strikeout, lo return max(plength, blength) def __render_play_result(canvas, layout, colors, play_result): - text = "" - if layout.width > 64: - text = PLAY_RESULTS[play_result]["long"] - else: - text = PLAY_RESULTS[play_result]["short"] - print(text) - coords = layout.coords("atbat.batter") if layout.width > 64 else layout.coords("atbat.strikeout") - color = colors.graphics_color("atbat.strikeout") - font = layout.font("atbat.strikeout") + + coords = layout.coords("atbat.play_result") + color = colors.graphics_color("atbat.play_result") + font = layout.font("atbat.play_result") + text = PLAY_RESULTS[play_result][coords["desc_length"]] graphics.DrawText(canvas, font["font"], coords["x"], coords["y"], color, text) def __render_batter_text(canvas, layout, colors, batter, text_pos): From 51a17b2ecf0e98b5a603d582d1c9efc7c62d4141 Mon Sep 17 00:00:00 2001 From: jimcreel Date: Sat, 15 Jul 2023 11:37:24 -0700 Subject: [PATCH 05/12] moved play results to data/plays.py, adjusted play_result positioning --- colors/scoreboard.json.example | 12 +--------- coordinates/w128h32.json.example | 2 +- coordinates/w128h64.json.example | 2 +- coordinates/w192h64.json.example | 2 +- coordinates/w32h32.json.example | 2 +- coordinates/w64h32.json.example | 2 +- coordinates/w64h64.json.example | 2 +- data/plays.py | 36 ++++++++++++++++++++++++++++ renderers/games/game.py | 41 ++------------------------------ 9 files changed, 45 insertions(+), 56 deletions(-) create mode 100644 data/plays.py diff --git a/colors/scoreboard.json.example b/colors/scoreboard.json.example index 6dc30961..b2275f36 100644 --- a/colors/scoreboard.json.example +++ b/colors/scoreboard.json.example @@ -124,17 +124,7 @@ "g": 255, "b": 255 }, - "strikeout": { - "r": 255, - "g": 235, - "b": 59 - }, - "hit": { - "r": 255, - "g": 235, - "b": 59 - }, - "walk": { + "play_result": { "r": 255, "g": 235, "b": 59 diff --git a/coordinates/w128h32.json.example b/coordinates/w128h32.json.example index 61fb3716..4324094b 100644 --- a/coordinates/w128h32.json.example +++ b/coordinates/w128h32.json.example @@ -184,7 +184,7 @@ }, "loop": 64, "play_result": { - "x": 84, + "x": 60, "y": 30, "desc_length": "Short" } diff --git a/coordinates/w128h64.json.example b/coordinates/w128h64.json.example index ed8535c6..eb29fb8a 100644 --- a/coordinates/w128h64.json.example +++ b/coordinates/w128h64.json.example @@ -146,7 +146,7 @@ }, "loop": 68, "play_result": { - "x": 32, + "x": 16, "y": 60, "desc_length": "Long" } diff --git a/coordinates/w192h64.json.example b/coordinates/w192h64.json.example index 3e9fe786..eaf05fc7 100644 --- a/coordinates/w192h64.json.example +++ b/coordinates/w192h64.json.example @@ -146,7 +146,7 @@ }, "loop": 68, "play_result": { - "x": 32, + "x": 16, "y": 60, "desc_length": "Long" } diff --git a/coordinates/w32h32.json.example b/coordinates/w32h32.json.example index da1604d0..9cce89ea 100644 --- a/coordinates/w32h32.json.example +++ b/coordinates/w32h32.json.example @@ -165,7 +165,7 @@ "loop": 16, "play_result": { "x": 33, - "y": 33, + "y": 15, "desc_length": "Short" } }, diff --git a/coordinates/w64h32.json.example b/coordinates/w64h32.json.example index fe8f6a2a..766e5dbc 100644 --- a/coordinates/w64h32.json.example +++ b/coordinates/w64h32.json.example @@ -141,7 +141,7 @@ "loop": 36, "play_result": { "x": 15, - "y": 29, + "y": 15, "font_name": "5x7", "desc_length": "Short" }, diff --git a/coordinates/w64h64.json.example b/coordinates/w64h64.json.example index 93fe3d10..b016e99b 100644 --- a/coordinates/w64h64.json.example +++ b/coordinates/w64h64.json.example @@ -141,7 +141,7 @@ "loop": 64, "play_result": { "x": 31, - "y": 36, + "y": 18, "desc_length": "Short" } }, diff --git a/data/plays.py b/data/plays.py new file mode 100644 index 00000000..027f1057 --- /dev/null +++ b/data/plays.py @@ -0,0 +1,36 @@ +PLAY_RESULT_UPDATES = ["single", "double", "triple", "walk", "intent_walk", "home_run", "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" + }, + "intent_walk": { + "Short": "IBB", + "Long": "Int. Walk" + }, + "strikeout": { + "Short": "K", + "Long": "K" + }, + "strikeout_looking": { + "Short": "ꓘ", + "Long" : "ꓘ" + } + } diff --git a/renderers/games/game.py b/renderers/games/game.py index a3411fc5..0473e049 100644 --- a/renderers/games/game.py +++ b/renderers/games/game.py @@ -6,49 +6,11 @@ from data.scoreboard.bases import Bases from data.scoreboard.inning import Inning from data.scoreboard.pitches import Pitches +from data.plays import PLAY_RESULT_UPDATES, PLAY_RESULTS from renderers import scrollingtext from renderers.games import nohitter -PLAY_RESULT_UPDATES = ["single", "double", "triple", "walk", "intent_walk", "home_run", "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" - }, - "intent_walk": { - "short": "IBB", - "long": "Int. Walk" - }, - "strikeout": { - "short": "K", - "long": "K" - }, - "strikeout_looking": { - "short": "ꓘ", - "long" : "ꓘ" - } - } - - - def render_live_game(canvas, layout: Layout, colors: Color, scoreboard: Scoreboard, text_pos, animation_time): pos = 0 @@ -95,6 +57,7 @@ def _render_at_bat(canvas, layout, colors, atbat: AtBat, text_pos, play_result, return plength else: blength = __render_batter_text(canvas, layout, colors, atbat.batter, text_pos) + print(blength) return max(plength, blength) def __render_play_result(canvas, layout, colors, play_result): From 3f94d7126fe36e6dd62760351c111d4fcc29d6e2 Mon Sep 17 00:00:00 2001 From: jimcreel Date: Sat, 15 Jul 2023 11:39:01 -0700 Subject: [PATCH 06/12] removed debug printing --- renderers/games/game.py | 1 - 1 file changed, 1 deletion(-) diff --git a/renderers/games/game.py b/renderers/games/game.py index 0473e049..f785bc57 100644 --- a/renderers/games/game.py +++ b/renderers/games/game.py @@ -57,7 +57,6 @@ def _render_at_bat(canvas, layout, colors, atbat: AtBat, text_pos, play_result, return plength else: blength = __render_batter_text(canvas, layout, colors, atbat.batter, text_pos) - print(blength) return max(plength, blength) def __render_play_result(canvas, layout, colors, play_result): From 585a996ad066816530fa4396a3a86d133adda982 Mon Sep 17 00:00:00 2001 From: jimcreel Date: Sat, 15 Jul 2023 12:01:48 -0700 Subject: [PATCH 07/12] fixing short positioning for small screens --- coordinates/w64h32.json.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coordinates/w64h32.json.example b/coordinates/w64h32.json.example index 766e5dbc..fe8f6a2a 100644 --- a/coordinates/w64h32.json.example +++ b/coordinates/w64h32.json.example @@ -141,7 +141,7 @@ "loop": 36, "play_result": { "x": 15, - "y": 15, + "y": 29, "font_name": "5x7", "desc_length": "Short" }, From d74e92962cc9570328e180b6e29845eadd9cd9fb Mon Sep 17 00:00:00 2001 From: jimcreel Date: Sat, 15 Jul 2023 12:02:35 -0700 Subject: [PATCH 08/12] fixing positioning for small screens --- coordinates/w32h32.json.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coordinates/w32h32.json.example b/coordinates/w32h32.json.example index 9cce89ea..da1604d0 100644 --- a/coordinates/w32h32.json.example +++ b/coordinates/w32h32.json.example @@ -165,7 +165,7 @@ "loop": 16, "play_result": { "x": 33, - "y": 15, + "y": 33, "desc_length": "Short" } }, From a3ae6f86ed2ca46d5655d875faf4c8ec6e6d2c00 Mon Sep 17 00:00:00 2001 From: jimcreel Date: Sat, 15 Jul 2023 12:03:04 -0700 Subject: [PATCH 09/12] fixing positioning for small screens --- coordinates/w64h64.json.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coordinates/w64h64.json.example b/coordinates/w64h64.json.example index b016e99b..93fe3d10 100644 --- a/coordinates/w64h64.json.example +++ b/coordinates/w64h64.json.example @@ -141,7 +141,7 @@ "loop": 64, "play_result": { "x": 31, - "y": 18, + "y": 36, "desc_length": "Short" } }, From 6d3bdc4720271cc7b040dc5842d6e2249d675ec8 Mon Sep 17 00:00:00 2001 From: Jim Creel Date: Sat, 15 Jul 2023 21:46:09 -0700 Subject: [PATCH 10/12] constantized play results, removed play_result trigger list --- coordinates/w128h64.json.example | 2 +- data/plays.py | 95 ++++++++++++++++++++------------ data/scoreboard/__init__.py | 6 +- renderers/games/game.py | 10 +++- 4 files changed, 72 insertions(+), 41 deletions(-) diff --git a/coordinates/w128h64.json.example b/coordinates/w128h64.json.example index eb29fb8a..6aa5f343 100644 --- a/coordinates/w128h64.json.example +++ b/coordinates/w128h64.json.example @@ -148,7 +148,7 @@ "play_result": { "x": 16, "y": 60, - "desc_length": "Long" + "desc_length": "long" } }, "batter_count": { diff --git a/data/plays.py b/data/plays.py index 027f1057..205a113d 100644 --- a/data/plays.py +++ b/data/plays.py @@ -1,36 +1,61 @@ -PLAY_RESULT_UPDATES = ["single", "double", "triple", "walk", "intent_walk", "home_run", "strikeout", "strikeout_looking"] +SINGLE = "single" +DOUBLE = "double" +TRIPLE = "triple" +HOME_RUN = "home_run" -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" - }, - "intent_walk": { - "Short": "IBB", - "Long": "Int. Walk" - }, - "strikeout": { - "Short": "K", - "Long": "K" - }, - "strikeout_looking": { - "Short": "ꓘ", - "Long" : "ꓘ" - } - } +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 7e50cd17..78f71918 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: @@ -43,10 +45,10 @@ def strikeout_looking(self): return self.play_result == "strikeout_looking" def hit(self): - return self.play_result == "single" or self.play_result == "double" or self.play_result == "triple" + return self.play_result in plays.HITS def walk(self): - return self.play_result == "walk" or self.play_result == "intent_walk" + 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 f785bc57..95e01139 100644 --- a/renderers/games/game.py +++ b/renderers/games/game.py @@ -6,7 +6,7 @@ from data.scoreboard.bases import Bases from data.scoreboard.inning import Inning from data.scoreboard.pitches import Pitches -from data.plays import PLAY_RESULT_UPDATES, PLAY_RESULTS +from data.plays import PLAY_RESULTS from renderers import scrollingtext from renderers.games import nohitter @@ -51,7 +51,8 @@ def _render_at_bat(canvas, layout, colors, atbat: AtBat, text_pos, play_result, 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 play_result in PLAY_RESULT_UPDATES: + results = list(PLAY_RESULTS.keys()) + if play_result in results: if animation: __render_play_result(canvas, layout, colors, play_result) return plength @@ -64,7 +65,10 @@ def __render_play_result(canvas, layout, colors, play_result): coords = layout.coords("atbat.play_result") color = colors.graphics_color("atbat.play_result") font = layout.font("atbat.play_result") - text = PLAY_RESULTS[play_result][coords["desc_length"]] + 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): From b6c230c3d4ccc70e6aecfbcc2417bd1817790e77 Mon Sep 17 00:00:00 2001 From: jimcreel Date: Sat, 15 Jul 2023 21:55:10 -0700 Subject: [PATCH 11/12] updated w64h32 to remove hit and walk coords --- coordinates/w64h32.json.example | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/coordinates/w64h32.json.example b/coordinates/w64h32.json.example index fe8f6a2a..4a25e93d 100644 --- a/coordinates/w64h32.json.example +++ b/coordinates/w64h32.json.example @@ -144,17 +144,8 @@ "y": 29, "font_name": "5x7", "desc_length": "Short" - }, - "hit": { - "x": 15, - "y": 29, - "font_name": "5x7" - }, - "walk": { - "x": 15, - "y": 29, - "font_name": "5x7" } + }, "batter_count": { "x": 34, From 03e2b63063c5b73d8050a04dbbc06a8096ef92fb Mon Sep 17 00:00:00 2001 From: jimcreel Date: Sun, 16 Jul 2023 10:12:30 -0700 Subject: [PATCH 12/12] added separate color key for strikeout, updated keys for play_result desc_length in small displays --- colors/scoreboard.json.example | 5 +++++ coordinates/w128h32.json.example | 2 +- coordinates/w32h32.json.example | 2 +- coordinates/w64h32.json.example | 2 +- coordinates/w64h64.json.example | 2 +- renderers/games/game.py | 5 ++++- 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/colors/scoreboard.json.example b/colors/scoreboard.json.example index b2275f36..b016193b 100644 --- a/colors/scoreboard.json.example +++ b/colors/scoreboard.json.example @@ -128,6 +128,11 @@ "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 4324094b..6c224155 100644 --- a/coordinates/w128h32.json.example +++ b/coordinates/w128h32.json.example @@ -186,7 +186,7 @@ "play_result": { "x": 60, "y": 30, - "desc_length": "Short" + "desc_length": "short" } }, "pregame": { diff --git a/coordinates/w32h32.json.example b/coordinates/w32h32.json.example index da1604d0..5d8b0ed6 100644 --- a/coordinates/w32h32.json.example +++ b/coordinates/w32h32.json.example @@ -166,7 +166,7 @@ "play_result": { "x": 33, "y": 33, - "desc_length": "Short" + "desc_length": "short" } }, "batter_count": { diff --git a/coordinates/w64h32.json.example b/coordinates/w64h32.json.example index 4a25e93d..0a268819 100644 --- a/coordinates/w64h32.json.example +++ b/coordinates/w64h32.json.example @@ -143,7 +143,7 @@ "x": 15, "y": 29, "font_name": "5x7", - "desc_length": "Short" + "desc_length": "short" } }, diff --git a/coordinates/w64h64.json.example b/coordinates/w64h64.json.example index 93fe3d10..611f98f0 100644 --- a/coordinates/w64h64.json.example +++ b/coordinates/w64h64.json.example @@ -142,7 +142,7 @@ "play_result": { "x": 31, "y": 36, - "desc_length": "Short" + "desc_length": "short" } }, "pregame": { diff --git a/renderers/games/game.py b/renderers/games/game.py index 95e01139..4773c4dc 100644 --- a/renderers/games/game.py +++ b/renderers/games/game.py @@ -63,7 +63,10 @@ def _render_at_bat(canvas, layout, colors, atbat: AtBat, text_pos, play_result, def __render_play_result(canvas, layout, colors, play_result): coords = layout.coords("atbat.play_result") - color = colors.graphics_color("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"]]