Skip to content

Commit

Permalink
emulator scripts for FP
Browse files Browse the repository at this point in the history
  • Loading branch information
syd711 committed Dec 29, 2024
1 parent f3b0e84 commit 8307215
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 81 deletions.
6 changes: 5 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
- **Emulator Detection**: The way the **nvram** and **rom** folders are read has been changed. For VPX emulators...
- the **nvram** folder is read from the Windows registry first, instead of simply assuming the default folder of PinMAME which is used as fallback now.
- the **roms** folder is read from the frontend/Popper first. If the value is empty there or invalid, the Windows registry value for PinMAME roms is used instead.
- **Preferences / VPX Monitor**: The VPX monitor has been disabled for now. The task of this monitor was to detect the table that is currently running to provide services like the pause menu also to non-Popper users. We used the VPX window title for this, but since the title does not include the active game anymore. I see currently no way to continue the support here.
- **Emulators Detection**: For some reason the launch and exit calls for the VPin Studio Server have never been (automatically) added to the emulator scripts of Future Pinball. As a result, the game status was never set for this emulator. As a result, in-game recording didn't work, because no active game status was found.
- **Preferences / VPX Monitor**: The VPX monitor has been disabled for now. The task of this monitor was to detect the table that is currently running to provide services like the pause menu also to non-Popper users. We used the VPX window title for this, but since the title does not include the active game anymore. Currently, I see no way to continue the support here.
- **Server**: Fixed issue that DOFLinx was also killed on Popper restart.
- **Tables / Table Data Manager**: Fixed issue that the Table Data Manager dialog did not open because of issues in the PinVol tab (needs to be revisited again).


---

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 @@ -45,7 +45,7 @@ public void setTableEntries(List<PinVolTableEntry> tableEntries) {
}

public PinVolTableEntry getSystemVolume() {
Optional<PinVolTableEntry> system = this.tableEntries.stream().filter(p -> p.getName().equals("System")).findFirst();
Optional<PinVolTableEntry> system = this.tableEntries.stream().filter(p -> p != null && p.getName() != null && p.getName().equals("System")).findFirst();
if (system.isPresent()) {
return system.get();
}
Expand All @@ -57,25 +57,24 @@ public PinVolTableEntry getSystemVolume() {

public PinVolTableEntry getTableEntry(String fileName, boolean vpxGame, boolean fpGame) {
String key = getKey(fileName, vpxGame, fpGame);
return getTableEntry(key);
}

public PinVolTableEntry getTableEntry(String key) {
for (PinVolTableEntry tableEntry : tableEntries) {
if (tableEntry.getName().contains(key)) {
if (tableEntry != null && tableEntry.getName() != null && tableEntry.getName().contains(key)) {
return tableEntry;
}
}
return null;
}

public boolean contains(String key) {
for (PinVolTableEntry tableEntry : tableEntries) {
if (tableEntry.getName().equals(key)) {
return true;
}
}
return false;
return getTableEntry(key) != null;
}

public static String getKey(String fileName, boolean vpxGame, boolean fpGame) {
String name = FilenameUtils.getBaseName(fileName);
String name = FilenameUtils.getBaseName(String.valueOf(fileName));
String prefix = "";
if (vpxGame) {
prefix = "VP.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public BotCommandResponse onBotCommand(BotCommand cmd) {
for (Game game : games) {
if (game.getGameDisplayName().toLowerCase().contains(cmd.getParameter()) || String.valueOf(game.getId()).equals(cmd.getParameter().trim())) {
HighscoreMetadata metadata = highscoreService.scanScore(game, EventOrigin.BOT_CMD);
if (StringUtils.isEmpty(metadata.getRaw()) && !StringUtils.isEmpty(metadata.getStatus())) {
if (metadata == null || (StringUtils.isEmpty(metadata.getRaw()) && !StringUtils.isEmpty(metadata.getStatus()))) {
return () -> "Highscore for '" + game.getGameDisplayName() + "' retrieval failed: " + metadata.getStatus();
}
ScoreSummary highscores = highscoreService.getScoreSummary(cmd.getServerId(), game);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public class PinUPConnector implements FrontendConnector, InitializingBean {
@Autowired
private PreferencesService preferencesService;

private PupServer pupServer;
private PupLauncher pupLauncher;

private PinUPMediaAccessStrategy pinUPMediaAccessStrategy;
Expand All @@ -86,7 +85,7 @@ public File getInstallationFolder() {
return systemService.getPinupInstallationFolder();
}

private void initVisualPinballXScripts(Emulator emulator) {
private void initEmulatorScripts(Emulator emulator) {
String emulatorName = emulator.getName();
String emulatorStartupScript = this.getEmulatorStartupScript(emulatorName);
if (!emulatorStartupScript.contains(CURL_COMMAND_TABLE_START)) {
Expand Down Expand Up @@ -115,7 +114,7 @@ private Connection connect() {
return DriverManager.getConnection(url);
}
catch (SQLException e) {
LOG.error("Failed to connect to sqlite: " + e.getMessage(), e);
LOG.error("Failed to connect to sqlite: {}", e.getMessage(), e);
}
return null;
}
Expand All @@ -126,7 +125,7 @@ private void disconnect(Connection conn) {
conn.close();
}
catch (SQLException e) {
LOG.error("Error disconnecting from sqlite: " + e.getMessage());
LOG.error("Error disconnecting from sqlite: {}", e.getMessage());
}
}
}
Expand All @@ -150,45 +149,14 @@ public Game getGame(int id) {
statement.close();
}
catch (SQLException e) {
LOG.error("Failed to get game for id '" + id + "': " + e.getMessage(), e);
LOG.error("Failed to get game for id '{}': {}", id, e.getMessage(), e);
}
finally {
disconnect(connect);
}
return info;
}

/**
* Not used anymore.
* I assume this one was used to show additional .exe files for the launcher dialog.
* Since we read these from the actual emulator, there is no necessity for this.
*/
@NonNull
public List<String> getAltExeList() {
Connection connect = connect();
try {
PreparedStatement statement = Objects.requireNonNull(connect).prepareStatement("SELECT Altexe FROM PupLookups");
ResultSet rs = statement.executeQuery();
if (rs.next()) {
String altExe = rs.getString("Altexe");
if (!StringUtils.isEmpty(altExe)) {
String[] split = altExe.split("\\r\\n");
return Arrays.asList(split);
}
}
rs.close();
statement.close();
}
catch (SQLException e) {
LOG.error("Failed to load altexe list: " + e.getMessage(), e);
}
finally {
disconnect(connect);
}

return Collections.emptyList();
}

@Nullable
public TableDetails getTableDetails(int id) {
ServerSettings serverSettings = preferencesService.getJsonPreference(PreferenceNames.SERVER_SETTINGS, ServerSettings.class);
Expand Down Expand Up @@ -279,7 +247,7 @@ public TableDetails getTableDetails(int id) {
}
}
catch (SQLException e) {
LOG.error("Failed to get game for id '" + id + "': " + e.getMessage(), e);
LOG.error("Failed to get game for id '{}': {}", id, e.getMessage(), e);
}
finally {
disconnect(connect);
Expand All @@ -303,7 +271,7 @@ public void updateTableFileUpdated(int id) {
preparedStatement.close();
}
catch (Exception e) {
LOG.error("Failed to save table details: " + e.getMessage(), e);
LOG.error("Failed to save table details: {}", e.getMessage(), e);
}
finally {
this.disconnect(connect);
Expand Down Expand Up @@ -1164,8 +1132,8 @@ public List<Emulator> getEmulators() {

//this can not be executed within a fetch!!!
for (Emulator emulator : result) {
if (emulator.getType().isVpxEmulator()) {
initVisualPinballXScripts(emulator);
if (emulator.getType().isVpxEmulator() || emulator.getType().isFpEmulator()) {
initEmulatorScripts(emulator);
}
}

Expand All @@ -1192,8 +1160,8 @@ public Emulator getEmulator(int emuId) {
finally {
this.disconnect(connect);
}
if (emulator != null && emulator.getType().isVpxEmulator()) {
initVisualPinballXScripts(emulator);
if (emulator != null && (emulator.getType().isVpxEmulator() || emulator.getType().isFpEmulator())) {
initEmulatorScripts(emulator);
}
return emulator;
}
Expand Down Expand Up @@ -1501,7 +1469,7 @@ public int getGameCount(int emuId) {
statement.close();
}
catch (SQLException e) {
LOG.error("Failed to read game count for emulator " + emuId + ": " + e.getMessage(), e);
LOG.error("Failed to read game count for emulator {}: {}", emuId, e.getMessage(), e);
}
finally {
this.disconnect(connect);
Expand Down Expand Up @@ -1553,7 +1521,7 @@ public List<Game> getGames() {
statement.close();
}
catch (SQLException e) {
LOG.error("Failed to get games: " + e.getMessage(), e);
LOG.error("Failed to get games: {}", e.getMessage(), e);
}
finally {
this.disconnect(connect);
Expand Down Expand Up @@ -1651,7 +1619,7 @@ private Map<Integer, PlaylistGame> getGamesFromPlaylist(int id) {
statement.close();
}
catch (SQLException e) {
LOG.error("Failed to read playlists: " + e.getMessage(), e);
LOG.error("Failed to read playlists: {}", e.getMessage(), e);
}
finally {
disconnect(connect);
Expand All @@ -1676,7 +1644,7 @@ private List<Integer> getGameIdsFromSqlPlaylist(String sql) {
statement.close();
}
catch (Exception e) {
LOG.error("Failed to read playlists: " + e.getMessage(), e);
LOG.error("Failed to read playlists: {}", e.getMessage(), e);
}
finally {
disconnect(connect);
Expand Down Expand Up @@ -1906,15 +1874,14 @@ private Map<String, String> getLookups() {
try {
Statement statement = Objects.requireNonNull(connect).createStatement();
ResultSet rs = statement.executeQuery("SELECT * FROM PupLookups;");
while (rs.next()) {
if (rs.next()) {
results.put("GameType", rs.getString("GameType"));
results.put("GameTheme", rs.getString("GameTheme"));
results.put("Manufact", rs.getString("Manufact"));
results.put("Category", rs.getString("Category"));
results.put("Custom1", rs.getString("Custom1"));
results.put("Custom2", rs.getString("Custom2"));
results.put("Custom3", rs.getString("Custom3"));
break;
}
rs.close();
statement.close();
Expand Down Expand Up @@ -1996,20 +1963,20 @@ public List<FrontendPlayerDisplay> getPupPlayerDisplays() {
display.setRotation(sectionNode.getInt("ScreenRotation"));
}
else {
LOG.warn("Unsupported PinUP display for screen '" + name + "', display has been skipped.");
LOG.warn("Unsupported PinUP display for screen '{}', display has been skipped.", name);
}
result.add(display);
}
catch (Exception e) {
LOG.error("Failed to create PinUPPlayerDisplay: " + e.getMessage());
LOG.error("Failed to create PinUPPlayerDisplay: {}", e.getMessage());
}
}
}

LOG.info("Loaded " + result.size() + " PinUPPlayer displays.");
}
catch (Exception e) {
LOG.error("Failed to get player displays: " + e.getMessage(), e);
LOG.error("Failed to get player displays: {}", e.getMessage(), e);
}
return result;
}
Expand Down Expand Up @@ -2145,9 +2112,7 @@ public boolean killFrontend() {
p.info().command().get().contains("VPinballX") ||
p.info().command().get().startsWith("VPinball") ||
p.info().command().get().contains("Future Pinball") ||
p.info().command().get().contains("B2SBackglassServerEXE") ||
p.info().command().get().contains("DOF")))
.collect(Collectors.toList());
p.info().command().get().contains("B2SBackglassServerEXE"))).collect(Collectors.toList());

if (pinUpProcesses.isEmpty()) {
LOG.info("No remaining PinUP processes found, termination finished.");
Expand Down Expand Up @@ -2326,7 +2291,6 @@ private java.util.Date getDateAsTimestamp(ResultSet set, String field) {
@Override
public void afterPropertiesSet() throws Exception {
try {
this.pupServer = new PupServer(this, systemService);
this.pupLauncher = new PupLauncher();
this.pupEventEmitter = new PupEventEmitter(this.getInstallationFolder());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,9 @@ public Optional<Highscore> getHighscore(@NonNull Game game, boolean forceScan, E
if (forceScan) {
if (highscore.isEmpty() && !StringUtils.isEmpty(game.getRom())) {
HighscoreMetadata metadata = scanScore(game, eventOrigin);
return updateHighscore(game, metadata, eventOrigin);
if (metadata != null) {
return updateHighscore(game, metadata, eventOrigin);
}
}
}
}
Expand All @@ -361,11 +363,12 @@ public Optional<Highscore> getHighscore(@NonNull Game game, boolean forceScan, E
return highscore;
}

@NonNull
@Nullable
public HighscoreMetadata scanScore(@NonNull Game game, @NonNull EventOrigin eventOrigin) {
if (!game.isVpxGame()) {
SLOG.error("Game " + game.getGameDisplayName() + " is not a VPX game.");
throw new UnsupportedOperationException("Game " + game.getGameDisplayName() + " is not a VPX game.");
SLOG.info("Game " + game.getGameDisplayName() + " is not a VPX game, highscore parsing cancelled.");
LOG.info("Game " + game.getGameDisplayName() + " is not a VPX game, highscore parsing cancelled.");
return null;
}
HighscoreMetadata highscoreMetadata = readHighscore(game);
updateHighscore(game, highscoreMetadata, eventOrigin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,12 @@ public void handle(WindowEvent event) {
tableScreensController.setGame(game, tableDetails);
tabPane.getSelectionModel().select(tab);

pinVolController.setData(stage, Arrays.asList(game), false);
try {
pinVolController.setData(stage, Arrays.asList(game), false);
}
catch (Exception e) {
LOG.error("Failed to init PinVol panel: {}", e.getMessage(), e);
}
}

private void setVpsTableIdValue(String value) {
Expand Down Expand Up @@ -1147,7 +1152,7 @@ private void initVpsStatus() {
private void refreshVersionsCombo(VpsTable tableById) {
if (tableById != null) {
GameEmulatorRepresentation emulatorRepresentation = client.getFrontendService().getGameEmulator(game.getEmulatorId());
List<String> tableFormat = emulatorRepresentation.getVpsEmulatorFeatures();
List<String> tableFormat = emulatorRepresentation.getVpsEmulatorFeatures();
List<VpsTableVersion> tableFiles = new ArrayList<>(tableById.getTableFilesForFormat(tableFormat));

if (!tableFiles.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,23 @@ public void setData(Stage stage, List<GameRepresentation> games, boolean showSys
systemVolume.setSsfRearVolume(t1);
}, 300));

if (games.size() == 1) {
GameRepresentation game = games.get(0);
entry = pinVolTablePreferences.getTableEntry(game.getGameFileName(), game.isVpxGame(), game.isFpGame());
}
else {
for (GameRepresentation game : games) {
try {
if (games.size() == 1) {
GameRepresentation game = games.get(0);
entry = pinVolTablePreferences.getTableEntry(game.getGameFileName(), game.isVpxGame(), game.isFpGame());
if (entry != null) {
break;
}
else {
for (GameRepresentation game : games) {
entry = pinVolTablePreferences.getTableEntry(game.getGameFileName(), game.isVpxGame(), game.isFpGame());
if (entry != null) {
break;
}
}
}
}
catch (Exception e) {
LOG.error("Failed to calculate matching PinVOL entry: {}", e.getMessage(), e);
}

if (!games.isEmpty()) {
setTableValues(systemVolume);
Expand Down

0 comments on commit 8307215

Please sign in to comment.