Adds running a game with Vice.
Joystick port and true drive emulation is used when launching the game.
This commit is contained in:
parent
5141cb9c2b
commit
cb60726142
|
@ -28,6 +28,7 @@ screens/
|
|||
games/
|
||||
covers/
|
||||
backup/
|
||||
vice/
|
||||
|
||||
pcu.properties
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import se.lantz.manager.ScraperManager;
|
|||
import se.lantz.model.MainViewModel;
|
||||
import se.lantz.model.data.GameListData;
|
||||
import se.lantz.model.data.ScraperFields;
|
||||
import se.lantz.util.FileManager;
|
||||
|
||||
public class GameDetailsBackgroundPanel extends JPanel
|
||||
{
|
||||
|
@ -56,6 +57,10 @@ public class GameDetailsBackgroundPanel extends JPanel
|
|||
setLayout(cardLayout);
|
||||
add(getEmptyPanel(), EMPTY);
|
||||
add(getDetailsPanel(), DETAILS);
|
||||
model.addSaveChangeListener(e -> {
|
||||
saveButton.setEnabled(model.isDataChanged());
|
||||
runButton.setEnabled(!model.getInfoModel().getGamesFile().isEmpty());
|
||||
});
|
||||
}
|
||||
|
||||
void focusTitleField()
|
||||
|
@ -162,10 +167,6 @@ public class GameDetailsBackgroundPanel extends JPanel
|
|||
{
|
||||
buttonPanel = new JPanel();
|
||||
GridBagLayout gbl_buttonPanel = new GridBagLayout();
|
||||
gbl_buttonPanel.columnWidths = new int[] { 0, 0, 0 };
|
||||
gbl_buttonPanel.rowHeights = new int[] { 0, 0 };
|
||||
gbl_buttonPanel.columnWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
|
||||
gbl_buttonPanel.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
|
||||
buttonPanel.setLayout(gbl_buttonPanel);
|
||||
GridBagConstraints gbc_scrapeButton = new GridBagConstraints();
|
||||
gbc_scrapeButton.weighty = 1.0;
|
||||
|
@ -176,12 +177,19 @@ public class GameDetailsBackgroundPanel extends JPanel
|
|||
buttonPanel.add(getScrapeButton(), gbc_scrapeButton);
|
||||
GridBagConstraints gbc_saveButton = new GridBagConstraints();
|
||||
gbc_saveButton.weighty = 1.0;
|
||||
gbc_saveButton.weightx = 1.0;
|
||||
gbc_saveButton.anchor = GridBagConstraints.SOUTHEAST;
|
||||
gbc_saveButton.insets = new Insets(5, 5, 5, 6);
|
||||
gbc_saveButton.gridx = 1;
|
||||
gbc_saveButton.gridx = 2;
|
||||
gbc_saveButton.gridy = 0;
|
||||
buttonPanel.add(getSaveButton(), gbc_saveButton);
|
||||
GridBagConstraints gbc_runButton = new GridBagConstraints();
|
||||
gbc_runButton.anchor = GridBagConstraints.EAST;
|
||||
gbc_runButton.weighty = 1.0;
|
||||
gbc_runButton.weightx = 1.0;
|
||||
gbc_runButton.insets = new Insets(5, 0, 5, 10);
|
||||
gbc_runButton.gridx = 1;
|
||||
gbc_runButton.gridy = 0;
|
||||
buttonPanel.add(getRunButton(), gbc_runButton);
|
||||
}
|
||||
return buttonPanel;
|
||||
}
|
||||
|
@ -190,9 +198,6 @@ public class GameDetailsBackgroundPanel extends JPanel
|
|||
{
|
||||
if (saveButton == null)
|
||||
{
|
||||
model.addSaveChangeListener(e -> {
|
||||
saveButton.setEnabled(model.isDataChanged());
|
||||
});
|
||||
saveButton = new JButton("Save");
|
||||
saveButton.addActionListener(new ActionListener()
|
||||
{
|
||||
|
@ -222,6 +227,7 @@ public class GameDetailsBackgroundPanel extends JPanel
|
|||
}
|
||||
|
||||
private ScraperDialog scraperDialog = null;
|
||||
private JButton runButton;
|
||||
|
||||
private void scrapeGamesInformation()
|
||||
{
|
||||
|
@ -282,4 +288,11 @@ public class GameDetailsBackgroundPanel extends JPanel
|
|||
}
|
||||
}
|
||||
}
|
||||
private JButton getRunButton() {
|
||||
if (runButton == null) {
|
||||
runButton = new JButton("Run game");
|
||||
runButton.addActionListener(e -> model.runGameInVice());
|
||||
}
|
||||
return runButton;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ public class VersionDownloadDialog extends BaseDialog
|
|||
setTitle("New version available");
|
||||
addContent(getVersionDownloadPanel());
|
||||
getOkButton().setText("Exit");
|
||||
getCancelButton().setText("Continue");
|
||||
getCancelButton().setText("Close");
|
||||
this.setResizable(false);
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ public class ImportOptionsPanel extends JPanel
|
|||
add(getFavoriteCheckBox(), gbc_favoriteCheckBox);
|
||||
GridBagConstraints gbc_matchLabel = new GridBagConstraints();
|
||||
gbc_matchLabel.insets = new Insets(15, 10, 15, 10);
|
||||
gbc_matchLabel.anchor = GridBagConstraints.NORTHWEST;
|
||||
gbc_matchLabel.anchor = GridBagConstraints.NORTH;
|
||||
gbc_matchLabel.weighty = 1.0;
|
||||
gbc_matchLabel.weightx = 1.0;
|
||||
gbc_matchLabel.gridx = 0;
|
||||
|
|
|
@ -39,7 +39,7 @@ public class MainViewModel extends AbstractModel
|
|||
private JoystickModel joy2Model = new JoystickModel(false);
|
||||
private SystemModel systemModel = new SystemModel();
|
||||
|
||||
private FileManager fileManager = new FileManager(infoModel);
|
||||
private FileManager fileManager = new FileManager(this);
|
||||
|
||||
private String currentGameId = "";
|
||||
|
||||
|
@ -436,4 +436,9 @@ public class MainViewModel extends AbstractModel
|
|||
gameListModel.notifyChange();
|
||||
}
|
||||
}
|
||||
|
||||
public void runGameInVice()
|
||||
{
|
||||
fileManager.runGameInVice();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@ import org.slf4j.LoggerFactory;
|
|||
import se.lantz.db.DbConnector;
|
||||
import se.lantz.gui.MainWindow;
|
||||
import se.lantz.model.InfoModel;
|
||||
import se.lantz.model.MainViewModel;
|
||||
import se.lantz.model.SystemModel;
|
||||
import se.lantz.model.data.GameDetails;
|
||||
|
||||
public class FileManager
|
||||
|
@ -44,32 +46,36 @@ public class FileManager
|
|||
|
||||
private static Properties fileProperties;
|
||||
|
||||
private InfoModel model;
|
||||
private MainViewModel model;
|
||||
private InfoModel infoModel;
|
||||
private SystemModel systemModel;
|
||||
|
||||
public FileManager(InfoModel model)
|
||||
public FileManager(MainViewModel model)
|
||||
{
|
||||
this.infoModel = model.getInfoModel();
|
||||
this.systemModel = model.getSystemModel();
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public void saveFiles()
|
||||
{
|
||||
//Check if title is different that in db, then rename existing files!
|
||||
if (model.isTitleChanged())
|
||||
if (infoModel.isTitleChanged())
|
||||
{
|
||||
//Rename existing covers and screens and game file
|
||||
renameFiles();
|
||||
}
|
||||
|
||||
//Fetch images that has been added
|
||||
BufferedImage cover = model.getCoverImage();
|
||||
BufferedImage screen1 = model.getScreen1Image();
|
||||
BufferedImage screen2 = model.getScreen2Image();
|
||||
String coverFileName = model.getCoverFile();
|
||||
String screen1FileName = model.getScreens1File();
|
||||
String screen2FileName = model.getScreens2File();
|
||||
BufferedImage cover = infoModel.getCoverImage();
|
||||
BufferedImage screen1 = infoModel.getScreen1Image();
|
||||
BufferedImage screen2 = infoModel.getScreen2Image();
|
||||
String coverFileName = infoModel.getCoverFile();
|
||||
String screen1FileName = infoModel.getScreens1File();
|
||||
String screen2FileName = infoModel.getScreens2File();
|
||||
|
||||
String gameName = model.getGamesFile();
|
||||
Path gamePath = model.getGamesPath();
|
||||
String gameName = infoModel.getGamesFile();
|
||||
Path gamePath = infoModel.getGamesPath();
|
||||
|
||||
//Store on disk with the name in the models. The UI must make sure the names is according to the Maxi format.
|
||||
|
||||
|
@ -162,11 +168,11 @@ public class FileManager
|
|||
|
||||
private void renameFiles()
|
||||
{
|
||||
String oldTitle = generateFileNameFromTitle(model.getTitleInDb());
|
||||
if (!model.getCoverFile().isEmpty())
|
||||
String oldTitle = generateFileNameFromTitle(infoModel.getTitleInDb());
|
||||
if (!infoModel.getCoverFile().isEmpty())
|
||||
{
|
||||
File oldCover = new File(COVERS + oldTitle + "-cover.png");
|
||||
File newCover = new File(COVERS + model.getCoverFile());
|
||||
File newCover = new File(COVERS + infoModel.getCoverFile());
|
||||
if (oldCover.renameTo(newCover))
|
||||
{
|
||||
logger.debug("Renamed cover {} to {}", oldCover.getName(), newCover.getName());
|
||||
|
@ -176,10 +182,10 @@ public class FileManager
|
|||
logger.debug("Could NOT rename cover {} to {}", oldCover.getName(), newCover.getName());
|
||||
}
|
||||
}
|
||||
if (!model.getScreens1File().isEmpty())
|
||||
if (!infoModel.getScreens1File().isEmpty())
|
||||
{
|
||||
File oldScreen1 = new File(SCREENS + oldTitle + "-00.png");
|
||||
File newScreen1 = new File(SCREENS + model.getScreens1File());
|
||||
File newScreen1 = new File(SCREENS + infoModel.getScreens1File());
|
||||
if (oldScreen1.renameTo(newScreen1))
|
||||
{
|
||||
logger.debug("Renamed screen1 {} to {}", oldScreen1.getName(), newScreen1.getName());
|
||||
|
@ -189,10 +195,10 @@ public class FileManager
|
|||
logger.debug("Could NOT rename screen1 {} to {}", oldScreen1.getName(), newScreen1.getName());
|
||||
}
|
||||
}
|
||||
if (!model.getScreens2File().isEmpty())
|
||||
if (!infoModel.getScreens2File().isEmpty())
|
||||
{
|
||||
File oldScreen2 = new File(SCREENS + oldTitle + "-01.png");
|
||||
File newScreen2 = new File(SCREENS + model.getScreens2File());
|
||||
File newScreen2 = new File(SCREENS + infoModel.getScreens2File());
|
||||
if (oldScreen2.renameTo(newScreen2))
|
||||
{
|
||||
logger.debug("Renamed screen2 {} to {}", oldScreen2.getName(), newScreen2.getName());
|
||||
|
@ -202,11 +208,11 @@ public class FileManager
|
|||
logger.debug("Could NOT rename screen2 {} to {}", oldScreen2.getName(), newScreen2.getName());
|
||||
}
|
||||
}
|
||||
if (!model.getGamesFile().isEmpty())
|
||||
if (!infoModel.getGamesFile().isEmpty())
|
||||
{
|
||||
String fileEnding = model.getGamesFile().substring(model.getGamesFile().indexOf("."));
|
||||
String fileEnding = infoModel.getGamesFile().substring(infoModel.getGamesFile().indexOf("."));
|
||||
File oldGame = new File(GAMES + oldTitle + fileEnding);
|
||||
File newGame = new File(GAMES + model.getGamesFile());
|
||||
File newGame = new File(GAMES + infoModel.getGamesFile());
|
||||
if (oldGame.renameTo(newGame))
|
||||
{
|
||||
logger.debug("Renamed game {} to {}", oldGame.getName(), newGame.getName());
|
||||
|
@ -330,6 +336,62 @@ public class FileManager
|
|||
}
|
||||
fw.close();
|
||||
}
|
||||
|
||||
public void runGameInVice()
|
||||
{
|
||||
String gameFile = GAMES + infoModel.getGamesFile();
|
||||
StringBuilder command = new StringBuilder();
|
||||
if (systemModel.isC64())
|
||||
{
|
||||
command.append("./vice/x64.exe ");
|
||||
}
|
||||
else
|
||||
{
|
||||
command.append("./vice/xvic.exe ");
|
||||
}
|
||||
//Append game file
|
||||
Path gamePath = infoModel.getGamesPath();
|
||||
if (gamePath != null)
|
||||
{
|
||||
command.append("-autostart " + gamePath.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
command.append("-autostart " + gameFile);
|
||||
}
|
||||
//Append truedrive
|
||||
command.append(" -autostart-handle-tde ");
|
||||
if (systemModel.isAccurateDisk())
|
||||
{
|
||||
command.append("-truedrive ");
|
||||
}
|
||||
else
|
||||
{
|
||||
command.append("+truedrive ");
|
||||
}
|
||||
//Append default joystick port
|
||||
if (model.getJoy1Model().isPrimary())
|
||||
{
|
||||
command.append("-joydev1 1 ");
|
||||
command.append("-joydev2 0");
|
||||
}
|
||||
else
|
||||
{
|
||||
command.append("-joydev1 0 ");
|
||||
command.append("-joydev2 1");
|
||||
}
|
||||
|
||||
//Launch Vice
|
||||
try
|
||||
{
|
||||
logger.debug("Launching VICE with command: {}", command.toString());
|
||||
Runtime. getRuntime().exec(command.toString());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
ExceptionHandler.handleException(e, "Could not launch Vice with command " + command) ;
|
||||
}
|
||||
}
|
||||
|
||||
public static void storeProperties()
|
||||
{
|
||||
|
@ -354,7 +416,6 @@ public class FileManager
|
|||
fileProperties = new Properties();
|
||||
try (InputStream input = new FileInputStream("./pcu.properties"))
|
||||
{
|
||||
|
||||
// load a properties file
|
||||
fileProperties.load(input);
|
||||
|
||||
|
|
Loading…
Reference in New Issue