diff --git a/package.json b/package.json index e3592d1..ee28ffe 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "aframe-orbit-controls": "^1.2.0", "aframe-proxy-event-component": "^2.1.0", "aframe-slice9-component": "^1.0.0", - "aframe-state-component": "^6.1.0", + "aframe-state-component": "^6.2.0", "aframe-super-keyboard": "2.0.2", "aframe-thumb-controls-component": "^1.1.0", "algoliasearch": "^3.29.0", diff --git a/src/components/copy-texture.js b/src/components/copy-texture.js new file mode 100644 index 0000000..6c6e368 --- /dev/null +++ b/src/components/copy-texture.js @@ -0,0 +1,29 @@ +AFRAME.registerComponent('copy-texture', { + dependencies: ['geometry', 'material'], + + schema: { + from: {type: 'selector'} + }, + + init: function () { + const data = this.data; + + data.from.addEventListener('materialtextureloaded', () => { this.copyTexture(); }); + this.copyTexture(); + }, + + copyTexture: function () { + const el = this.el; + const target = this.data.from; + const material = el.getObject3D('mesh').material; + + if (!target.getObject3D('mesh')) { return; } + + material.map = target.getObject3D('mesh').material.map; + + if (!material.map) { return; } + + material.map.needsUpdate = true; + material.needsUpdate = true; + } +}); diff --git a/src/components/menu-selected-challenge-image.js b/src/components/menu-selected-challenge-image.js index be301f9..df6c011 100644 --- a/src/components/menu-selected-challenge-image.js +++ b/src/components/menu-selected-challenge-image.js @@ -1,27 +1,13 @@ -/** - * Reuse images from the search result. - */ AFRAME.registerComponent('menu-selected-challenge-image', { - dependencies: ['geometry', 'material'], - schema: { - selectedChallengeIndex: {type: 'number'} - }, - - init: function () { - const el = this.el; - this.searchThumbnails = document.getElementById('searchThumbnailImages'); - el.getObject3D('mesh').material.map = this.searchThumbnails.getObject3D('mesh').material.map; - el.getObject3D('mesh').material.needsUpdate = true; + selectedChallengeId: {type: 'string'} }, update: function () { - const data = this.data; const el = this.el; - - if (data.selectedChallengeIndex === -1 || data.selectedChallengeIndex === '') { return; } - - // Update UVs. - el.setAttribute('atlas-uvs', 'row', data.selectedChallengeIndex + 1); + if (!this.data.selectedChallengeId) { return; } + el.setAttribute( + 'material', 'src', + `https://s3-us-west-2.amazonaws.com/supersaber/${this.data.selectedChallengeId}-image.jpg`); } }); diff --git a/src/components/search-thumbnail-atlas.js b/src/components/search-thumbnail-atlas.js index cdb957a..111cf2e 100644 --- a/src/components/search-thumbnail-atlas.js +++ b/src/components/search-thumbnail-atlas.js @@ -23,10 +23,9 @@ AFRAME.registerComponent('search-thumbnail-atlas', { this.ctx = canvas.getContext('2d'); this.clearCanvas(); - document.body.appendChild(canvas); - this.el.setAttribute('material', 'src', canvas); + this.el.setAttribute('material', 'src', canvas); this.images = []; }, @@ -34,8 +33,6 @@ AFRAME.registerComponent('search-thumbnail-atlas', { var el = this.el; var data = this.data; - this.clearCanvas(); - const results = el.sceneEl.systems.state.state.searchResultsPage; for (let i = 0; i < results.length; i++) { let img = this.images[i] = this.images[i] || document.createElement('img'); diff --git a/src/state/index.js b/src/state/index.js index a8b28c1..913e3ee 100644 --- a/src/state/index.js +++ b/src/state/index.js @@ -243,6 +243,7 @@ function computeSearchPagination (state) { state.search.songSubNameTexts = ''; state.searchResultsPage.length = 0; + state.searchResultsPage.__dirty = true; for (i = state.search.page * SEARCH_PER_PAGE; i < state.search.page * SEARCH_PER_PAGE + SEARCH_PER_PAGE; i++) { if (!state.search.results[i]) { break; } diff --git a/src/templates/dialogs.html b/src/templates/dialogs.html index 77b33e4..bfb3763 100644 --- a/src/templates/dialogs.html +++ b/src/templates/dialogs.html @@ -42,12 +42,13 @@ + + diff --git a/src/templates/menu.html b/src/templates/menu.html index 092d918..a0f3348 100644 --- a/src/templates/menu.html +++ b/src/templates/menu.html @@ -25,6 +25,7 @@