From d629f61b33b4f6ddfc2fff1336a1920df8c981d6 Mon Sep 17 00:00:00 2001 From: Mario Carneiro Date: Wed, 28 Feb 2024 04:38:59 -0500 Subject: [PATCH 1/2] left-handed mode for OneSaber --- src/components/beat-generator.js | 19 +++++++++++++------ src/scene.html | 2 +- src/state/index.js | 10 ++++++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/components/beat-generator.js b/src/components/beat-generator.js index dc15f72ea..e5c9d4164 100644 --- a/src/components/beat-generator.js +++ b/src/components/beat-generator.js @@ -25,6 +25,7 @@ AFRAME.registerComponent('beat-generator', { schema: { challengeId: { type: 'string' }, // If clicked play. gameMode: { type: 'string' }, // classic, punch, ride. + leftHandedMode: { default: false }, difficulty: { type: 'string' }, beatmapCharacteristic: { type: 'string' }, has3DOFVR: { default: false }, @@ -252,9 +253,9 @@ AFRAME.registerComponent('beat-generator', { let color; let type = noteInfo._cutDirection === 8 ? 'dot' : 'arrow'; if (noteInfo._type === 0) { - color = 'red'; + color = data.leftHandedMode ? 'blue' : 'red'; } else if (noteInfo._type === 1) { - color = 'blue'; + color = data.leftHandedMode ? 'red' : 'blue'; } else { type = 'mine'; color = undefined; @@ -286,7 +287,10 @@ AFRAME.registerComponent('beat-generator', { // Apply sword offset. Blocks arrive on beat in front of the user. const cutDirection = this.orientationsHumanized[noteInfo._cutDirection]; - const horizontalPosition = this.horizontalPositionsHumanized[noteInfo._lineIndex] || 'left'; + let lineIndex = noteInfo._lineIndex; + // mirror notes in OneSaber left handed mode + if (data.leftHandedMode) lineIndex = 3 - lineIndex; + const horizontalPosition = this.horizontalPositionsHumanized[lineIndex] || 'left'; const verticalPosition = this.verticalPositionsHumanized[noteInfo._lineLayer] || 'middle'; // Factor in sword offset and beat anticipation time (percentage). @@ -336,7 +340,10 @@ AFRAME.registerComponent('beat-generator', { if (data.has3DOFVR && data.gameMode !== 'viewer') { return; } const durationSeconds = 60 * (wallInfo._duration / this.bpm); - const horizontalPosition = this.horizontalPositionsHumanized[wallInfo._lineIndex] || 'none'; + let lineIndex = wallInfo._lineIndex; + // mirror obstacles in OneSaber left handed mode + if (data.leftHandedMode) lineIndex = 3 - lineIndex; + const horizontalPosition = this.horizontalPositionsHumanized[lineIndex] || 'none';; const isCeiling = wallInfo._type === 1; const length = durationSeconds * data.speed; const width = wallInfo._width / 2; // We want half the reported width. @@ -385,10 +392,10 @@ AFRAME.registerComponent('beat-generator', { this.tube.emit('pulse', null, false); break; case 12: - this.stageColors.setColor('leftglow', event._value); + this.stageColors.setColor(this.data.leftHandedMode ? 'rightglow' : 'leftglow', event._value); break; case 13: - this.stageColors.setColor('rightglow', event._value); + this.stageColors.setColor(this.data.leftHandedMode ? 'leftglow' : 'rightglow', event._value); break; } }, diff --git a/src/scene.html b/src/scene.html index 42f0818e7..462a32123 100644 --- a/src/scene.html +++ b/src/scene.html @@ -5,7 +5,7 @@ {% set firekey = true and 'AIzaSyAilakXLvMgwPcBcHs3oys51eLp4yrfz0w' or 'AIzaSyALCaDKg0b7aD3nOyRv_f5RTZ1vedrGyWw' %} { resetScore(state); + setLeftHandedMode(state); state.challenge.isBeatsPreloaded = false; state.isGameOver = false; state.isPaused = false; @@ -624,6 +626,8 @@ AFRAME.registerState({ // Set challenge. Object.assign(state.challenge, state.menuSelectedChallenge); + setLeftHandedMode(state); + gtag('event', 'difficulty', { event_label: state.challenge.difficulty }); // Reset menu. @@ -954,6 +958,12 @@ function resetScore(state) { state.score.score = 0; } +function setLeftHandedMode(state) { + state.challenge.leftHandedMode = + state.challenge.beatmapCharacteristic == 'OneSaber' && + state.activeHand == 'left'; +} + function computeMenuSelectedChallengeIndex(state) { state.menuSelectedChallenge.index = -1; for (let i = 0; i < state.searchResultsPage.length; i++) { From c2e88a4b6ce9477dabbbb4cbe44e7d308151f7d4 Mon Sep 17 00:00:00 2001 From: Mario Carneiro Date: Wed, 28 Feb 2024 08:57:56 -0500 Subject: [PATCH 2/2] disable off-hand in OneSaber mode --- src/components/blade.js | 2 +- src/scene.html | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/components/blade.js b/src/components/blade.js index 9890f0294..928b382f0 100644 --- a/src/components/blade.js +++ b/src/components/blade.js @@ -89,7 +89,7 @@ AFRAME.registerComponent('blade', { const RIGHT = 'right'; return function (beat) { - if (this.strokeSpeed < 1) { return false; } + if (!this.data.enabled || this.strokeSpeed < 1) { return false; } // Convert points to beat space. for (let i = 0; i < 3; i++) { diff --git a/src/scene.html b/src/scene.html index 462a32123..df15b0037 100644 --- a/src/scene.html +++ b/src/scene.html @@ -154,19 +154,21 @@ id="controllerRig" proxy-event="event: recentered; to: #cameraRig; captureBubbles: true; as: recenter"> {% macro weapon (hand, otherHand) %} + {% set active = "(challenge.beatmapCharacteristic != 'OneSaber' || " + ("!" if hand != "left") + "challenge.leftHandedMode)" %} @@ -225,7 +227,7 @@ id="{{ hand }}punch" class="punch" render-order="weapon" - bind__visible="isPlaying && gameMode === 'punch'" + bind__visible="isPlaying && gameMode === 'punch' && {{ active }}" bind__position="has3DOFVR && '0 0 -0.75' || '0 0 0'" rotation="0 0 0"> + bind__visible="isPlaying && gameMode === 'ride' && {{ active }}">