From 635f5515168fca117f155d864b0bc64a595ad3e0 Mon Sep 17 00:00:00 2001 From: Kevin Ngo Date: Sat, 21 Jul 2018 23:00:19 +0200 Subject: [PATCH] difficulty menu highlight active --- package-lock.json | 12 ++++---- package.json | 4 +-- src/components/menu-difficulty-select.js | 36 ++++++++++++++++++++++-- src/templates/menu.html | 5 ++-- 4 files changed, 44 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index e2ec908..1c3c972 100644 --- a/package-lock.json +++ b/package-lock.json @@ -81,9 +81,9 @@ } }, "aframe-animation-component": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/aframe-animation-component/-/aframe-animation-component-5.0.0.tgz", - "integrity": "sha512-cqQ5o5iK5RvUUxS8e8VZ419Z/7N3eGvKhP6IUypZE2we71O0YuTOkd3DHGuvjoaI8mhqcJQ20lsUEfE8tWNEYA==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/aframe-animation-component/-/aframe-animation-component-5.1.0.tgz", + "integrity": "sha512-8IP5V2TDReAu5RPhg7t1gMidz/FQZMvvEwxw0xDxrgOCPBBlpFd5rGpW06CaJI+7Enu/PpZGIkImjYwto8tT9A==", "requires": { "animejs": "2.2.0" } @@ -148,9 +148,9 @@ "integrity": "sha1-+w+EQdrdHosRzCRRK6eqaS1iK+E=" }, "aframe-state-component": { - "version": "4.4.1", - "resolved": "https://registry.npmjs.org/aframe-state-component/-/aframe-state-component-4.4.1.tgz", - "integrity": "sha512-V3YcjWMGBGZx8QIqs8csk+v+zmyPoIMelj0l+P57spSjPhyF4wivf5/QFRyEhcrwZIrytLZKRodW431tp30LZA==", + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/aframe-state-component/-/aframe-state-component-4.5.0.tgz", + "integrity": "sha512-jo7GG3ILwWW0zvaf8A2/30zLYyiqNJK/pBLZwGa/y6Xo3FWYgDL30stEHJslka4MtQNK7ONWPOA8mfQTwWUDjg==", "requires": { "aframe": "github:aframevr/aframe#2afb6ac191f1a44edbbfe6f0e733380356a9e0c8" } diff --git a/package.json b/package.json index b0f9477..825a679 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "start": "webpack-dev-server --host 0.0.0.0 --progress --colors --hot --inline --port 3000" }, "dependencies": { - "aframe-animation-component": "^5.0.0", + "aframe-animation-component": "^5.1.0", "aframe-animation-timeline-component": "^1.3.1", "aframe-cubemap-component": "^0.1.2", "aframe-event-decorators": "^1.0.2", @@ -18,7 +18,7 @@ "aframe-particle-system-component": "^1.0.11", "aframe-proxy-event-component": "^1.1.1", "aframe-slice9-component": "^1.0.0", - "aframe-state-component": "^4.4.1", + "aframe-state-component": "^4.5.0", "aframe-super-keyboard": "^2.0.0", "algoliasearch": "^3.29.0", "ansi-html": "0.0.7", diff --git a/src/components/menu-difficulty-select.js b/src/components/menu-difficulty-select.js index 17598f8..8235974 100644 --- a/src/components/menu-difficulty-select.js +++ b/src/components/menu-difficulty-select.js @@ -1,5 +1,34 @@ var bindEvent = require('aframe-event-decorators').bindEvent; +/** + * Select difficulty. + */ +AFRAME.registerComponent('menu-difficulty-option', { + dependencies: ['material'], + + schema: { + activeDifficulty: {default: ''} + }, + + init: function () { + this.defaultColor = this.el.getAttribute('material').color; + }, + + update: function () { + var el = this.el; + let optionValue = this.el.closest('[data-bind-for-value]').dataset.bindForValue; + if (optionValue === this.data.activeDifficulty) { + el.setAttribute('animation__mouseenter', 'enabled', false); + el.setAttribute('animation__mouseleave', 'enabled', false); + el.setAttribute('material', 'color', '#4BF'); + } else { + el.setAttribute('material', 'color', this.defaultColor); + el.setAttribute('animation__mouseenter', 'enabled', true); + el.setAttribute('animation__mouseleave', 'enabled', true); + } + }, +}); + /** * Select difficulty. */ @@ -13,8 +42,9 @@ AFRAME.registerComponent('menu-difficulty-select', { }, click: bindEvent(function (evt) { - this.el.emit('menudifficultyselect', - evt.target.closest('.difficultyOption').dataset.difficulty, - false); + this.el.sceneEl.emit( + 'menudifficultyselect', + evt.target.closest('.difficultyOption').dataset.difficulty, + false); }) }); diff --git a/src/templates/menu.html b/src/templates/menu.html index 63b8edd..3a55199 100644 --- a/src/templates/menu.html +++ b/src/templates/menu.html @@ -52,20 +52,21 @@ {% raw %}