From 92150f3fbe09b7e939ddf2b60e9b236455a3bc2a Mon Sep 17 00:00:00 2001
From: Louis Capitanchik <ljcapitanio@gmail.com>
Date: Tue, 8 Mar 2016 03:05:21 +0000
Subject: [PATCH] Interface and usability tweaks, now supports 4/4/2 game
 setups

---
 app.js                   | 32 +++++++++++++++++++++++-
 conf.json                |  4 +++
 local_modules/xbridge.js |  2 ++
 package.json             |  2 ++
 public/index.html        | 54 +++++++++++++++++++++++++++++-----------
 scripts/xscrp.sh         |  4 ++-
 6 files changed, 82 insertions(+), 16 deletions(-)
 create mode 100644 conf.json

diff --git a/app.js b/app.js
index a017388..920f29b 100644
--- a/app.js
+++ b/app.js
@@ -1,3 +1,4 @@
+"use strict";
 var exec = require("child_process").exec,
     level = require("levelup"),
     http = require("combi-server")({
@@ -9,12 +10,17 @@ var exec = require("child_process").exec,
             lib: true
         }
     }),
+    Form = require("formidable"),
     q = require("q"),
     reroute = require("./local_modules/reroute"),
     path = require("path"),
     x = require("./local_modules/xbridge"),
+    Route = require("combi-server-router"),
 
-    ni = require("os").networkInterfaces()["eth0"].reduce(function(p, c){if(c.family == "IPv4"){return c;}else{return p;}}, null);
+    router = new Route.Router(),
+    ni = require("os").networkInterfaces();
+
+const conf = require("./conf");
 
 console.dir(ni);
 
@@ -22,9 +28,31 @@ reroute.add("/", "/index.html");
 reroute.add("/log", "/chat.html");
 
 http.use(reroute.middleware);
+http.use((req, res, next) => {
+  let def = q.defer();
+  if(req.method.toLowerCase() == "post") {
+    let form = new Form.IncomingForm();
+    form.parse(req, (err, fields, files) => {
+      if(err) {
+        def.reject(err);
+      }
+      req.body = fields;
+      def.resolve(next());
+    });
+  } else {
+    def.resolve(next());
+  }
+  return def.promise;
+});
 
 http.static(path.join(__dirname, "public"));
 
+// router.post("/token", (req, res) => {
+//
+// });
+
+http.use(Route.middleware(router));
+
 http.ws.do("input:json", function(conn, data) {
     x.do(data.key)
     .then(function(e) {
@@ -46,4 +74,6 @@ http.ws.do("input:json", function(conn, data) {
     });
 })
 
+
+
 http.listen();
diff --git a/conf.json b/conf.json
new file mode 100644
index 0000000..3e4b113
--- /dev/null
+++ b/conf.json
@@ -0,0 +1,4 @@
+{
+  "username": "Commander-lol",
+  "password": "PlayfulFox"
+}
diff --git a/local_modules/xbridge.js b/local_modules/xbridge.js
index 067fbed..3207720 100644
--- a/local_modules/xbridge.js
+++ b/local_modules/xbridge.js
@@ -20,6 +20,8 @@ var errmap = {
             down: "Down",
             a: "x",
             b: "z",
+            y: "a",
+            x: "s",
             r: "w",
             l: "q",
             select: "Shift_R",
diff --git a/package.json b/package.json
index 84b3281..c5b816d 100644
--- a/package.json
+++ b/package.json
@@ -6,6 +6,8 @@
   "main": "app.js",
   "dependencies": {
     "combi-server": "^1.3.2",
+    "combi-server-router": "^1.0.1",
+    "formidable": "^1.0.17",
     "leveldown": "^1.4.3",
     "levelup": "^1.3.1",
     "node-ip": "^0.1.2",
diff --git a/public/index.html b/public/index.html
index a3a0c60..7249613 100644
--- a/public/index.html
+++ b/public/index.html
@@ -24,7 +24,7 @@
                 opacity: 0;
                 transition: opacity 0.1s linear;
             }
-            .hitbox:hover {
+            .hitbox:active {
                 opacity: 0.3;
             }
 
@@ -47,14 +47,11 @@
             #b .box {
                 fill: #f0ba24;
             }
-
-            .hitbox {
-                fill: black;
-                opacity: 0;
-                transition: opacity 0.1s linear;
+            #y .box {
+                fill: #11ff33;
             }
-            .hitbox:hover {
-                opacity: 0.3;
+            #x .box {
+                fill: #1133ff;
             }
             svg {
                 position: absolute;
@@ -66,8 +63,8 @@
         </style>
     </head>
     <body>
-        <svg viewbox="0, 0, 500, 350">
-            <g class="group arrows" transform="translate(10,0)">
+        <svg viewbox="0, 0, 700, 350">
+            <g class="group arrows" transform="translate(110,0)">
                 <g class="button" id="left"  transform="translate(0,60)">
                     <path class="box" d="M 50,0 L 0,50 L 50,100 L 100,50 Z" />
                     <path class="arrow" d="M 50,10 L 60,20 L 30,50 L 60,80 L 50,90 L 10,50 Z" />
@@ -93,21 +90,46 @@
                 </g>
             </g>
 
-            <g class="group letters" transform="translate(260,0)">
-                <g class="button" id="a"  transform="translate(60,120)">
+            <g class="group shoulders" transform="translate(100, 0)">
+                <g class="button" id="l"  transform="translate(-100,0)">
+                    <rect class="box" x="1" y="30" width="98" height="40" rx="15" ry="15"/>
+                    <text x="50" y="50" dy="7">L</text>
+                    <rect class="hitbox" x="1" y="30" width="98" height="40" rx="15" ry="15"/>
+                </g>
+                <g class="button" id="r"  transform="translate(500,0)">
+                    <rect class="box" x="1" y="30" width="98" height="40" rx="15" ry="15"/>
+                    <text x="50" y="50" dy="7">R</text>
+                    <rect class="hitbox" x="1" y="30" width="98" height="40" rx="15" ry="15"/>
+                </g>
+            </g>
+
+            <g class="group letters" transform="translate(360,0)">
+                <g class="button" id="a"  transform="translate(120,60)">
                     <circle class="box" r="35" cx="50" cy="50"/>
                     <text x="50" y="50" dy="7">A</text>
                     <circle class="hitbox" r="35" cx="50" cy="50"/>
                 </g>
 
-                <g class="button" id="b"  transform="translate(120,60)">
+                <g class="button" id="b"  transform="translate(60,120)">
                     <circle class="box" r="35" cx="50" cy="50"/>
                     <text x="50" y="50" dy="7">B</text>
                     <circle class="hitbox" r="35" cx="50" cy="50"/>
                 </g>
+
+                <g class="button" id="y"  transform="translate(0,60)">
+                    <circle class="box" r="35" cx="50" cy="50"/>
+                    <text x="50" y="50" dy="7">Y</text>
+                    <circle class="hitbox" r="35" cx="50" cy="50"/>
+                </g>
+
+                <g class="button" id="x"  transform="translate(60,0)">
+                    <circle class="box" r="35" cx="50" cy="50"/>
+                    <text x="50" y="50" dy="7">X</text>
+                    <circle class="hitbox" r="35" cx="50" cy="50"/>
+                </g>
             </g>
 
-            <g class="group commands" transform="translate(135,250)">
+            <g class="group commands" transform="translate(235,250)">
                 <g class="button" id="select"  transform="translate(0,0)">
                     <rect class="box" x="1" y="30" width="98" height="40" rx="25" ry="25"/>
                     <text x="50" y="50" dy="7">SELECT</text>
@@ -127,6 +149,10 @@
                 keys = [
                     "a",
                     "b",
+                    "y",
+                    "x",
+                    "l",
+                    "r",
                     "left",
                     "right",
                     "up",
diff --git a/scripts/xscrp.sh b/scripts/xscrp.sh
index 0c2db0b..d7abcfc 100755
--- a/scripts/xscrp.sh
+++ b/scripts/xscrp.sh
@@ -1,7 +1,7 @@
 #!/bin/bash
 
 WID=`xdotool search --name RetroArch`
-VALID="_z__x__q__w__Left__Right__Up__Down__Shift_R__Return_"
+VALID="_z__x__q__w__s__a__Left__Right__Up__Down__Shift_R__Return_"
 if [[ $WID == "" ]]
 then
     echo 1
@@ -11,6 +11,8 @@ else
         xdotool windowactivate $WID
         xdotool windowfocus $WID
         xdotool keydown $1
+        sleep 0.25 # Platformers
+        #sleep 0.01 # Tetris
         xdotool keyup $1
         echo 0
     else
-- 
GitLab