From 2434f38c3dbbc906aded81fa2459544594828d69 Mon Sep 17 00:00:00 2001 From: Mario Carneiro Date: Wed, 28 Feb 2024 04:38:59 -0500 Subject: [PATCH] left-handed mode for OneSaber --- src/components/beat-generator.js | 19 +++++++++++++------ src/scene.html | 2 +- src/state/index.js | 11 +++++++++++ 3 files changed, 25 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,13 @@ function resetScore(state) { state.score.score = 0; } +function setLeftHandedMode(state) { + state.challenge.leftHandedMode = + state.challenge.beatmapCharacteristic == 'OneSaber' && + state.activeHand == 'left'; + debugLog(state, `setLeftHandedMode(${state.challenge.beatmapCharacteristic}, ${state.activeHand})`); +} + function computeMenuSelectedChallengeIndex(state) { state.menuSelectedChallenge.index = -1; for (let i = 0; i < state.searchResultsPage.length; i++) {