Skip to content

Commit

Permalink
left-handed mode for OneSaber
Browse files Browse the repository at this point in the history
  • Loading branch information
digama0 committed Feb 28, 2024
1 parent 8456119 commit 2434f38
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
19 changes: 13 additions & 6 deletions src/components/beat-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/scene.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% set firekey = true and 'AIzaSyAilakXLvMgwPcBcHs3oys51eLp4yrfz0w' or 'AIzaSyALCaDKg0b7aD3nOyRv_f5RTZ1vedrGyWw' %}

<a-scene
bind__beat-generator="challengeId: challenge.id; difficulty: challenge.difficulty; beatmapCharacteristic: challenge.beatmapCharacteristic; gameMode: gameMode; has3DOFVR: has3DOFVR; hasSongLoadError: hasSongLoadError; isPlaying: isPlaying; isZipFetching: isZipFetching; menuSelectedChallengeId: menuSelectedChallenge.id; songDuration: challenge.metadata.duration; speed: speed"
bind__beat-generator="challengeId: challenge.id; difficulty: challenge.difficulty; beatmapCharacteristic: challenge.beatmapCharacteristic; gameMode: gameMode; leftHandedMode: challenge.leftHandedMode; has3DOFVR: has3DOFVR; hasSongLoadError: hasSongLoadError; isPlaying: isPlaying; isZipFetching: isZipFetching; menuSelectedChallengeId: menuSelectedChallenge.id; songDuration: challenge.metadata.duration; speed: speed"
bind__beat-system="gameMode: gameMode; hasVR: hasVR; isLoading: isLoading; isPlaying: isPlaying"
bind__gameover="isGameOver: isGameOver"
bind__intro-song="isPlaying: menuActive && !menuSelectedChallenge.id; isSearching: isSearching"
Expand Down
11 changes: 11 additions & 0 deletions src/state/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ AFRAME.registerState({
id: AFRAME.utils.getUrlParameter('challenge'), // Will be empty string if not playing.
image: '',
isBeatsPreloaded: false, // Whether we have passed the negative time.
leftHandedMode: false,
numBeats: undefined,
songDuration: 0,
songName: '',
Expand Down Expand Up @@ -374,6 +375,7 @@ AFRAME.registerState({

gamemenurestart: state => {
resetScore(state);
setLeftHandedMode(state);
state.challenge.isBeatsPreloaded = false;
state.isGameOver = false;
state.isPaused = false;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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++) {
Expand Down

0 comments on commit 2434f38

Please sign in to comment.