Add keys type and support of async trigger
This commit is contained in:
parent
cccfacfa02
commit
080550b8bc
6 changed files with 81 additions and 3 deletions
15
package-lock.json
generated
15
package-lock.json
generated
|
@ -17,6 +17,9 @@
|
|||
"node-sass-middleware": "0.11.0",
|
||||
"pug": "2.0.0-beta11",
|
||||
"socket.io": "^3.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"node-key-sender": "^1.0.11"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/babel-types": {
|
||||
|
@ -1617,6 +1620,12 @@
|
|||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/node-key-sender": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/node-key-sender/-/node-key-sender-1.0.11.tgz",
|
||||
"integrity": "sha512-vv2IXd8QdZBFYXaIy02uy2rK6EKj+tOTEuoTxJKS9l8zw8Cz6DeLffR8ompj7N2A3h6XK7aiy+YAcTaeOqwp2Q==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/node-sass": {
|
||||
"version": "4.14.1",
|
||||
"resolved": "https://registry.npmjs.org/node-sass/-/node-sass-4.14.1.tgz",
|
||||
|
@ -4284,6 +4293,12 @@
|
|||
"which": "1"
|
||||
}
|
||||
},
|
||||
"node-key-sender": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/node-key-sender/-/node-key-sender-1.0.11.tgz",
|
||||
"integrity": "sha512-vv2IXd8QdZBFYXaIy02uy2rK6EKj+tOTEuoTxJKS9l8zw8Cz6DeLffR8ompj7N2A3h6XK7aiy+YAcTaeOqwp2Q==",
|
||||
"dev": true
|
||||
},
|
||||
"node-sass": {
|
||||
"version": "4.14.1",
|
||||
"resolved": "https://registry.npmjs.org/node-sass/-/node-sass-4.14.1.tgz",
|
||||
|
|
|
@ -15,5 +15,8 @@
|
|||
"node-sass-middleware": "0.11.0",
|
||||
"pug": "2.0.0-beta11",
|
||||
"socket.io": "^3.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"node-key-sender": "^1.0.11"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -159,6 +159,8 @@ function customFields(values) {
|
|||
d.classList.add("input-field");
|
||||
d.insertAdjacentElement("beforeend", e);
|
||||
d.insertAdjacentHTML("beforeend", `<label for="${name}">${field.name}</label>`);
|
||||
if (field.helper)
|
||||
d.insertAdjacentHTML("beforeend", `<span class="helper-text">${field.helper}</span>`);
|
||||
customs.insertAdjacentElement("beforeend", d);
|
||||
if (values && name in values) {
|
||||
e.value = values[name];
|
||||
|
|
|
@ -2,7 +2,7 @@ const db = require("../db.json");
|
|||
const getSlot = require("../types").getSlot;
|
||||
|
||||
module.exports = socket => {
|
||||
return data => {
|
||||
return async data => {
|
||||
let err = null;
|
||||
if (data && Array.isArray(data) && data.length === 3) {
|
||||
if (db.decks[data[0]]) {
|
||||
|
@ -10,7 +10,10 @@ module.exports = socket => {
|
|||
|
||||
if (el) {
|
||||
try {
|
||||
el.trigger(socket);
|
||||
if (el.trigger.constructor.name === "AsyncFunction")
|
||||
await el.trigger(socket);
|
||||
else
|
||||
el.trigger(socket);
|
||||
} catch (exc) {
|
||||
err = "unknown";
|
||||
console.error(exc)
|
||||
|
|
54
types/Keys.js
Normal file
54
types/Keys.js
Normal file
|
@ -0,0 +1,54 @@
|
|||
const Base = require("./Base");
|
||||
const ks = require('node-key-sender');
|
||||
|
||||
|
||||
class Keys extends Base {
|
||||
static name = "Keys";
|
||||
static type = "keys";
|
||||
static fields = {
|
||||
keys: {
|
||||
type: "text",
|
||||
name: "Keys",
|
||||
helper: "Key separated by a comma, if combo use +"
|
||||
}
|
||||
};
|
||||
|
||||
constructor(text, image = null, options = null) {
|
||||
super(text, image, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
static staticToJSON() {
|
||||
return super.staticToJSON(Keys.name, Keys.type, Keys.fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
toJSON() {
|
||||
return super.toJSON(Keys.type)
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
async trigger() {
|
||||
let keys = this.options.keys.split(",");
|
||||
let toSend = [];
|
||||
|
||||
for (const key of keys)
|
||||
if (key.match(/\S\+\S/))
|
||||
toSend.push([ks.sendCombination, key.split("+")]);
|
||||
else if (toSend.length !== 0 && toSend[toSend.length-1][0] === ks.sendKeys)
|
||||
toSend[toSend.length-1][1].push(key);
|
||||
else
|
||||
toSend.push([ks.sendKeys, [key]]);
|
||||
|
||||
for (const send of toSend)
|
||||
await send[0](send[1]);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Keys;
|
|
@ -2,7 +2,8 @@ const db = require("../db.json");
|
|||
|
||||
const types = {
|
||||
"execCommand": require("./ExecCommand"),
|
||||
"deck": require("./Deck")
|
||||
"deck": require("./Deck"),
|
||||
"keys": require("./Keys")
|
||||
};
|
||||
|
||||
module.exports.types = types;
|
||||
|
|
Loading…
Reference in a new issue