From 8cf5cefe6e91a5a1ed6eeaae4d94760d84c304a6 Mon Sep 17 00:00:00 2001 From: Minteck Date: Sat, 5 Jun 2021 19:27:48 +0200 Subject: Presque sortie du jeu --- views/script/core_stats.js | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 views/script/core_stats.js (limited to 'views/script/core_stats.js') 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 -- cgit