Newer
Older
var errmap = {
"0": {
code: 200,
message: "Ok"
},
"1": {
code: 404,
message: "Retro Arch Not Found"
},
"2": {
code: 400,
message: "Invalid Input Given"
}
},
controlmap = {
gba: {
left: "Left",
right: "Right",
up: "Up",
down: "Down",
a: "x",
b: "z",
y: "a",
x: "s",
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
r: "w",
l: "q",
select: "Shift_R",
start: "Return"
}
},
curControl = "gba";
exec = require("child_process").exec,
q = require("q");
module.exports = {
do: function(virtualKey) {
var def = q.defer();
if (!controlmap[curControl].hasOwnProperty(virtualKey)) {
def.reject(new Error("Invalid Virtual Keypress"));
} else {
exec("bash scripts/xscrp.sh " + controlmap[curControl][virtualKey], function(err, stdout, stderr) {
if (err) {
def.reject(err);
} else {
def.resolve(stdout.toString());
}
});
}
return def.promise;
},
set controls (e) {
if (controlmap.hasOwnProperty(e)) {
curControl = e;
} else {
throw new Error("Invalid Control Scheme");
}
},
get controls () {
return curControl;
},
get errs () {
return errmap;
}
}