2021-03-09 00:12:17 +01:00
|
|
|
const db = require("../db.json");
|
|
|
|
const fs = require("fs");
|
|
|
|
|
2021-03-08 19:42:32 +01:00
|
|
|
/**
|
|
|
|
* @abstract
|
|
|
|
*/
|
|
|
|
class Base {
|
2021-03-09 00:12:17 +01:00
|
|
|
static name = "Base";
|
2021-03-08 19:42:32 +01:00
|
|
|
|
|
|
|
constructor(text, image = null, options = null) {
|
|
|
|
this.text = text;
|
|
|
|
this.image = image;
|
|
|
|
this.options = options;
|
|
|
|
}
|
|
|
|
|
|
|
|
trigger() {
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
2021-03-09 00:12:17 +01:00
|
|
|
save(name, position) {
|
|
|
|
if (!(position[0] in db.decks[name].rows))
|
|
|
|
db.decks[name].rows[position[0]] = {};
|
|
|
|
db.decks[name].rows[position[0]][position[1]] = this.toJSON();
|
2021-03-09 17:18:39 +01:00
|
|
|
Base.write()
|
|
|
|
}
|
|
|
|
|
|
|
|
static saveConfig(type, configuration) {
|
|
|
|
db.types[type] = configuration;
|
|
|
|
Base.write();
|
2021-03-09 08:23:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
remove(name, position) {
|
|
|
|
if (position[0] in db.decks[name].rows && position[1] in db.decks[name].rows[position[0]]) {
|
|
|
|
delete db.decks[name].rows[position[0]][position[1]];
|
2021-03-09 17:18:39 +01:00
|
|
|
Base.write();
|
2021-03-09 08:23:20 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-03-09 17:18:39 +01:00
|
|
|
static write() {
|
2021-03-09 00:12:17 +01:00
|
|
|
fs.writeFileSync("./db.json", JSON.stringify(db));
|
|
|
|
}
|
|
|
|
|
2021-03-09 17:18:39 +01:00
|
|
|
static staticToJSON(name, type, fields, config) {
|
2021-03-09 00:12:17 +01:00
|
|
|
return {
|
|
|
|
"name": name,
|
|
|
|
"type": type,
|
2021-03-09 17:18:39 +01:00
|
|
|
"fields": fields,
|
|
|
|
"configuration": config
|
2021-03-09 00:12:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-08 19:42:32 +01:00
|
|
|
toJSON(type) {
|
|
|
|
return {
|
|
|
|
"text": this.text,
|
|
|
|
"image": this.image,
|
|
|
|
"type": type,
|
|
|
|
"options": this.options
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Base;
|