Skip to content

Commit

Permalink
Merge remote-tracking branch 'jimcreel/issue-471' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ty-porter committed Jul 16, 2023
2 parents c5160bc + 03e2b63 commit cec8a9b
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 39 deletions.
7 changes: 6 additions & 1 deletion colors/scoreboard.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
7 changes: 4 additions & 3 deletions coordinates/w128h32.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
7 changes: 4 additions & 3 deletions coordinates/w128h64.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
7 changes: 4 additions & 3 deletions coordinates/w192h64.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
5 changes: 3 additions & 2 deletions coordinates/w32h32.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,10 @@
"append_pitcher_name": false
},
"loop": 16,
"strikeout": {
"play_result": {
"x": 33,
"y": 33
"y": 33,
"desc_length": "short"
}
},
"batter_count": {
Expand Down
6 changes: 4 additions & 2 deletions coordinates/w64h32.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions coordinates/w64h64.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@
"append_pitcher_name": false
},
"loop": 64,
"strikeout": {
"play_result": {
"x": 31,
"y": 36
"y": 36,
"desc_length": "short"
}
},
"pregame": {
Expand Down
61 changes: 61 additions & 0 deletions data/plays.py
Original file line number Diff line number Diff line change
@@ -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": "ꓘ"
}
}
8 changes: 8 additions & 0 deletions data/scoreboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
52 changes: 30 additions & 22 deletions renderers/games/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion renderers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cec8a9b

Please sign in to comment.