Skip to content

Commit

Permalink
Table imports
Browse files Browse the repository at this point in the history
  • Loading branch information
syd711 committed Sep 10, 2024
1 parent 8fec0de commit 1164fd7
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 54 deletions.
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
- **Table Overview / VPin MAME**: Fixed typos.
- **Table Overview**: Fixed possible issue caused by the update news dialog which may have caused database locks.
- **Event Log**: Improved event log with additional iScored infos.
- **Highscore Parsing**: Added support for table "Jungle Princess".
- **Highscore Parsing**: Fixed status message for unsupported highscore text files. Previously the wrong error message was shown, stating that no file has been found even though it was there. Now the correct message is shown, that the file was found but is not yet supported. Please report these tables so these can be fixed.

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 @@ -103,7 +103,7 @@ public synchronized HighscoreMetadata readHighscore(Game game) {
return metadata;
}

private String readHSFileHighscore(Game game, HighscoreMetadata metadata) throws IOException {
private String readHSFileHighscore(@NonNull Game game, @NonNull HighscoreMetadata metadata) throws IOException {
File hsFile = game.getHighscoreTextFile();
if ((hsFile == null || !hsFile.exists())) {
hsFile = game.getAlternateHighscoreTextFile(game.getTableName());
Expand All @@ -123,7 +123,7 @@ private String readHSFileHighscore(Game game, HighscoreMetadata metadata) throws
metadata.setFilename(hsFile.getCanonicalPath());
metadata.setModified(new Date(hsFile.lastModified()));

return TextHighscoreConverters.convertTextFileTextToMachineReadable(scoringDB, hsFile);
return TextHighscoreConverters.convertTextFileTextToMachineReadable(metadata, scoringDB, hsFile);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.mephisto.vpin.restclient.highscores.logging.SLOG;
import de.mephisto.vpin.restclient.system.ScoringDB;
import de.mephisto.vpin.server.highscores.HighscoreMetadata;
import de.mephisto.vpin.server.highscores.parsing.text.adapters.*;
import de.mephisto.vpin.server.highscores.parsing.text.adapters.customized.SpongebobAdapter;
import edu.umd.cs.findbugs.annotations.NonNull;
Expand Down Expand Up @@ -34,6 +35,7 @@ public class TextHighscoreConverters {
adapters.add(new AlteringScoreInitialsBlocksAdapter("MagicCity_67VPX.txt", 6, 5));
adapters.add(new AlteringScoreInitialsBlocksAdapter("WorldSeries_72VPX.txt", 6, 5));
adapters.add(new AlteringScoreInitialsBlocksAdapter("MountainClimbingHS.txt", 3, 5));
adapters.add(new AlteringScoreInitialsBlocksAdapter("jungleprincess_1977_v2a.txt", 0, 5));
adapters.add(new AlteringScoreInitialsBlocksAdapter(33, 0, 5));
adapters.add(new AlteringScoreInitialsBlocksAdapter(32, 0, 5));
adapters.add(new AlteringScoreInitialsBlocksAdapter(31, 0, 5));
Expand Down Expand Up @@ -81,7 +83,7 @@ public static boolean resetHighscores(@NonNull ScoringDB scoringDB, @NonNull Fil
return false;
}

public static String convertTextFileTextToMachineReadable(@NonNull ScoringDB scoringDB, @NonNull File file) {
public static String convertTextFileTextToMachineReadable(@NonNull HighscoreMetadata metadata, @NonNull ScoringDB scoringDB, @NonNull File file) {
if (scoringDB.getIgnoredTextFiles().contains(file.getName())) {
SLOG.info("\"" + file.getName() + "\" was marked as to be ignored for text file based highscores.");
return null;
Expand All @@ -98,6 +100,7 @@ public static String convertTextFileTextToMachineReadable(@NonNull ScoringDB sco
}
}
LOG.info("No parser found for " + file.getName() + ", length: " + lines.size() + " rows.");
metadata.setStatus("No parser found for highscore file \"" + file.getName() + "\". Please report this table.");
}
catch (IOException e) {
SLOG.error("Error reading EM highscore file: " + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,10 +604,9 @@ public static void openTablesBackupDialog(List<GameRepresentation> games) {
stage.showAndWait();
}

public static void openTableImportDialog(GameEmulatorRepresentation emulator) {
Stage stage = Dialogs.createStudioDialogStage(TableImportController.class, "dialog-table-import.fxml", "Table Import for '" + emulator.getName() + "'");
public static void openTableImportDialog() {
Stage stage = Dialogs.createStudioDialogStage(TableImportController.class, "dialog-table-import.fxml", "Table Importer");
TableImportController controller = (TableImportController) stage.getUserData();
controller.setEmulator(emulator);
stage.showAndWait();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,19 +639,13 @@ public void onTablesScanAll() {

@FXML
public void onImport() {
GameEmulatorRepresentation emulatorSelection = getEmulatorSelection();
if (emulatorSelection == null) {
WidgetFactory.showInformation(stage, "No emulator selected.", "Select a specific emulator to import tables from.");
return;
}

if (client.getFrontendService().isFrontendRunning()) {
if (Dialogs.openFrontendRunningWarning(Studio.stage)) {
TableDialogs.openTableImportDialog(emulatorSelection);
TableDialogs.openTableImportDialog();
}
}
else {
TableDialogs.openTableImportDialog(emulatorSelection);
TableDialogs.openTableImportDialog();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,29 @@

import de.mephisto.vpin.commons.fx.DialogController;
import de.mephisto.vpin.commons.utils.WidgetFactory;
import de.mephisto.vpin.restclient.PreferenceNames;
import de.mephisto.vpin.restclient.frontend.Frontend;
import de.mephisto.vpin.restclient.games.GameEmulatorRepresentation;
import de.mephisto.vpin.restclient.games.GameList;
import de.mephisto.vpin.restclient.games.GameListItem;
import de.mephisto.vpin.restclient.jobs.JobExecutionResult;
import de.mephisto.vpin.restclient.jobs.JobType;
import de.mephisto.vpin.restclient.preferences.UISettings;
import de.mephisto.vpin.ui.Studio;
import de.mephisto.vpin.ui.events.EventManager;
import de.mephisto.vpin.ui.util.FrontendUtil;
import de.mephisto.vpin.ui.util.ProgressDialog;
import de.mephisto.vpin.ui.util.ProgressResultModel;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
Expand All @@ -29,27 +35,25 @@
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import java.util.stream.Collectors;

import static de.mephisto.vpin.ui.Studio.client;

public class TableImportController implements Initializable, DialogController {
private final static Logger LOG = LoggerFactory.getLogger(TableImportController.class);

@FXML
private Label text1Description;
@FXML
private Label text2Description;
@FXML
private Label text3Description;
@FXML
private Label text4Description;

@FXML
private VBox tableBox;

@FXML
private Button saveBtn;

@FXML
private ComboBox<GameEmulatorRepresentation> emulatorCombo;

private final List<CheckBox> checkBoxes = new ArrayList<>();

@FXML
Expand Down Expand Up @@ -94,30 +98,50 @@ private void onCancelClick(ActionEvent e) {

@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
try {
UISettings uiSettings = client.getPreferenceService().getJsonPreference(PreferenceNames.UI_SETTINGS, UISettings.class);

Frontend frontend = client.getFrontendService().getFrontendCached();
// should always be done
FrontendUtil.replaceNames(text2Description, frontend, frontend.getName());
GameEmulatorRepresentation selectedEmu = this.emulatorCombo.getSelectionModel().getSelectedItem();
this.emulatorCombo.valueProperty().addListener(new ChangeListener<GameEmulatorRepresentation>() {
@Override
public void changed(ObservableValue<? extends GameEmulatorRepresentation> observable, GameEmulatorRepresentation oldValue, GameEmulatorRepresentation newValue) {
if (newValue != null) {
refreshEmulator(newValue);
}
saveBtn.setDisable(newValue == null);
}
});

List<GameEmulatorRepresentation> emulators = new ArrayList<>(client.getFrontendService().getGameEmulatorsUncached());
List<GameEmulatorRepresentation> filtered = emulators.stream().filter(e -> !uiSettings.getIgnoredEmulatorIds().contains(Integer.valueOf(e.getId()))).collect(Collectors.toList());
this.emulatorCombo.setItems(FXCollections.observableList(filtered));

if (selectedEmu == null && !filtered.isEmpty()) {
this.emulatorCombo.getSelectionModel().selectFirst();
}
}
catch (Exception e) {
LOG.error("Failed to init import dialog: " + e.getMessage(), e);
WidgetFactory.showAlert(Studio.stage, "Error", "Failed to read import list: " + e.getMessage());
}
}

public void setEmulator(GameEmulatorRepresentation emulator) {
private void refreshEmulator(GameEmulatorRepresentation emulator) {
try {
Frontend frontend = client.getFrontendService().getFrontendCached();
GameList importableTables = client.getFrontendService().getImportableTables(emulator.getId());
saveBtn.setDisable(importableTables.getItems().isEmpty());

// should always be done
FrontendUtil.replaceNames(text1Description, frontend, emulator.getName());
FrontendUtil.replaceNames(text2Description, frontend, emulator.getName());
checkBoxes.clear();
tableBox.getChildren().removeAll(tableBox.getChildren());

if (importableTables.getItems().isEmpty()) {
Label label = new Label("No tables found for \"" + emulator.getName() + "\" that have not been imported yet.");
label.setStyle("-fx-font-size: 14px;");
tableBox.getChildren().add(label);

text3Description.setVisible(false);
text4Description.setVisible(false);
}
else {
FrontendUtil.replaceNames(text3Description, frontend, emulator.getName());
FrontendUtil.replaceNames(text4Description, frontend, emulator.getName());

CheckBox selectCheckbox = new CheckBox("Select All");
selectCheckbox.setStyle("-fx-font-size: 14px;-fx-font-weight: bold;");
selectCheckbox.setPrefHeight(50);
Expand All @@ -144,6 +168,7 @@ public void setEmulator(GameEmulatorRepresentation emulator) {
}
}


@Override
public void onDialogCancel() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.layout.BorderPane?>
Expand Down Expand Up @@ -40,43 +41,35 @@
<center>
<VBox BorderPane.alignment="CENTER">
<children>
<Label text="Available Tables" textFill="WHITE">
<font>
<Font name="System Bold" size="14.0" />
</font>
<VBox.margin>
<Insets />
</VBox.margin>
</Label>
<Label fx:id="text1Description" layoutX="10.0" layoutY="10.0" styleClass="preference-description" text="The list shows the tables files located in the &quot;Tables&quot; folder of [Emulator]" textFill="WHITE">
<Label fx:id="text1Description" layoutX="10.0" layoutY="10.0" styleClass="preference-description" text="The list shows the tables for the selected emulator that have not been " textFill="WHITE">
<font>
<Font name="System Bold" size="14.0" />
</font>
<VBox.margin>
<Insets top="6.0" />
</VBox.margin>
</Label>
<Label fx:id="text2Description" layoutX="10.0" layoutY="30.0" styleClass="preference-description" text="that have not been imported to [Frontend] yet." textFill="WHITE">
<Label fx:id="text2Description" layoutX="10.0" layoutY="30.0" styleClass="preference-description" text="imported to [Frontend] yet." textFill="WHITE">
<font>
<Font name="System Bold" size="14.0" />
</font>
<VBox.margin>
<Insets bottom="12.0" />
</VBox.margin>
</Label>
<Label fx:id="text3Description" layoutX="10.0" layoutY="58.0" styleClass="preference-description" text="Rename the &quot;Game Name&quot; in the &quot;Table Data&quot; dialog after the import " textFill="WHITE">
<font>
<Font name="System Bold" size="14.0" />
</font>
<HBox alignment="CENTER_LEFT" spacing="6.0">
<children>
<Label styleClass="default-text" text="Emulator:" textFill="WHITE">
<font>
<Font name="System Bold" size="14.0" />
</font>
</Label>
<ComboBox fx:id="emulatorCombo" prefWidth="150.0" />
</children>
<VBox.margin>
<Insets />
<Insets bottom="12.0" />
</VBox.margin>
</Label>
<Label fx:id="text4Description" layoutX="10.0" layoutY="92.0" styleClass="preference-description" text="if you have already assets in the screen folders of [Frontend] for this table." textFill="WHITE">
<font>
<Font name="System Bold" size="14.0" />
</font>
</Label>
</HBox>
<ScrollPane maxHeight="500.0" minHeight="500.0">
<content>
<VBox fx:id="tableBox" />
Expand Down

0 comments on commit 1164fd7

Please sign in to comment.