OpenDeck/types/Deck.js

50 lines
1 KiB
JavaScript
Raw Permalink Normal View History

2021-03-08 19:42:32 +01:00
const Base = require("./Base");
const db = require("../db.json");
class Deck extends Base {
static name = "Deck";
static type = "deck";
2021-03-08 19:42:32 +01:00
constructor(text, image = null, options = null) {
super(text, image, options);
}
static fields() {
return {
deck: {
type: "select",
options: Object.keys(db.decks),
name: "Deck",
required: true,
}
};
}
/**
* @override
*/
static staticToJSON() {
return super.staticToJSON(Deck.name, Deck.type, Deck.fields());
}
2021-03-08 19:42:32 +01:00
/**
* @override
*/
toJSON() {
return super.toJSON(Deck.type)
2021-03-08 19:42:32 +01:00
}
/**
* @override
*/
trigger(socket) {
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;