Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable off-hand in OneSaber mode #199

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/components/blade.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
20 changes: 11 additions & 9 deletions 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 Expand Up @@ -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)" %}
<a-entity id="{{ hand }}Hand"
class="weapon"
bind__hand-swapper="enabled: {{ otherHand }}RaycasterActive"
bind__haptics-wall="enabled: isPlaying && gameMode === 'classic'"
bind__haptics="enabled: !isPlaying || {{ active }}"
bind__haptics-wall="enabled: isPlaying && gameMode === 'classic' && {{ active }}"
bind__headfist="isPlaying: isPlaying"
bind__menu-controls="enabled: mainMenuActive"
bind__pauser="enabled: isPlaying"
bind__punch="enabled: isPlaying && gameMode === 'punch'"
bind__raycaster="enabled: {{ hand }}RaycasterActive"
bind__raycaster__game="enabled: isPlaying && (gameMode === 'classic' || gameMode === 'punch')"
bind__blade="enabled: isPlaying && gameMode === 'classic'"
bind__weapon-particles="enabled: isPlaying; gameMode: gameMode"
bind__trail="colorScheme: colorScheme; enabled: isPlaying && gameMode === 'classic'"
bind__blade="enabled: isPlaying && gameMode === 'classic' && {{ active }}"
bind__weapon-particles="enabled: isPlaying && {{ active }}; gameMode: gameMode"
bind__trail="colorScheme: colorScheme; enabled: isPlaying && gameMode === 'classic' && {{ active }}"
controller="hand: {{ hand }}"
data-hand="{{ hand }}"
haptics="events: mouseenter; dur: 35; force: 0.075"
Expand Down Expand Up @@ -198,7 +200,7 @@
bind__rotation="controllerType.indexOf('oculus') !== -1 && '135 0 0' || '90 0 0'">
<a-entity
class="bladeContainer"
bind__visible="isPlaying && gameMode === 'classic'"
bind__visible="isPlaying && gameMode === 'classic' && {{ active }}"
animation="property: scale; from: 0 0 0; to: 1 1 1; dur: 750; easing: linear; startEvents: drawblade"
scale="0.001 0.001 0.001">
<a-entity
Expand All @@ -213,7 +215,7 @@

<a-entity
class="bladeHandle"
bind__visible="!isPlaying || gameMode === 'classic'"
bind__visible="!isPlaying || gameMode === 'classic' && {{ active }}"
obj-model="obj: #weaponHandleObj"
materials="name: {{ hand }}WeaponHandle">
<a-entity class="bladeHandleHelper"></a-entity>
Expand All @@ -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">
<a-entity
Expand All @@ -249,7 +251,7 @@
id="{{ hand }}star"
class="handStar"
render-order="weapon"
bind__visible="isPlaying && gameMode === 'ride'">
bind__visible="isPlaying && gameMode === 'ride' && {{ active }}">
<a-entity
class="handStar"
bind__material="colorPrimary: colorPrimary; colorSecondary: colorSecondary; colorTertiary: colorTertiary"
Expand Down
10 changes: 10 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,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++) {
Expand Down