# Conflicts:
#	index.html
#	js/gamepad.js
This commit is contained in:
e7d 2017-05-09 23:26:10 +02:00
commit d99b4801d0
3 changed files with 15 additions and 14 deletions

View File

@ -14,7 +14,7 @@ body {
} }
.no-gamepad { .no-gamepad {
position: absolute; position: absolute;
bottom: 0; top: 20px;
display: none; display: none;
width: 100vw; width: 100vw;
line-height: 2em; line-height: 2em;

View File

@ -8,12 +8,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/png" href="favicon.png"> <link rel="icon" type="image/png" href="favicon.png">
<link rel="stylesheet" href="css/normalize.css?ef81677"> <link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/main.css?ef81677"> <link rel="stylesheet" href="css/main.css">
</head> </head>
<body> <body>
<div class="debug">Debug</div> <div class="debug">Debug</div>
<div class="no-gamepad">No active gamepad. Press <kbd>H</kbd> to see how it works.</div> <div class="no-gamepad">No active gamepad detected. Press <kbd>H</kbd> to read instructions.</div>
<div class="gamepad"></div> <div class="gamepad"></div>
<div class="help"> <div class="help">
<h2>Help</h2> <h2>Help</h2>
@ -63,6 +63,6 @@
</div> </div>
<script src="https://static.e7d.io/libs/jquery/3.1.1/jquery.min.js"></script> <script src="https://static.e7d.io/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="js/gamepad.js?ef81677"></script> <script src="js/gamepad.js"></script>
</body> </body>
</html> </html>

View File

@ -1,4 +1,4 @@
// (function(window, document, undefined) { (function(window, document, undefined) {
$.urlParam = function(name) { $.urlParam = function(name) {
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href); var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (results === null) { if (results === null) {
@ -10,6 +10,7 @@
var haveEvents = 'ongamepadconnected' in window; var haveEvents = 'ongamepadconnected' in window;
var debug = false; var debug = false;
var scanGamepadsDelay = 1000;
var gamepads = {}; var gamepads = {};
var $gamepad = $('.gamepad'); var $gamepad = $('.gamepad');
var $nogamepad = $('.no-gamepad'); var $nogamepad = $('.no-gamepad');
@ -17,20 +18,20 @@
var $help = $('.help'); var $help = $('.help');
var gamepadIdentifiers = { var gamepadIdentifiers = {
'debug': { 'debug': {
'id': /xinput|XInput/, 'id': /debug/,
'colors': [] 'colors': []
}, },
'ds4': { 'ds4': {
'id': /054c.*?05c4/, 'id': /054c.*?05c4/,
'colors': ['black', 'white', 'red', 'blue'] 'colors': ['black', 'white', 'red', 'blue']
}, },
// 'xbox-one': { 'xbox-one': {
// 'id': /xinput|XInput/, 'id': /xinput|XInput/,
// 'colors': ['black', 'white'] 'colors': ['black', 'white']
// } }
}; };
var gamepadHelpTimeout = null; var gamepadHelpTimeout = null;
var gamepadHelpDelay = 10000; var gamepadHelpDelay = 5000;
var activeGamepadIndex = null; var activeGamepadIndex = null;
var activeGamepadType = null; var activeGamepadType = null;
var activeGamepadIdentifier = null; var activeGamepadIdentifier = null;
@ -113,7 +114,7 @@
displayGamepadHelp(); displayGamepadHelp();
} }
setInterval(scanGamepads, 500); setInterval(scanGamepads, scanGamepadsDelay);
function scanGamepads() { function scanGamepads() {
if (null !== activeGamepadIndex) { if (null !== activeGamepadIndex) {
return; return;
@ -319,4 +320,4 @@
$debug[debug ? 'fadeIn' : 'fadeOut'](); $debug[debug ? 'fadeIn' : 'fadeOut']();
} }
// })(window, document); })(window, document);