diff options
author | Minteck <nekostarfan@gmail.com> | 2021-06-05 19:27:48 +0200 |
---|---|---|
committer | Minteck <nekostarfan@gmail.com> | 2021-06-05 19:27:48 +0200 |
commit | 8cf5cefe6e91a5a1ed6eeaae4d94760d84c304a6 (patch) | |
tree | 7096b67b189c0220826123c7d5b121752545d140 /views/script/core_stats.js | |
download | kartik-client-8cf5cefe6e91a5a1ed6eeaae4d94760d84c304a6.tar.gz kartik-client-8cf5cefe6e91a5a1ed6eeaae4d94760d84c304a6.tar.bz2 kartik-client-8cf5cefe6e91a5a1ed6eeaae4d94760d84c304a6.zip |
Presque sortie du jeu
Diffstat (limited to 'views/script/core_stats.js')
-rw-r--r-- | views/script/core_stats.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/views/script/core_stats.js b/views/script/core_stats.js new file mode 100644 index 0000000..5c7314f --- /dev/null +++ b/views/script/core_stats.js @@ -0,0 +1,47 @@ +const fs = require('fs'); +const homedir = require('@electron/remote').getCurrentWindow().homedir; +const defaultStats = { + times: { + game: 0, + single: 0, + local: 0, + online: 0 + }, + results: { + wins: 0, + loses: 0 + }, + ingame: { + walls: 0, + laps: 0, + turns: 0 + } +} + +if (!fs.existsSync(homedir + "/.kartik/stats.json")) { + fs.writeFileSync(homedir + "/.kartik/stats.json", JSON.stringify(defaultStats)); +} else { + try { + JSON.parse(fs.readFileSync(homedir + "/.kartik/stats.json").toString()); + } catch (e) { + fs.writeFileSync(homedir + "/.kartik/stats.json", JSON.stringify(defaultStats)); + } +} + +class Stats { + static add(category, counter, quantity) { + try { + let current = JSON.parse(fs.readFileSync(homedir + "/.kartik/stats.json").toString()); + current[category][counter] = current[category][counter] + quantity; + fs.writeFileSync(homedir + "/.kartik/stats.json", JSON.stringify(current)); + } catch (e) {} + } + + static set(category, counter, value) { + try { + let current = JSON.parse(fs.readFileSync(homedir + "/.kartik/stats.json").toString()); + current[category][counter] = value; + fs.writeFileSync(homedir + "/.kartik/stats.json", JSON.stringify(current)); + } catch (e) {} + } +}
\ No newline at end of file |