play audio with block state
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2024-08-02 17:08:39 -04:00
parent 02c23d6e28
commit 859670d3b6
6 changed files with 75 additions and 22 deletions

View File

@ -290,6 +290,9 @@
"priorityCategory": "MOVEMENT_MODIFIER", "priorityCategory": "MOVEMENT_MODIFIER",
"boneGroups" : ["armLeft", "armRight", "handLeft", "handRight"] "boneGroups" : ["armLeft", "armRight", "handLeft", "handRight"]
}, },
"mainAudio" : {
"audioPath" : "Audio/weapons/swordUnsheath1.ogg"
},
"defaults" : [ "defaults" : [
{ {
"equipPoint" : "handRight", "equipPoint" : "handRight",

View File

@ -462,12 +462,18 @@ public class Globals {
* Inits default audio resources * Inits default audio resources
*/ */
public static void initDefaultAudioResources(){ public static void initDefaultAudioResources(){
String[] audioToInit = new String[]{
"/Audio/inventoryGrabItem.ogg",
"/Audio/inventorySlotItem.ogg",
"/Audio/openMenu.ogg",
"/Audio/closeMenu.ogg",
"/Audio/ambienceWind1SeamlessMono.ogg",
"/Audio/weapons/swordUnsheath1.ogg",
};
LoggerInterface.loggerStartup.INFO("Loading default audio resources"); LoggerInterface.loggerStartup.INFO("Loading default audio resources");
Globals.assetManager.addAudioPathToQueue("/Audio/inventoryGrabItem.ogg"); for(String path : audioToInit){
Globals.assetManager.addAudioPathToQueue("/Audio/inventorySlotItem.ogg"); Globals.assetManager.addAudioPathToQueue(path);
Globals.assetManager.addAudioPathToQueue("/Audio/openMenu.ogg"); }
Globals.assetManager.addAudioPathToQueue("/Audio/closeMenu.ogg");
Globals.assetManager.addAudioPathToQueue("/Audio/ambienceWind1SeamlessMono.ogg");
Globals.assetManager.loadAssetsInQueue(); Globals.assetManager.loadAssetsInQueue();
} }

View File

@ -346,17 +346,19 @@ public class AssetManager {
// //
public void addAudioPathToQueue(String path){ public void addAudioPathToQueue(String path){
if(!audioInQueue.contains(path) && !audioLoadedIntoMemory.containsKey(path)){ String sanitizedPath = FileUtils.sanitizeFilePath(path);
audioInQueue.add(path); if(!audioInQueue.contains(sanitizedPath) && !audioLoadedIntoMemory.containsKey(sanitizedPath)){
audioInQueue.add(sanitizedPath);
} }
} }
public AudioBuffer fetchAudio(String path){ public AudioBuffer fetchAudio(String path){
AudioBuffer rVal = null; AudioBuffer rVal = null;
if(audioLoadedIntoMemory.containsKey(path)){ String sanitizedPath = FileUtils.sanitizeFilePath(path);
rVal = audioLoadedIntoMemory.get(path); if(audioLoadedIntoMemory.containsKey(sanitizedPath)){
rVal = audioLoadedIntoMemory.get(sanitizedPath);
} else { } else {
LoggerInterface.loggerAudio.WARNING("Failed to find audio " + path); LoggerInterface.loggerAudio.WARNING("Failed to find audio " + sanitizedPath);
} }
return rVal; return rVal;
} }

View File

@ -109,6 +109,11 @@ public class StateTransitionUtil {
animation = state.getAnimation.get(); animation = state.getAnimation.get();
} }
TreeDataAudio audioData = state.audioData;
if(state.getAudio != null && state.getAudio.get() != null){
audioData = state.getAudio.get();
}
// //
//Play main animation //Play main animation
@ -122,13 +127,13 @@ public class StateTransitionUtil {
if(parent == Globals.playerEntity && !Globals.controlHandler.cameraIsThirdPerson() && animation != null){ if(parent == Globals.playerEntity && !Globals.controlHandler.cameraIsThirdPerson() && animation != null){
//first person //first person
//play first person audio //play first person audio
if(state.audioData != null && state.audioData.getAudioPath() != null){ if(audioData != null && audioData.getAudioPath() != null){
Globals.virtualAudioSourceManager.createVirtualAudioSource(state.audioData.getAudioPath(), VirtualAudioSourceType.CREATURE, false); Globals.virtualAudioSourceManager.createVirtualAudioSource(audioData.getAudioPath(), VirtualAudioSourceType.CREATURE, false);
} }
} else { } else {
//play third person audio //play third person audio
if(state.audioData != null && state.audioData.getAudioPath() != null){ if(audioData != null && audioData.getAudioPath() != null){
Globals.virtualAudioSourceManager.createVirtualAudioSource(state.audioData.getAudioPath(), VirtualAudioSourceType.CREATURE, false, EntityUtils.getPosition(parent)); Globals.virtualAudioSourceManager.createVirtualAudioSource(audioData.getAudioPath(), VirtualAudioSourceType.CREATURE, false, EntityUtils.getPosition(parent));
} }
} }
@ -289,6 +294,9 @@ public class StateTransitionUtil {
//The audio data //The audio data
TreeDataAudio audioData; TreeDataAudio audioData;
//Gets the audio to play
Supplier<TreeDataAudio> getAudio;
//The function to fire on completion (ie to transition to the next state) //The function to fire on completion (ie to transition to the next state)
Runnable onComplete; Runnable onComplete;
@ -331,12 +339,12 @@ public class StateTransitionUtil {
private StateTransitionUtilItem( private StateTransitionUtilItem(
Object stateEnum, Object stateEnum,
Supplier<TreeDataAnimation> getAnimation, Supplier<TreeDataAnimation> getAnimation,
TreeDataAudio audioData, Supplier<TreeDataAudio> getAudio,
Runnable onComplete Runnable onComplete
){ ){
this.stateEnum = stateEnum; this.stateEnum = stateEnum;
this.getAnimation = getAnimation; this.getAnimation = getAnimation;
this.audioData = audioData; this.getAudio = getAudio;
this.onComplete = onComplete; this.onComplete = onComplete;
} }
@ -346,19 +354,19 @@ public class StateTransitionUtil {
* The intended usecase is if the animation could change based on some state in the tree. * The intended usecase is if the animation could change based on some state in the tree.
* @param stateEnum The enum value for this state * @param stateEnum The enum value for this state
* @param getAnimationData The supplier for the animation data. If it is null, it will not play any animation * @param getAnimationData The supplier for the animation data. If it is null, it will not play any animation
* @param audioData The path to an audio file to play on starting the animation. If null, no audio will be played * @param getAudio The supplier for path to an audio file to play on starting the animation. If null, no audio will be played
* @param onComplete !!Must transition to the next state!! Fires when the animation completes. If not supplied, animations and autio will loop * @param onComplete !!Must transition to the next state!! Fires when the animation completes. If not supplied, animations and autio will loop
*/ */
public static StateTransitionUtilItem create( public static StateTransitionUtilItem create(
Object stateEnum, Object stateEnum,
Supplier<TreeDataAnimation> getAnimation, Supplier<TreeDataAnimation> getAnimation,
TreeDataAudio audioData, Supplier<TreeDataAudio> getAudio,
Runnable onComplete Runnable onComplete
){ ){
return new StateTransitionUtilItem( return new StateTransitionUtilItem(
stateEnum, stateEnum,
getAnimation, getAnimation,
audioData, getAudio,
onComplete onComplete
); );
} }

View File

@ -56,19 +56,19 @@ public class ClientBlockTree implements BehaviorTree {
StateTransitionUtilItem.create( StateTransitionUtilItem.create(
BlockState.WIND_UP, BlockState.WIND_UP,
() -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getWindUpAnimation();}, () -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getWindUpAnimation();},
null, () -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getWindUpAudio();},
null null
), ),
StateTransitionUtilItem.create( StateTransitionUtilItem.create(
BlockState.BLOCKING, BlockState.BLOCKING,
() -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getMainAnimation();}, () -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getMainAnimation();},
null, () -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getMainAudio();},
null null
), ),
StateTransitionUtilItem.create( StateTransitionUtilItem.create(
BlockState.COOLDOWN, BlockState.COOLDOWN,
() -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getCooldownAnimation();}, () -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getCooldownAnimation();},
null, () -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getCooldownAudio();},
null null
), ),
}); });

View File

@ -3,6 +3,7 @@ package electrosphere.game.data.creature.type.block;
import java.util.List; import java.util.List;
import electrosphere.game.data.common.TreeDataAnimation; import electrosphere.game.data.common.TreeDataAnimation;
import electrosphere.game.data.common.TreeDataAudio;
/** /**
* A variant of data that can be loaded into the block system. Variants are for different types of equip states. * A variant of data that can be loaded into the block system. Variants are for different types of equip states.
@ -17,12 +18,21 @@ public class BlockVariant {
//the animation to play when winding up //the animation to play when winding up
TreeDataAnimation windUpAnimation; TreeDataAnimation windUpAnimation;
//the audio to play when winding up
TreeDataAudio windUpAudio;
//the main animation to play while blocking //the main animation to play while blocking
TreeDataAnimation mainAnimation; TreeDataAnimation mainAnimation;
//the main audio to play while blocking
TreeDataAudio mainAudio;
//the animation to play when cooling down //the animation to play when cooling down
TreeDataAnimation cooldownAnimation; TreeDataAnimation cooldownAnimation;
//the audio to play while cooling down
TreeDataAudio cooldownAudio;
//the list of default equipment cases that this variant should be used for //the list of default equipment cases that this variant should be used for
List<VariantDefaults> defaults; List<VariantDefaults> defaults;
@ -42,6 +52,14 @@ public class BlockVariant {
return windUpAnimation; return windUpAnimation;
} }
/**
* Gets the audio to play when winding up
* @return The audio
*/
public TreeDataAudio getWindUpAudio(){
return windUpAudio;
}
/** /**
* The main animation to play while blocking * The main animation to play while blocking
* @return * @return
@ -50,6 +68,14 @@ public class BlockVariant {
return mainAnimation; return mainAnimation;
} }
/**
* Gets the audio to play when blocking
* @return The audio
*/
public TreeDataAudio getMainAudio(){
return mainAudio;
}
/** /**
* The animation to play when cooling down * The animation to play when cooling down
* @return * @return
@ -58,6 +84,14 @@ public class BlockVariant {
return cooldownAnimation; return cooldownAnimation;
} }
/**
* Gets the audio to play when cooling down
* @return The audio
*/
public TreeDataAudio getCooldownAudio(){
return cooldownAudio;
}
/** /**
* the list of default equipment cases that this variant should be used for * the list of default equipment cases that this variant should be used for
* @return * @return