aboutsummaryrefslogtreecommitdiff
path: root/views/script/core_stats.js
diff options
context:
space:
mode:
Diffstat (limited to 'views/script/core_stats.js')
-rw-r--r--views/script/core_stats.js47
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