Skip to content

Commit

Permalink
Fixed loading of tournaments where a participating bot has been delet…
Browse files Browse the repository at this point in the history
…ed (#130)

* Fixed loading of tournaments where a participating bot has been deleted

* Add change to changelog
  • Loading branch information
NicEastvillage authored Jul 9, 2024
1 parent 960a9b6 commit 0968070
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Fixed MatchRunner not working for users with spaces in their windows username. - NicEastvillage
- Adjusted logger formatting. - NicEastvillage
- Fixed "succesfully saved"-alert when saving was cancelled. #129 - NicEastvillage
- Fixed loading of tournaments where a participating bot has been deleted. #130 - NicEastvillage

#### Version 1.8.2 - April 2024
- Updated RLBot python path to python 3.11 installation. #117/#127 - CodeRed/NicEastvillage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public boolean reload() {
configLoadedCorrectly = true;
} catch (Exception e) {
configLoadedCorrectly = false;
throw new RuntimeException("Could not load bot from config " + pathToConfig + ", reason: " + e.getMessage());
throw new RuntimeException("Could not load bot from config " + pathToConfig, e);
}
return loadedCorrectly();
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/dk/aau/cs/ds306e18/tournament/model/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dk.aau.cs.ds306e18.tournament.model.stats.StatsManager;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -91,6 +92,7 @@ public StatsManager getStatsManager() {
* Repairs properties that cannot be deserialized.
*/
public void postDeserializationRepair() {
bots.removeAll(Collections.singletonList(null));
statsManager = new StatsManager(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import dk.aau.cs.ds306e18.tournament.Main;
import dk.aau.cs.ds306e18.tournament.model.Bot;
import dk.aau.cs.ds306e18.tournament.model.BotFromConfig;
import dk.aau.cs.ds306e18.tournament.rlbot.configuration.BotSkill;
import dk.aau.cs.ds306e18.tournament.model.PsyonixBotFromConfig;
import dk.aau.cs.ds306e18.tournament.rlbot.BotCollection;
import dk.aau.cs.ds306e18.tournament.utility.Alerts;
import javafx.application.Platform;

import java.io.IOException;

Expand Down Expand Up @@ -51,23 +54,33 @@ public Bot read(JsonReader in) throws IOException {
in.nextName();
double skill = in.nextDouble();
in.endObject();
PsyonixBotFromConfig bot = new PsyonixBotFromConfig(config, BotSkill.getSkillFromNumber(skill));

// Add to BotCollection and return
BotCollection.global.add(bot);
return bot;
try {
PsyonixBotFromConfig bot = new PsyonixBotFromConfig(config, BotSkill.getSkillFromNumber(skill));
BotCollection.global.add(bot);
return bot;

} catch (RuntimeException e) {
Main.LOGGER.log(System.Logger.Level.ERROR, "Failed to load bot from config. " + e.getCause().getMessage());
Platform.runLater(() -> Alerts.errorNotification("Failed to load bot: " + config, e.getCause().getMessage()));
return null;
}

} else if (BotFromConfig.class.getSimpleName().equals(clazz)) {

// Construct bot from config
in.nextName();
String config = in.nextString();
in.endObject();
BotFromConfig bot = new BotFromConfig(config);

// Add to BotCollection and return
BotCollection.global.add(bot);
return bot;
try {
BotFromConfig bot = new BotFromConfig(config);
BotCollection.global.add(bot);
return bot;

} catch (RuntimeException e) {
Main.LOGGER.log(System.Logger.Level.ERROR, "Failed to load bot from config. " + e.getCause().getMessage());
Platform.runLater(() -> Alerts.errorNotification("Failed to load bot: " + config, e.getCause().getMessage()));
return null;
}
}

in.endObject();
Expand Down

0 comments on commit 0968070

Please sign in to comment.