-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (40 loc) · 1.63 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const express = require('express')
const fs = require('fs');
const { get } = require('http');
const {join} = require('path');
const { isNumberObject } = require('util/types');
const app = express()
let port = 30000
const arguments = Object.fromEntries(process.argv.slice(2).map(arg => arg.split('=' )));
if(arguments.port || Number.isInteger(arguments.port)){
port = arguments.port
}
app.use(express.static('public'))
app.listen(port, () => {
console.log(`MARVEL SNAP Decklist Overlay running on port ${port}`)
})
function getPath(fileToWatch){
const user_dir = process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Preferences' : process.env.HOME + "/.local/share")
return join(
user_dir,
'LocalLow',
'Second Dinner',
'SNAP',
'Standalone',
'States',
'nvprod',
fileToWatch
).replace('Roaming\\', '');
}
app.get('/current_deck',async (req, res) => {
let playState_string = await fs.readFileSync(getPath('PlayState.json'), {encoding:'utf8', flag:'r'});
console.log(playState_string)
playState_string = playState_string.replace(/\s/,'');
const playState_json = await JSON.parse(playState_string);
const decck_id = playState_json.SelectedDeckId;
let collection_string = fs.readFileSync(getPath('CollectionState.json'), {encoding:'utf8', flag:'r'});
collection_string = collection_string.replace(/\s/,'');;
const collection_json = await JSON.parse(collection_string);
const deck_data = collection_json.ServerState.Decks.find((deck) => deck.Id === decck_id )
res.send(deck_data)
})