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) {} } }