Skip to content

Commit

Permalink
VPS diff
Browse files Browse the repository at this point in the history
  • Loading branch information
syd711 committed Dec 20, 2024
1 parent 187d800 commit dbf4bb0
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 37 deletions.
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
## Release Notes 3.11.1

## Bugfixes

- **Tables / PUP Packs**: Fixed wrong order of PUP pack detection when an alias was used.
- **Tables / VPS Updates**: Fixed filtering issues.

## Release Notes 3.11.0

Expand Down
2 changes: 1 addition & 1 deletion resources/vpsdb.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public interface UIDefaults {

int THUMBNAIL_SIZE = 240;
int SCROLL_OFFSET = 120;

int MAX_REFRESH_COUNT = 3;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import de.mephisto.vpin.restclient.PreferenceNames;
import de.mephisto.vpin.restclient.frontend.FrontendType;
import de.mephisto.vpin.restclient.games.*;
import de.mephisto.vpin.restclient.preferences.UISettings;
import de.mephisto.vpin.ui.tables.dialogs.TableDataController;
import de.mephisto.vpin.ui.tables.models.TableStatus;
import de.mephisto.vpin.ui.tables.panels.BaseFilterController;
Expand Down Expand Up @@ -104,13 +105,15 @@ public class TableFilterController extends BaseFilterController<GameRepresentati
private ComboBox<NoteType> notesCombo;

private FilterSettings filterSettings;
private UISettings uiSettings;

private TableOverviewPredicateFactory predicateFactory = new TableOverviewPredicateFactory();


public void applyFilters() {
// as we do not call filterGames() anymore, manually call saveFilterSettings to persist the reset
client.getPreferenceService().setJsonPreference(filterSettings);
uiSettings = client.getPreferenceService().getJsonPreference(PreferenceNames.UI_SETTINGS, UISettings.class);
super.applyFilters();
}

Expand All @@ -127,7 +130,7 @@ protected GameEmulatorRepresentation getEmulatorSelection() {
@Override
public Predicate<GameRepresentationModel> buildPredicate(String searchTerm, PlaylistRepresentation playlist) {
GameEmulatorRepresentation emulatorSelection = getEmulatorSelection();
return predicateFactory.buildPredicate(searchTerm, playlist, emulatorSelection, filterSettings);
return predicateFactory.buildPredicate(searchTerm, playlist, emulatorSelection, filterSettings, uiSettings);
}

protected void resetFilters() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.mephisto.vpin.commons.utils.WidgetFactory;
import de.mephisto.vpin.connectors.vps.VPS;
import de.mephisto.vpin.connectors.vps.model.VPSChanges;
import de.mephisto.vpin.connectors.vps.model.VpsDiffTypes;
import de.mephisto.vpin.restclient.PreferenceNames;
import de.mephisto.vpin.restclient.altsound.AltSound;
Expand Down Expand Up @@ -488,7 +489,12 @@ public void onVps() {
@FXML
public void onVpsReset() {
List<GameRepresentation> selectedItems = getSelections();
TableActions.onVpsReset(selectedItems);
onVpsReset(selectedItems);
}

public static void onVpsReset(List<GameRepresentation> selectedItems) {
List<GameRepresentation> collect = selectedItems.stream().filter(g -> !g.getVpsUpdates().isEmpty()).collect(Collectors.toList());
ProgressDialog.createProgressDialog(new VPSResetProgressModel(collect));
}

@FXML
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package de.mephisto.vpin.ui.tables;

import de.mephisto.vpin.connectors.vps.model.VPSChange;
import de.mephisto.vpin.restclient.games.FilterSettings;
import de.mephisto.vpin.restclient.games.GameEmulatorRepresentation;
import de.mephisto.vpin.restclient.games.GameRepresentation;
import de.mephisto.vpin.restclient.games.NoteType;
import de.mephisto.vpin.restclient.games.PlaylistRepresentation;
import de.mephisto.vpin.restclient.preferences.UISettings;
import de.mephisto.vpin.ui.tables.vps.VpsTableColumn;
import org.apache.commons.lang3.StringUtils;

import java.util.function.Predicate;
Expand All @@ -13,7 +16,7 @@ public class TableOverviewPredicateFactory {
/**
* We need a new Predicate each time else TableView does not detect the changes
*/
public Predicate<GameRepresentationModel> buildPredicate(String searchTerm, PlaylistRepresentation playlist, GameEmulatorRepresentation emulator, FilterSettings filterSettings) {
public Predicate<GameRepresentationModel> buildPredicate(String searchTerm, PlaylistRepresentation playlist, GameEmulatorRepresentation emulator, FilterSettings filterSettings, UISettings uiSettings) {
return new Predicate<GameRepresentationModel>() {
@Override
public boolean test(GameRepresentationModel model) {
Expand Down Expand Up @@ -55,9 +58,19 @@ public boolean test(GameRepresentationModel model) {
return false;
}

if (filterSettings.isVpsUpdates() && game.getVpsUpdates() != null && game.getVpsUpdates().isEmpty()) {
if (filterSettings.isVpsUpdates() && (StringUtils.isEmpty(game.getExtTableId()) || game.getVpsUpdates() == null || game.getVpsUpdates().isEmpty())) {
return false;
}

if (filterSettings.isVpsUpdates() && game.getVpsUpdates() != null) {
for (VPSChange change : game.getVpsUpdates().getChanges()) {
if (!VpsTableColumn.isFiltered(uiSettings, change)) {
continue;
}
return false;
}
}

if (filterSettings.isVersionUpdates() && !game.isUpdateAvailable()) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private void onTableOpen() {
private void onVpsReset() {
if (!this.game.isEmpty()) {
GameRepresentation gameRepresentation = this.game.get();
TableActions.onVpsReset(Arrays.asList(gameRepresentation));
TableOverviewController.onVpsReset(Arrays.asList(gameRepresentation));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package de.mephisto.vpin.ui.tables;

import de.mephisto.vpin.commons.utils.WidgetFactory;
import de.mephisto.vpin.connectors.vps.model.VPSChanges;
import de.mephisto.vpin.restclient.games.GameRepresentation;
import de.mephisto.vpin.ui.Studio;
import de.mephisto.vpin.ui.events.EventManager;
import de.mephisto.vpin.ui.util.ProgressModel;
import de.mephisto.vpin.ui.util.ProgressResultModel;
import javafx.application.Platform;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Iterator;
import java.util.List;

import static de.mephisto.vpin.commons.fx.pausemenu.UIDefaults.MAX_REFRESH_COUNT;
import static de.mephisto.vpin.ui.Studio.client;

public class VPSResetProgressModel extends ProgressModel<GameRepresentation> {
private final static Logger LOG = LoggerFactory.getLogger(VPSResetProgressModel.class);
private List<GameRepresentation> games;

private final Iterator<GameRepresentation> gameIterator;

public VPSResetProgressModel(List<GameRepresentation> games) {
super("Resetting VPS Update Indicators");
this.games = games;
this.gameIterator = games.iterator();
}

@Override
public boolean isShowSummary() {
return false;
}

@Override
public boolean isIndeterminate() {
return games.size() == 1;
}

@Override
public int getMax() {
return games.size();
}

@Override
public boolean hasNext() {
return this.gameIterator.hasNext();
}

@Override
public GameRepresentation getNext() {
return gameIterator.next();
}

@Override
public String nextToString(GameRepresentation game) {
return game.getGameDisplayName();
}

@Override
public void finalizeModel(ProgressResultModel progressResultModel) {
super.finalizeModel(progressResultModel);

if (games.size() > MAX_REFRESH_COUNT) {
EventManager.getInstance().notifyTablesChanged();
}
}

@Override
public void processNext(ProgressResultModel progressResultModel, GameRepresentation game) {
try {
game.setUpdates(new VPSChanges());
client.getGameService().saveGame(game);
if (games.size() <= MAX_REFRESH_COUNT) {
EventManager.getInstance().notifyTableChange(game.getId(), null);
}
}
catch (Exception e) {
LOG.error("Failed to reset VPS indicator: " + e.getMessage(), e);
Platform.runLater(() -> {
WidgetFactory.showAlert(Studio.stage, "Error", "Failed to reset VPS indicator: " + e.getMessage());
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public VpsTableColumn(@Nullable String vpsTableId, @Nullable String vpsTableVers
}
}

private static boolean isFiltered(UISettings uiSettings, VPSChange change) {
public static boolean isFiltered(UISettings uiSettings, VPSChange change) {
if (uiSettings != null) {
if (change.getDiffType() != null && change.getDiffType().equals(VpsDiffTypes.b2s) && !uiSettings.isVpsBackglass()) {
return true;
Expand Down

0 comments on commit dbf4bb0

Please sign in to comment.