Skip to content

Commit

Permalink
FIX: Properly update AI aircrafts when deleting user aircraft during
Browse files Browse the repository at this point in the history
replay
  • Loading branch information
till213 committed Aug 4, 2021
1 parent c220467 commit 526909f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Export
* Illegal file path characters are replaced by _ in the initially suggested file path
* KML export: exported character data (title, description) is properly enclosed in a CDATA tag
- Properly update AI aircrafts when deleting the user aircraft during replay

## 0.8.3

Expand Down
10 changes: 4 additions & 6 deletions src/Persistence/src/Service/AircraftService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,18 @@ bool AircraftService::deleteByIndex(int index) noexcept
// Remove AI object
Flight &flight = Logbook::getInstance().getCurrentFlight();

const bool removeUserAircraft = flight.getUserAircraftIndex() == index;
Aircraft &aircraft = flight[index];
std::optional<std::reference_wrapper<SkyConnectIntf>> skyConnect = SkyConnectManager::getInstance().getCurrentSkyConnect();
if (skyConnect) {
skyConnect->get().destroyAIObject(aircraft);
}
const qint64 aircraftId = flight.deleteAircraftByIndex(index);
if (skyConnect) {
const bool userAircraftRemoved = flight.getUserAircraftIndex() == index;
if (userAircraftRemoved) {
skyConnect->get().updateUserAircraft();
}
}
bool ok;
if (aircraftId != Aircraft::InvalidId) {
if (skyConnect && removeUserAircraft) {
skyConnect->get().updateUserAircraft();
}
ok = QSqlDatabase::database().transaction();
if (ok) {
ok = d->aircraftDao->deleteById(aircraftId);
Expand Down

0 comments on commit 526909f

Please sign in to comment.