-
Notifications
You must be signed in to change notification settings - Fork 210
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
equip sound + sword grunt + sword sound #3674
Changes from 9 commits
2679653
eeb49e1
2704bdb
24c08f1
3fabd68
2e6e2f3
e6de4c2
5f8199a
d8d6a68
9954dfb
9af4f04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,16 @@ const freestyleOffset = 900 / 2; | |
const breaststrokeDuration = 1066.6666666666666; | ||
const breaststrokeOffset = 433.3333333333333; | ||
|
||
const aimAnimations = { | ||
swordSideIdle: 'sword_idle_side.fbx', | ||
swordSideIdleStatic: 'sword_idle_side_static.fbx', | ||
swordSideSlash: 'sword_side_slash.fbx', | ||
swordSideSlashStep: 'sword_side_slash_step.fbx', | ||
swordTopDownSlash: 'sword_topdown_slash.fbx', | ||
swordTopDownSlashStep: 'sword_topdown_slash_step.fbx', | ||
swordUndraw: 'sword_undraw.fbx', | ||
}; | ||
|
||
|
||
// HACK: this is used to dynamically control the step offset for a particular animation | ||
// it is useful during development to adjust sync between animations and sound | ||
|
@@ -62,22 +72,29 @@ const _getActionFrameIndex = (f, frameTimes) => { | |
return i; | ||
}; | ||
|
||
class CharacterSfx { | ||
class CharacterSfx extends EventTarget{ | ||
constructor(player) { | ||
super(); | ||
this.player = player; | ||
|
||
this.lastJumpState = false; | ||
this.lastStepped = [false, false]; | ||
this.lastWalkTime = 0; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bad spacing. |
||
|
||
|
||
this.lastSwordComboName = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are now so many random state keys on this class that it needs to be broken up further. |
||
this.swordComboStartTime = 0; | ||
|
||
this.lastEatFrameIndex = -1; | ||
this.lastDrinkFrameIndex = -1; | ||
|
||
this.narutoRunStartTime = 0; | ||
this.narutoRunFinishTime = 0; | ||
this.narutoRunTrailSoundStartTime = 0; | ||
this.narutoRunTurnSoundStartTime = 0; | ||
this.currentQ=new THREE.Quaternion(); | ||
this.preQ=new THREE.Quaternion(); | ||
this.currentQ = new THREE.Quaternion(); | ||
this.preQ = new THREE.Quaternion(); | ||
this.arr = [0, 0, 0, 0]; | ||
|
||
this.startRunningTime = 0; | ||
|
@@ -86,21 +103,12 @@ class CharacterSfx { | |
this.oldNarutoRunSound = null; | ||
this.lastEmote = null; | ||
|
||
if (this.player.isLocalPlayer) { | ||
const wearupdate = e => { | ||
sounds.playSoundName(e.wear ? 'itemEquip' : 'itemUnequip'); | ||
}; | ||
player.addEventListener('wearupdate', wearupdate); | ||
this.cleanup = () => { | ||
player.removeEventListener('wearupdate', wearupdate); | ||
}; | ||
} | ||
|
||
this.currentStep = null; | ||
this.currentSwimmingHand = null; | ||
this.setSwimmingHand = true; | ||
|
||
this.lastLandState = false; | ||
|
||
} | ||
update(timestamp, timeDiffS) { | ||
if (!this.player.avatar) { | ||
|
@@ -227,6 +235,7 @@ class CharacterSfx { | |
if (!this.player.hasAction('sit')) { | ||
_handleStep(); | ||
} | ||
|
||
const _handleSwim = () => { | ||
if(this.player.hasAction('swim')){ | ||
// const candidateAudios = soundFiles.water; | ||
|
@@ -342,8 +351,49 @@ class CharacterSfx { | |
|
||
}; | ||
_handleNarutoRun(); | ||
|
||
|
||
// combo | ||
const dispatchComboSoundEvent = (soundIndex) =>{ | ||
this.dispatchEvent(new MessageEvent('meleewhoosh', { | ||
data: { | ||
index: soundIndex | ||
}, | ||
})); | ||
} | ||
const _handleCombo = () => { | ||
if (this.player.hasAction('use') && this.player.getAction('use').behavior === 'sword' && this.player.getAction('use').animationCombo) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why look it up 3 times per There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
const comboAnimationName = aimAnimations[this.player.getAction('use').animationCombo[this.player.avatar.useAnimationIndex]]; | ||
if (comboAnimationName && comboAnimationName !== this.lastSwordComboName) { | ||
this.swordComboStartTime = timeSeconds; | ||
this.alreadyPlayComboSound = false; | ||
} | ||
if (comboAnimationName) { | ||
const animations = Avatar.getAnimations(); | ||
const animation = animations.find(a => a.name === comboAnimationName); | ||
const animationComboIndices = Avatar.getanimationComboIndices(); | ||
const animationIndices = animationComboIndices.find(i => i.name === comboAnimationName); | ||
const handDeltas = this.player.getAction('use').boneAttachment === 'leftHand' ? animationIndices.rightHandDeltas : animationIndices.leftHandDeltas; | ||
const maxDeltaIndex = this.player.getAction('use').boneAttachment === 'leftHand' ? animationIndices.maxRightDeltaIndex : animationIndices.maxLeftDeltaIndex; | ||
|
||
const ratio = (timeSeconds - this.swordComboStartTime) / animation.duration; | ||
if (ratio <= 1 && !this.alreadyPlayComboSound) { | ||
const index = Math.floor(ratio * handDeltas.length); | ||
if (index > maxDeltaIndex) { | ||
this.alreadyPlayComboSound = true; | ||
this.playGrunt('attack'); | ||
const soundIndex = this.player.avatar.useAnimationIndex * 4 + Math.floor(Math.random() * 4); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
dispatchComboSoundEvent(soundIndex); | ||
|
||
} | ||
} | ||
} | ||
this.lastSwordComboName = comboAnimationName; | ||
} | ||
|
||
}; | ||
|
||
_handleCombo(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is poor quality unstructured code. The rest of the file has the exact same problem of being random unstructured IMO this file needs a complete redesign under some sort of structured coding theory before anyone can review it. |
||
|
||
const _handleGasp = () =>{ | ||
const isRunning = currentSpeed > 0.5; | ||
if(isRunning){ | ||
|
@@ -459,12 +509,12 @@ class CharacterSfx { | |
} | ||
} | ||
|
||
if(index===undefined){ | ||
if (index === undefined) { | ||
let voice = selectVoice(voiceFiles); | ||
duration = voice.duration; | ||
offset = voice.offset; | ||
} | ||
else{ | ||
else { | ||
duration = voiceFiles[index].duration; | ||
offset = voiceFiles[index].offset; | ||
} | ||
|
@@ -480,7 +530,7 @@ class CharacterSfx { | |
audioBufferSourceNode.connect(this.player.avatar.getAudioInput()); | ||
|
||
// if the oldGrunt are still playing | ||
if(this.oldGrunt){ | ||
if (this.oldGrunt) { | ||
this.oldGrunt.stop(); | ||
this.oldGrunt = null; | ||
} | ||
|
@@ -546,12 +596,12 @@ class CharacterSfx { | |
} | ||
} | ||
|
||
if(index===undefined){ | ||
if (index === undefined) { | ||
let voice = selectVoice(voiceFiles); | ||
duration = voice.duration; | ||
offset = voice.offset; | ||
} | ||
else{ | ||
else { | ||
duration = voiceFiles[index].duration; | ||
offset = voiceFiles[index].offset; | ||
} | ||
|
@@ -567,7 +617,7 @@ class CharacterSfx { | |
audioBufferSourceNode.connect(this.player.avatar.getAudioInput()); | ||
|
||
// if the oldGrunt are still playing | ||
if(this.oldGrunt){ | ||
if (this.oldGrunt) { | ||
this.oldGrunt.stop(); | ||
this.oldGrunt = null; | ||
} | ||
|
@@ -590,4 +640,4 @@ class CharacterSfx { | |
|
||
export { | ||
CharacterSfx, | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is completely unabstracted and unreadable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no comments or functions here, so it's not clear what this is supposed to do or why it would be correct.