-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧 #77 [feat/config] auto change config for a game
Signed-off-by: JAGFx <contact@jagfx.fr>
- Loading branch information
Showing
16 changed files
with
185 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../server/src/services |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../server/src/utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* @author: Emmanuel SMITH <hey@emmanuel-smith.me> | ||
* project: ets2-dashboard-skin | ||
* file: config.service.js | ||
* Date: 18/10/2021 | ||
* Time: 19:48 | ||
*/ | ||
|
||
import { saveAppConfig, saveGameConfig, config } from '../utils/config.util'; | ||
|
||
const postConfigRequest = ( req, res, basePath = null ) => { | ||
saveAppConfig( req.body.app, basePath ); | ||
saveGameConfig( req.params.target, req.body.game, basePath ); | ||
|
||
config = { | ||
app: req.body.app, | ||
game: req.body.game | ||
}; | ||
res.send( req.body ); | ||
} | ||
|
||
const getConfigRequest = ( req, res ) => { | ||
res.send( config ); | ||
} | ||
|
||
export const initConfig = (app, basePath = null) => { | ||
app.post( '/config/:target', ( req, res) => { | ||
postConfigRequest( req, res, basePath ) | ||
} ); | ||
app.get( '/config', getConfigRequest ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* @author: Emmanuel SMITH <hey@emmanuel-smith.me> | ||
* project: ets2-dashboard-skin | ||
* file: telemetry.service.js | ||
* Date: 18/10/2021 | ||
* Time: 20:09 | ||
*/ | ||
|
||
import { config, gameConfig } from '../utils/config.util'; | ||
|
||
export const telemetryInterval = () => { | ||
return (config.app.hasOwnProperty( 'general_refresh_rate' )) | ||
? Math.min( parseInt( config.app.general_refresh_rate ), 100 ) | ||
: 100; | ||
}; | ||
|
||
export const telemetryWatch = (io, telemetry) => { | ||
telemetry.watch( { interval: telemetryInterval }, data => { | ||
if ( config.game === null && data.game.game.name !== undefined ) | ||
config.game = gameConfig( data.game.game.name ); | ||
|
||
io.emit( 'update', data ); | ||
} ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* @author: Emmanuel SMITH <hey@emmanuel-smith.me> | ||
* project: ets2-dashboard-skin | ||
* file: _config.js | ||
* Date: 14/10/2021 | ||
* Time: 19:24 | ||
*/ | ||
|
||
import { existsSync, readFileSync, writeFileSync } from 'fs'; | ||
import path from 'path'; | ||
|
||
const oldConfigPath = (basePath = null) => path.resolve( basePath ?? process.cwd(), './config.ets2-dashboard-skin.json' ); | ||
|
||
export const appConfigPath = (basePath = null) => { | ||
const newAppConfigPath = path.resolve( basePath ?? process.cwd(), `./config.json` ); | ||
|
||
return ( existsSync( newAppConfigPath ) ) | ||
? newAppConfigPath | ||
: oldConfigPath(basePath) | ||
} | ||
|
||
export const gameConfigPath = (target, basePath = null) => { | ||
const newGameConfigPath = path.resolve( basePath ?? process.cwd(), `./config.${ target }.json` ); | ||
|
||
return ( existsSync( newGameConfigPath ) ) | ||
? newGameConfigPath | ||
: oldConfigPath(basePath) | ||
} | ||
|
||
export const appConfig = (basePath = null) => readFileSync( appConfigPath(basePath), 'UTF-8' ); | ||
|
||
export const gameConfig = (target, basePath = null) => readFileSync( gameConfigPath(target, basePath), 'UTF-8' ); | ||
|
||
export const saveAppConfig = (data, basePath = null) => { | ||
writeFileSync( appConfigPath(basePath), JSON.stringify( data, null, 2 ) ); | ||
} | ||
|
||
export const saveGameConfig = (target, data, basePath = null) => { | ||
writeFileSync( gameConfigPath(target, basePath), JSON.stringify( data, null, 2 ) ); | ||
} | ||
|
||
export let config = { | ||
app: appConfig(), | ||
game: null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"general_region" : "eu", | ||
"general_refresh_rate" : 100, | ||
"general_skin_on_load" : "JAGFx", | ||
"general_unit_auto" : false, | ||
"general_h-shift-layout" : "h-shifter", | ||
"general_skin_locale" : "en-EN", | ||
"general_job_remaining" : "due_date" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.