diff --git a/css/main.css b/css/main.css index 84b8216..536ec4a 100644 --- a/css/main.css +++ b/css/main.css @@ -90,6 +90,7 @@ body { #help { background: whitesmoke; + color: black; border: 1px solid rgba(0, 0, 0, 0.2); box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5); box-sizing: border-box; diff --git a/index.html b/index.html index 09c647b..18dd600 100644 --- a/index.html +++ b/index.html @@ -137,11 +137,7 @@ H - Display this help - - - O - Start the demo + Toggle this help menu Delete, Escape @@ -152,7 +148,6 @@ - diff --git a/js/demo.js b/js/demo.js deleted file mode 100644 index f1230f3..0000000 --- a/js/demo.js +++ /dev/null @@ -1,218 +0,0 @@ -/** - * The Gamepad demo class - * - * @class Demo - */ -class Demo { - /** - * Creates an instance of Demo. - * - * @param Gamepad gamepad - */ - constructor(gamepad) { - this.gamepad = gamepad; - this.demoGamepad = { - 'id': 'xinput', - 'timestamp': 0, - 'index': 'demo', - 'mapping': 'standard', - 'axes': [], - 'buttons': [], - }; - - for (let axisIndex = 0; axisIndex < 6; axisIndex++) { - this.demoGamepad.axes[axisIndex] = 0; - } - for (let buttonIndex = 0; buttonIndex < 20; buttonIndex++) { - this.demoGamepad.buttons[buttonIndex] = { - pressed: false, - value: 0 - }; - } - } - - /** - * Starts the demonstration mode - * - * @param {string} [mode='random'] - * @param {string} [id='xinput'] - */ - start(mode = 'random', id = 'xinput') { - // add the demo gamepad to the gamepads list - this.gamepad.gamepads['demo'] = this.demoGamepad; - // map the demo gamepad as active gamepad - this.gamepad.map('demo'); - - // determine the callback to use following the demo mode - let callback; - switch (mode) { - case 'random': - callback = this.randomModeCallback; - this.demoUpdateDelay = 100; - break; - case 'realist': - callback = this.realistModeCallback; - this.demoUpdateDelay = false; - break; - case 'sequential': - default: - callback = this.sequentialModeCallback; - this.controlType = 'axis'; - this.controlIndex = 0; - this.demoUpdateDelay = 1000; - break; - } - - // execute the callback once - callback.bind(this)(); - if (this.demoUpdateDelay) { - // setup an repeat callback if needed - this.demoInterval = window.setInterval( - () => { - callback.bind(this)(); - }, - this.demoUpdateDelay - ); - } - } - - /** - * Stops the demonstration mode - */ - stop() { - // stop any running demo callback - window.clearInterval(this.demoInterval); - } - - /** - * Executes the random mode callback - */ - randomModeCallback() { - // set a random value for each axis - for (let axisIndex = 0; axisIndex < this.demoGamepad.axes.length; axisIndex++) { - this.demoGamepad.axes[axisIndex] = (Math.random() * 2) - 1; - } - // set a random value for each button - for (let buttonIndex = 0; buttonIndex < this.demoGamepad.buttons.length; buttonIndex++) { - this.pressButton(buttonIndex, Math.random() > 0.5, Math.random()); - } - } - - /** - * Executes the realistic mode callback - */ - realistModeCallback() { - // TODO: capture a real usage, approx. 10s - } - - /** - * Executes the sequential mode callback - */ - sequentialModeCallback() { - // store the current index locally - const index = this.controlIndex; - - // Axis - if ('axis' === this.controlType) { - // move axis from neutral to maximum, then minimum, then neutral again - for (let i = 0; i <= 1; i = +(i + 0.01).toFixed(2)) { - let value = 0; - if (i > 0.75) { - value = (1 - i) * 4; - } else if (i > 0.25) { - value = (i - 0.5) * 4; - } else { - value = (-i) * 4; - } - - window.setTimeout( - () => { - this.moveAxis( - index, - value - ); - }, - this.demoUpdateDelay * 0.7 * i - ) - } - - // job is done for this axis, move to next axis - this.controlIndex++; - if (this.controlIndex >= this.demoGamepad.axes.length) { - // if all axis where animated, change for buttons - this.controlType = 'button'; - this.controlIndex = 0; - } - - return; - } - - if ('button' === this.controlType) { - // update button pressure from null to maximum, then release again - for (let i = 0; i <= 1; i = +(i + 0.01).toFixed(2)) { - let value = 0; - if (i > 0.5) { - value = (1 - i) * 2; - } else { - value = i * 2; - } - - window.setTimeout( - () => { - this.pressButton( - index, - value > 0, - value - ); - }, - this.demoUpdateDelay * 0.7 * i - ) - } - - // job is done for this axis, move to next button - this.controlIndex++; - if (this.controlIndex >= this.demoGamepad.buttons.length) { - // if all axis where animated, change for axes - this.controlType = 'axis'; - this.controlIndex = 0; - } - - return; - } - } - - /** - * Simulates a button press - * - * @param {any} index - * @param {boolean} [pressed=true] - * @param {number} [value=1] - */ - pressButton(index, pressed = true, value = 1) { - // no pressure means a null value - if (!pressed) { - value = 0; - } - - // update gamepad timestamp - this.demoGamepad.timestamp++; - // update button status - this.demoGamepad.buttons[index] = { - 'pressed': pressed, - 'value': value - }; - } - - /** - * Simulates an axis movement - * - * @param {any} index - * @param {number} [value=1] - */ - moveAxis(index, value = 1) { - // update gamepad timestamp - this.demoGamepad.timestamp++; - // update axis status - this.demoGamepad.axes[index] = value; - } -} diff --git a/js/gamepad.js b/js/gamepad.js index ad2f2c0..11c6a02 100644 --- a/js/gamepad.js +++ b/js/gamepad.js @@ -8,8 +8,6 @@ class Gamepad { * Creates an instance of Gamepad. */ constructor() { - this.demo = new Demo(this); - // cached DOM references this.$body = $("body"); this.$gamepad = $("#gamepad"); @@ -24,6 +22,13 @@ class Gamepad { "lime", "magenta", ]; + this.textColors = [ + "black", + "black", + "white", + "black", + "black", + ]; // gamepad collection default values this.gamepads = {}; @@ -120,12 +125,6 @@ class Gamepad { this.$body.css("background", this.backgroundColors[this.index]); } - // start the demo if requested by params - if (this.params.demo) { - this.demo.start(this.params.demo); - return; - } - // by default, enqueue a delayed display of the help modal this.displayHelp(); } @@ -232,9 +231,6 @@ class Gamepad { case "KeyH": this.toggleHelp(); break; - case "KeyO": - this.demo.start(); - break; case "NumpadAdd": case "Equal": this.changeZoom("+"); @@ -420,11 +416,6 @@ class Gamepad { // ensure we have an index to remove if ("undefined" === typeof index) return; - // ensure to kill demo mode - if ("demo" === this.index) { - this.demo.stop(); - } - // if this is the active gamepad if (true === index || this.index === index) { // clear associated date @@ -590,10 +581,10 @@ class Gamepad { this.backgroundColorIndex = color; } - this.$body.css( - "background", - this.backgroundColors[this.backgroundColorIndex] - ); + this.$body.css({ + background: this.backgroundColors[this.backgroundColorIndex], + color: this.textColors[this.backgroundColorIndex], + }); } /**