diff --git a/README.md b/README.md index 38c7bda..e7e3854 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ A pitcher directory consists of the following files: ``` . ├── count.txt +├── pitchcount.txt ├── era.txt ├── firstname.txt ├── flag.png @@ -106,6 +107,7 @@ The complete output directory is structured as follows: ├── away_score.txt ├── away_team.txt ├── balls.txt +├── balls.png ├── bases │   ├── ooo.png │   ├── oox.png @@ -219,6 +221,7 @@ The complete output directory is structured as follows: │   └── 2.png ├── outs.png ├── strikes.txt +├── strikes.png └── team_resources ├── colors │   ├── ALB.png diff --git a/src/main/java/org/sundbybergheat/baseballstreaming/services/FilesService.java b/src/main/java/org/sundbybergheat/baseballstreaming/services/FilesService.java index c5b0963..1c0efd4 100644 --- a/src/main/java/org/sundbybergheat/baseballstreaming/services/FilesService.java +++ b/src/main/java/org/sundbybergheat/baseballstreaming/services/FilesService.java @@ -39,6 +39,15 @@ public void initResources() throws IOException { filesClient.copyFileFromResource("/outs/1.png", "outs/1.png"); filesClient.copyFileFromResource("/outs/2.png", "outs/2.png"); + filesClient.copyFileFromResource("/balls/0.png", "balls/0.png"); + filesClient.copyFileFromResource("/balls/1.png", "balls/1.png"); + filesClient.copyFileFromResource("/balls/2.png", "balls/2.png"); + filesClient.copyFileFromResource("/balls/3.png", "balls/3.png"); + + filesClient.copyFileFromResource("/strikes/0.png", "strikes/0.png"); + filesClient.copyFileFromResource("/strikes/1.png", "strikes/1.png"); + filesClient.copyFileFromResource("/strikes/2.png", "strikes/2.png"); + filesClient.copyFileFromResource( "/images/player-image-default.png", "team_resources/player_images/default.png"); filesClient.copyFileFromResource( @@ -162,14 +171,40 @@ private void updateScoreBoard() throws IOException { situation.put("balls", s.balls().orElse("0")); situation.put("strikes", s.strikes().orElse("0")); }); + + updateCount(situation); + } + + private void updateCount(Map situation) throws IOException { + String balls = situation.getOrDefault("balls", "0"); + String strikes = situation.getOrDefault("strikes", "0"); filesClient.writeStringToFile( "count.txt", - String.format( - "%s - %s", - situation.getOrDefault("balls", "0"), situation.getOrDefault("strikes", "0"))); - filesClient.writeStringToFile("balls.txt", situation.getOrDefault("balls", "0")); - filesClient.writeStringToFile("strikes.txt", situation.getOrDefault("strikes", "0")); + String.format("%s - %s", balls, strikes)); + + filesClient.writeStringToFile("balls.txt", balls); + filesClient.writeStringToFile("strikes.txt", strikes); + + String ballsTarget = "balls.png"; + if ("1".equals(balls)) { + filesClient.copyFile("balls/1.png", ballsTarget); + } else if ("2".equals(balls)) { + filesClient.copyFile("balls/2.png", ballsTarget); + } else if ("3".equals(balls)) { + filesClient.copyFile("balls/3.png", ballsTarget); + } else { + filesClient.copyFile("balls/0.png", ballsTarget); + } + + String strikesTarget = "strikes.png"; + if ("1".equals(strikes)) { + filesClient.copyFile("strikes/1.png", strikesTarget); + } else if ("2".equals(strikes)) { + filesClient.copyFile("strikes/2.png", strikesTarget); + } else { + filesClient.copyFile("strikes/0.png", strikesTarget); + } } private void updateBases() throws IOException { @@ -225,6 +260,9 @@ private void updatePitcher(final Player pitcher, final String subdir) throws IOE filesClient.writeStringToFile( subdir + "/count.txt", String.format("P: %s", pitcher.pitches().orElse("0"))); + filesClient.writeStringToFile( + subdir + "/pitchcount.txt", pitcher.pitches().orElse("0")); + filesClient.writeStringToFile(subdir + "/firstname.txt", pitcher.firstName().orElse("")); filesClient.writeStringToFile(subdir + "/fullname.txt", pitcher.fullName().orElse("")); filesClient.writeStringToFile(subdir + "/lastname.txt", pitcher.lastName().orElse("")); diff --git a/src/main/resources/balls/0.png b/src/main/resources/balls/0.png new file mode 100644 index 0000000..ab6aa88 Binary files /dev/null and b/src/main/resources/balls/0.png differ diff --git a/src/main/resources/balls/1.png b/src/main/resources/balls/1.png new file mode 100644 index 0000000..2d55feb Binary files /dev/null and b/src/main/resources/balls/1.png differ diff --git a/src/main/resources/balls/2.png b/src/main/resources/balls/2.png new file mode 100644 index 0000000..6908bdd Binary files /dev/null and b/src/main/resources/balls/2.png differ diff --git a/src/main/resources/balls/3.png b/src/main/resources/balls/3.png new file mode 100644 index 0000000..742b06d Binary files /dev/null and b/src/main/resources/balls/3.png differ diff --git a/src/main/resources/strikes/0.png b/src/main/resources/strikes/0.png new file mode 100644 index 0000000..58b89b3 Binary files /dev/null and b/src/main/resources/strikes/0.png differ diff --git a/src/main/resources/strikes/1.png b/src/main/resources/strikes/1.png new file mode 100644 index 0000000..b0d0d31 Binary files /dev/null and b/src/main/resources/strikes/1.png differ diff --git a/src/main/resources/strikes/2.png b/src/main/resources/strikes/2.png new file mode 100644 index 0000000..9e50fc2 Binary files /dev/null and b/src/main/resources/strikes/2.png differ diff --git a/src/test/java/org/sundbybergheat/baseballstreaming/services/FilesServiceTest.java b/src/test/java/org/sundbybergheat/baseballstreaming/services/FilesServiceTest.java index 5f74bde..5ddefa6 100644 --- a/src/test/java/org/sundbybergheat/baseballstreaming/services/FilesServiceTest.java +++ b/src/test/java/org/sundbybergheat/baseballstreaming/services/FilesServiceTest.java @@ -47,8 +47,19 @@ void willInitializeResources(@TempDir File tempDir) throws IOException { Stream.of(tempDir.listFiles((f) -> f.isDirectory() && f.getName().equals("outs"))) .findFirst(); + Optional ballsDir = + Stream.of(tempDir.listFiles((f) -> f.isDirectory() && f.getName().equals("balls"))) + .findFirst(); + + Optional strikesDir = + Stream.of(tempDir.listFiles((f) -> f.isDirectory() && f.getName().equals("strikes"))) + .findFirst(); + + assertTrue(basesDir.isPresent()); assertTrue(outsDir.isPresent()); + assertTrue(ballsDir.isPresent()); + assertTrue(strikesDir.isPresent()); assertTrue(teamResourcesDir.isPresent()); assertTrue(fileExistAndIsNonEmpty(basesDir.get(), "ooo.png")); @@ -64,6 +75,15 @@ void willInitializeResources(@TempDir File tempDir) throws IOException { assertTrue(fileExistAndIsNonEmpty(outsDir.get(), "1.png")); assertTrue(fileExistAndIsNonEmpty(outsDir.get(), "2.png")); + assertTrue(fileExistAndIsNonEmpty(ballsDir.get(), "0.png")); + assertTrue(fileExistAndIsNonEmpty(ballsDir.get(), "1.png")); + assertTrue(fileExistAndIsNonEmpty(ballsDir.get(), "2.png")); + assertTrue(fileExistAndIsNonEmpty(ballsDir.get(), "3.png")); + + assertTrue(fileExistAndIsNonEmpty(strikesDir.get(), "0.png")); + assertTrue(fileExistAndIsNonEmpty(strikesDir.get(), "1.png")); + assertTrue(fileExistAndIsNonEmpty(strikesDir.get(), "2.png")); + Optional playerImagesDir = Stream.of( teamResourcesDir @@ -166,6 +186,7 @@ void shouldUpdatePlay(String playJsonFile, @TempDir File tempDir) throws IOExcep client.copyFileFromResource( "/wbsc/default-player.jpg", "team_resources/player_images/default.png"); FilesService service = new FilesService(client); + service.initResources(); Play play = JsonMapper.fromJson(playJson, Play.class); service.updatePlay(play); @@ -184,6 +205,7 @@ void shouldUpdatePlay(String playJsonFile, @TempDir File tempDir) throws IOExcep assertTrue(fileExistAndIsNonEmpty(currentPitcherDir.get(), "image.png")); assertTrue(fileExistAndIsNonEmpty(currentPitcherDir.get(), "walks.txt")); assertTrue(fileExistAndIsNonEmpty(currentPitcherDir.get(), "count.txt")); + assertTrue(fileExistAndIsNonEmpty(currentPitcherDir.get(), "pitchcount.txt")); assertTrue(fileExistAndIsNonEmpty(currentPitcherDir.get(), "fullname.txt")); assertTrue(fileExistAndIsNonEmpty(currentPitcherDir.get(), "pitching.txt")); assertTrue(fileExistAndIsNonEmpty(currentPitcherDir.get(), "lastname.txt")); @@ -235,7 +257,9 @@ void shouldUpdatePlay(String playJsonFile, @TempDir File tempDir) throws IOExcep assertTrue(fileExistAndIsNonEmpty(tempDir, "count.txt")); assertTrue(fileExistAndIsNonEmpty(tempDir, "balls.txt")); + assertTrue(fileExistAndIsNonEmpty(tempDir, "balls.png")); assertTrue(fileExistAndIsNonEmpty(tempDir, "strikes.txt")); + assertTrue(fileExistAndIsNonEmpty(tempDir, "strikes.png")); assertTrue(fileExistAndIsNonEmpty(tempDir, "inning_text.txt"));