Skip to content

Commit

Permalink
Fixed a bug - a new game would not show up in the library after it ha…
Browse files Browse the repository at this point in the history
…s been saved. Also, updated related method name for better readability.
  • Loading branch information
mrzhenya committed May 17, 2024
1 parent bc8d98f commit c38d4f5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public boolean gameExistsInLibrary(@NotNull GameData gameData) {
*
* @param gameData game to add
*/
public void addGameToLibrary(@NotNull GameData gameData) {
public void copyAndAddGameToLibrary(@NotNull GameData gameData) {
if (!gameData.isGameDataUsable()) {
// Don't add unusable games.
logger.warn("Trying to add unusable game to the library: {}", gameData.getFilePath());
Expand Down Expand Up @@ -378,7 +378,7 @@ private void copyNativeFormatGame(@NotNull GameData gameData) throws Exception {
if (isGameAdded) {
// Update game file path on the current game data.
gameData.setGameFilePaths(gameFilePath, gameBundlePath);
updateLibraryGames(gameData);
addGameToLibrary(gameData);
}
}

Expand Down Expand Up @@ -440,7 +440,7 @@ private void copyNonNativeFormatGame(GameData gameData) {
// Now, that the game data has been updated, create a game data file.
XmlFileUtilities.createGameFile(gameData, destFilePath);
gameData.changeToNativeData();
updateLibraryGames(gameData);
addGameToLibrary(gameData);
AppRegistry.getInstance().getLandingUi().updateLibrary(null);

return imageUrls;
Expand Down Expand Up @@ -592,7 +592,7 @@ public GameData createNewGame(@NotNull String gameName, String gameDescription)
* Updates library games when a new game was added to the library folder.
* @param gameData game data
*/
public void updateLibraryGames(GameData gameData) {
public void addGameToLibrary(@NotNull GameData gameData) {
this.libraryGames.add(gameData);
Collections.sort(this.libraryGames);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public Component getButtonComponent() {
*/
private void addGameToLibrary() {
Registry registry = AppRegistry.getInstance();
registry.getGameDataService().addGameToLibrary(this.result.getGameData());
registry.getGameDataService().copyAndAddGameToLibrary(this.result.getGameData());
registry.getLandingUi().updateLibrary(null);
this.setVisible(false);
this.dispose();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/curre/jjeopardy/ui/edit/EditGameWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ protected void saveGameData() {
boolean dataNew = this.gameData.isGameDataNew();
if (dataNew) {
logger.info("Adding a new game to the library");
gameService.updateLibraryGames(this.gameData);
gameService.addGameToLibrary(this.gameData);
}
ProgressDialog progressDialog = new ProgressDialog(this,
LocaleService.getString("jj.dialog.save.title"),
Expand All @@ -205,7 +205,7 @@ protected void saveGameData() {
this.originalGameData.copyFrom(this.gameData);

// If the game is in the library, update the library.
if (!dataNew && gameService.isLibraryGame(this.gameData)) {
if (gameService.isLibraryGame(this.gameData)) {
AppRegistry.getInstance().getLandingUi().updateLibrary(this.gameData);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ public void updateLibrary(@Null GameData gameData) {
LibraryGameItem item = (LibraryGameItem) component;
if (item.gameEquals(gameData)) {
item.updateContent();
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,12 @@ public void testGameExistsInLibrary_nativeWithBundle() {
* Tests addGameToLibrary while copying a single xml file.
*/
@Test
public void testAddGameToLibrary_nativeSingleFile() {
public void testCopyAndAddGameToLibrary_nativeSingleFile() {
try (MockedStatic<SettingsService> utilities = Mockito.mockStatic(SettingsService.class)) {
utilities.when(SettingsService::getVerifiedSettingsDirectoryPath).thenReturn(this.testSettingsPath);
GameData data = new GameData(VALID_DATA_PATH + "default.xml", null, true);

this.testGameService.addGameToLibrary(data);
this.testGameService.copyAndAddGameToLibrary(data);

// Verify the game is copied.
File bundlePath = new File(getTestLibraryPath("default" + BUNDLE_EXTENSION));
Expand All @@ -412,14 +412,14 @@ public void testAddGameToLibrary_nativeSingleFile() {
* Tests addGameToLibrary while copying a game bundle.
*/
@Test
public void testAddGameToLibrary_nativeBundle() {
public void testCopyAndAddGameToLibrary_nativeBundle() {
try (MockedStatic<SettingsService> utilities = Mockito.mockStatic(SettingsService.class)) {
utilities.when(SettingsService::getVerifiedSettingsDirectoryPath).thenReturn(this.testSettingsPath);
GameData data = new GameData(
VALID_DATA_PATH + "test-bundle.jj" + File.separatorChar + "test-bundle.xml",
VALID_DATA_PATH + "test-bundle.jj", true);

this.testGameService.addGameToLibrary(data);
this.testGameService.copyAndAddGameToLibrary(data);

// Verify the game is copied.
File bundlePath = new File(getTestLibraryPath("test-bundle" + BUNDLE_EXTENSION));
Expand Down

0 comments on commit c38d4f5

Please sign in to comment.