2021-03-08 19:42:32 +01:00
|
|
|
const Base = require("./Base");
|
|
|
|
const db = require("../db.json");
|
|
|
|
|
|
|
|
|
|
|
|
class Deck extends Base {
|
2021-03-09 00:12:17 +01:00
|
|
|
static name = "Deck";
|
|
|
|
static type = "deck";
|
|
|
|
|
2021-03-08 19:42:32 +01:00
|
|
|
constructor(text, image = null, options = null) {
|
|
|
|
super(text, image, options);
|
|
|
|
}
|
|
|
|
|
2021-03-09 00:12:17 +01:00
|
|
|
static fields() {
|
|
|
|
return {
|
|
|
|
deck: {
|
2021-03-09 17:18:39 +01:00
|
|
|
type: "select",
|
|
|
|
options: Object.keys(db.decks),
|
|
|
|
name: "Deck",
|
|
|
|
required: true,
|
2021-03-09 00:12:17 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
|
|
|
static staticToJSON() {
|
|
|
|
return super.staticToJSON(Deck.name, Deck.type, Deck.fields());
|
|
|
|
}
|
|
|
|
|
2021-03-08 19:42:32 +01:00
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
|
|
|
toJSON() {
|
2021-03-09 00:12:17 +01:00
|
|
|
return super.toJSON(Deck.type)
|
2021-03-08 19:42:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
|
|
|
trigger(socket) {
|
2021-03-09 00:12:17 +01:00
|
|
|
if (this.options && typeof this.options.deck === "string") {
|
|
|
|
socket.emit("getDeck", {name: this.options.deck, data: db.decks[this.options.deck]});
|
2021-03-08 19:42:32 +01:00
|
|
|
} else
|
|
|
|
socket.emit("trigger", {error: "invalidOptions"});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Deck;
|