Skip to content

Commit

Permalink
Add "Launch FS2022" button to header, bump to 0.9.85
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsage committed Oct 25, 2022
1 parent 0d71cdc commit 27bb691
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 11 deletions.
53 changes: 52 additions & 1 deletion modAssist_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ const trayIcon = !app.isPackaged

let pathBestGuess = userHome
let foundPath = false
let foundGame = ''

const gameExeName = 'FarmingSimulator2022.exe'
const gameGuesses = [
'C:\\Program Files (x86)\\Farming Simulator 2022\\',
'C:\\Program Files (x86)\\Steam\\steamapps\\common\\Farming Simulator 22'
]
const pathGuesses = [
path.join(userHome, 'OneDrive', 'Documents', 'My Games', 'FarmingSimulator2022'),
path.join(userHome, 'Documents', 'My Games', 'FarmingSimulator2022')
Expand All @@ -75,6 +81,12 @@ try {
pathGuesses.unshift(path.join(userFolder, 'My Games', 'FarmingSimulator2022'))
} catch { /* do nothing */ }

gameGuesses.forEach((testPath) => {
if ( fs.existsSync(path.join(testPath, gameExeName)) ) {
foundGame = path.join(testPath, gameExeName)
}
})

pathGuesses.forEach((testPath) => {
if ( !foundPath && fs.existsSync(testPath) ) {
foundPath = true
Expand All @@ -96,6 +108,7 @@ const settingsSchema = {
lock_lang : { type : 'boolean', default : false },
force_lang : { type : 'string', default : '' },
game_settings : { type : 'string', default : path.join(pathBestGuess, 'gameSettings.xml') },
game_path : { type : 'string', default : foundGame },
}

const Store = require('electron-store')
Expand Down Expand Up @@ -564,6 +577,25 @@ ipcMain.on('getDebugLogContents', (event) => { event.sender.send('update-log',
/** END: Debug window operation */


/** Game launcher */
ipcMain.on('toMain_startFarmSim', () => {
if ( mcStore.get('game_path') !== '' ) {
const cp = require('child_process')
const progPath = mcStore.get('game_path')
const child = cp.spawn(progPath, { detached : true, stdio : ['ignore', 'ignore', 'ignore'] })
child.unref()
} else {
const dialogOpts = {
type : 'info',
title : 'Game Path Not Found',
message : 'Please set the game path in preferences',
}
dialog.showMessageBox(dialogOpts)
log.log.warning('Game path not set!', 'game-launcher')
}
})
/** END: game launcher */

/** Preferences window operation */
ipcMain.on('toMain_openPrefs', () => { createPrefsWindow() })
ipcMain.on('toMain_getPref', (event, name) => { event.returnValue = mcStore.get(name) })
Expand Down Expand Up @@ -611,7 +643,26 @@ ipcMain.on('toMain_setPrefFile', (event) => {
}).catch((unknownError) => {
log.log.danger(`Could not read specified gamesettings : ${unknownError}`, 'game-settings')
})

})
ipcMain.on('toMain_setGamePath', (event) => {
dialog.showOpenDialog(windows.prefs, {
properties : ['openFile'],
defaultPath : path.join(userHome, gameExeName),
filters : [
{ name : gameExeName, extensions : ['exe'] },
{ name : 'All', extensions : ['*'] },
],
}).then((result) => {
if ( ! result.canceled ) {
mcStore.set('game_path', result.filePaths[0])
gameSettings = result.filePaths[0]
parseSettings()
refreshClientModList()
event.sender.send( 'fromMain_allSettings', mcStore.store )
}
}).catch((unknownError) => {
log.log.danger(`Could not read specified game EXE : ${unknownError}`, 'game-path')
})
})
/** END: Preferences window operation */

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fsg-mod-assistant",
"version": "0.9.81",
"version": "0.9.85",
"description": "FSG Farm Sim Mod Assistant",
"main": "modAssist_main.js",
"homepage": "https://github.com/FSGModding/FSG_Mod_Assistant#readme",
Expand Down
8 changes: 5 additions & 3 deletions renderer/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<div class="container-fluid px-0 user-select-none">
<div class="fixed-top pt-2 pb-2 bg-body" id="main-header">
<div class="row w-100 mb-2">
<div class="col-8 border-bottom">
<div class="col-6 border-bottom">
<h2 class="ps-2 mastHead"><l10n name="app_name"></l10n> <l10n class="ver" name="app_version"></l10n></h2>
</div>
<div class="col-3">
Expand All @@ -107,8 +107,10 @@ <h2 class="ps-2 mastHead"><l10n name="app_name"></l10n> <l10n class="ver" name="
</div>
</div>
</div>
<div class="col-1 text-end">
<button onclick="window.mods.openPreferences()" class="btn btn-outline-light text-center w-100" id="open_prefs"><l10n name="preferences_button"></l10n></button>
<div class="col-3 text-end">
<button onclick="window.mods.startFarmSim()" class="btn btn-primary w-75" id="open_prefs"><l10n name="launch_fs22"></l10n></button>
<button onclick="window.mods.openPreferences()" class="btn btn-outline-light" id="open_prefs"><l10n name="preferences_button"></l10n></button>

</div>
</div>

Expand Down
11 changes: 11 additions & 0 deletions renderer/prefs.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ <h2 class="ps-2 mastHead"><l10n name="app_name"></l10n> <l10n class="ver" name="
</div>
</div>

<div class="row mx-4 mb-3 pb-2 border-bottom">
<div class="col-8">
<h5><l10n name="user_pref_title_game_path"></l10n></h5>
<p class="ps-2"><l10n name="user_pref_blurb_game_path"></l10n></p>
<em class="ps-2 text-monospace small" id="game_path">TODO: FIX THIS</em>
</div>
<div class="col-4">
<div class="d-block btn btn-success btn-sm w-100 mt-5 mx-auto mb-3" onclick="window.mods.setGamePath()"><l10n name="user_pref_button_game_path"></l10n></div>
</div>
</div>

<div class="row mx-4 mb-3 pb-2 border-bottom">
<div class="col-8">
<h5><l10n name="user_pref_title_game_settings"></l10n></h5>
Expand Down
1 change: 1 addition & 0 deletions renderer/preload/preload-mainWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ contextBridge.exposeInMainWorld(

contextBridge.exposeInMainWorld(
'mods', {
startFarmSim : () => { ipcRenderer.send('toMain_startFarmSim') },
openPreferences : () => { ipcRenderer.send('toMain_openPrefs') },
addFolder : () => { ipcRenderer.send('toMain_addFolder') },
editFolders : () => { ipcRenderer.send('toMain_editFolders') },
Expand Down
1 change: 1 addition & 0 deletions renderer/preload/preload-prefsWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ contextBridge.exposeInMainWorld(
'mods', {
closeWindow : ( ) => { ipcRenderer.send('toMain_closeSubWindow', 'prefs') },
cleanCache : () => { ipcRenderer.send('toMain_cleanCacheFile') },
setGamePath : () => { ipcRenderer.send('toMain_setGamePath') },
setPrefFile : () => { ipcRenderer.send('toMain_setPrefFile') },
setPref : ( name, value ) => { ipcRenderer.send('toMain_setPref', name, value) },
receive : ( channel, func ) => {
Expand Down
6 changes: 5 additions & 1 deletion translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,9 @@
"version_diff": "Versionsabweichung",
"version_same": "Version Match",
"mod_badge_nonmh": "nonModHub",
"mod_badge_nonmh__title": "Diese Mod ist nicht im Modhub des Spiels verfügbar"
"mod_badge_nonmh__title": "Diese Mod ist nicht im Modhub des Spiels verfügbar",
"user_pref_title_game_path" : "Spielverlauf",
"user_pref_blurb_game_path" : "Legen Sie hier den Pfad zum Spiel fest, um die Schaltfläche \"FS22 starten\" zu aktivieren",
"user_pref_button_game_path" : "Spielpfad festlegen",
"launch_fs22" : "FS2022 starten"
}
6 changes: 5 additions & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,9 @@
"version_diff" : "Version Mismatch",
"version_same" : "Version Match",
"mod_badge_nonmh" : "nonModHub",
"mod_badge_nonmh__title" : "This mod is not available on the in-game modhub"
"mod_badge_nonmh__title" : "This mod is not available on the in-game modhub",
"user_pref_title_game_path" : "Game Path",
"user_pref_blurb_game_path" : "Set the path to the game here to enable the Launch FS22 Button",
"user_pref_button_game_path" : "Set Game Path",
"launch_fs22" : "Launch FS2022"
}
6 changes: 5 additions & 1 deletion translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,9 @@
"version_diff": "Desajuste de la versión",
"version_same": "Versión de la partida",
"mod_badge_nonmh": "nonModHub",
"mod_badge_nonmh__title": "Este mod no está disponible en el modhub del juego"
"mod_badge_nonmh__title": "Este mod no está disponible en el modhub del juego",
"user_pref_title_game_path" : "Ruta de juego",
"user_pref_blurb_game_path" : "Establezca aquí la ruta del juego para activar el botón de lanzamiento de FS22",
"user_pref_button_game_path" : "Establecer ruta de juego",
"launch_fs22" : "Lanzar FS2022"
}
6 changes: 5 additions & 1 deletion translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,9 @@
"version_diff": "Erreur de version",
"version_same": "Version Match",
"mod_badge_nonmh": "nonModHub",
"mod_badge_nonmh__title": "Ce mod n'est pas disponible sur le modhub du jeu."
"mod_badge_nonmh__title": "Ce mod n'est pas disponible sur le modhub du jeu.",
"user_pref_title_game_path" : "Chemin du jeu",
"user_pref_blurb_game_path" : "Définissez ici le chemin du jeu pour activer le bouton de lancement de FS22",
"user_pref_button_game_path" : "Définir le chemin du jeu",
"launch_fs22" : "Lancer FS2022"
}
6 changes: 5 additions & 1 deletion translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,9 @@
"version_diff": "Verkeerde versie",
"version_same": "Versie wedstrijd",
"mod_badge_nonmh": "nonModHub",
"mod_badge_nonmh__title": "Deze mod is niet beschikbaar op de in-game modhub"
"mod_badge_nonmh__title": "Deze mod is niet beschikbaar op de in-game modhub",
"user_pref_title_game_path" : "Game Path",
"user_pref_blurb_game_path" : "Stel hier het pad naar het spel in om de Lanceer FS22 knop in te schakelen.",
"user_pref_button_game_path" : "Set Game Path",
"launch_fs22" : "Start FS2022"
}
6 changes: 5 additions & 1 deletion translations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,9 @@
"version_diff": "Różne wersje",
"version_same": "Ta sama wersja",
"mod_badge_nonmh": "nonModHub",
"mod_badge_nonmh__title": "Ten mod nie jest dostępny na ModHubie"
"mod_badge_nonmh__title": "Ten mod nie jest dostępny na ModHubie",
"user_pref_title_game_path" : "Ścieżka gry",
"user_pref_blurb_game_path" : "Ustaw tutaj ścieżkę do gry, aby włączyć przycisk Launch FS22",
"user_pref_button_game_path" : "Set Game Path",
"launch_fs22" : "Launch FS2022"
}

0 comments on commit 27bb691

Please sign in to comment.