play audio with block state
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
This commit is contained in:
parent
02c23d6e28
commit
859670d3b6
@ -290,6 +290,9 @@
|
||||
"priorityCategory": "MOVEMENT_MODIFIER",
|
||||
"boneGroups" : ["armLeft", "armRight", "handLeft", "handRight"]
|
||||
},
|
||||
"mainAudio" : {
|
||||
"audioPath" : "Audio/weapons/swordUnsheath1.ogg"
|
||||
},
|
||||
"defaults" : [
|
||||
{
|
||||
"equipPoint" : "handRight",
|
||||
|
||||
@ -462,12 +462,18 @@ public class Globals {
|
||||
* Inits default audio resources
|
||||
*/
|
||||
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");
|
||||
Globals.assetManager.addAudioPathToQueue("/Audio/inventoryGrabItem.ogg");
|
||||
Globals.assetManager.addAudioPathToQueue("/Audio/inventorySlotItem.ogg");
|
||||
Globals.assetManager.addAudioPathToQueue("/Audio/openMenu.ogg");
|
||||
Globals.assetManager.addAudioPathToQueue("/Audio/closeMenu.ogg");
|
||||
Globals.assetManager.addAudioPathToQueue("/Audio/ambienceWind1SeamlessMono.ogg");
|
||||
for(String path : audioToInit){
|
||||
Globals.assetManager.addAudioPathToQueue(path);
|
||||
}
|
||||
Globals.assetManager.loadAssetsInQueue();
|
||||
}
|
||||
|
||||
|
||||
@ -346,17 +346,19 @@ public class AssetManager {
|
||||
//
|
||||
|
||||
public void addAudioPathToQueue(String path){
|
||||
if(!audioInQueue.contains(path) && !audioLoadedIntoMemory.containsKey(path)){
|
||||
audioInQueue.add(path);
|
||||
String sanitizedPath = FileUtils.sanitizeFilePath(path);
|
||||
if(!audioInQueue.contains(sanitizedPath) && !audioLoadedIntoMemory.containsKey(sanitizedPath)){
|
||||
audioInQueue.add(sanitizedPath);
|
||||
}
|
||||
}
|
||||
|
||||
public AudioBuffer fetchAudio(String path){
|
||||
AudioBuffer rVal = null;
|
||||
if(audioLoadedIntoMemory.containsKey(path)){
|
||||
rVal = audioLoadedIntoMemory.get(path);
|
||||
String sanitizedPath = FileUtils.sanitizeFilePath(path);
|
||||
if(audioLoadedIntoMemory.containsKey(sanitizedPath)){
|
||||
rVal = audioLoadedIntoMemory.get(sanitizedPath);
|
||||
} else {
|
||||
LoggerInterface.loggerAudio.WARNING("Failed to find audio " + path);
|
||||
LoggerInterface.loggerAudio.WARNING("Failed to find audio " + sanitizedPath);
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@ -109,6 +109,11 @@ public class StateTransitionUtil {
|
||||
animation = state.getAnimation.get();
|
||||
}
|
||||
|
||||
TreeDataAudio audioData = state.audioData;
|
||||
if(state.getAudio != null && state.getAudio.get() != null){
|
||||
audioData = state.getAudio.get();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//Play main animation
|
||||
@ -122,13 +127,13 @@ public class StateTransitionUtil {
|
||||
if(parent == Globals.playerEntity && !Globals.controlHandler.cameraIsThirdPerson() && animation != null){
|
||||
//first person
|
||||
//play first person audio
|
||||
if(state.audioData != null && state.audioData.getAudioPath() != null){
|
||||
Globals.virtualAudioSourceManager.createVirtualAudioSource(state.audioData.getAudioPath(), VirtualAudioSourceType.CREATURE, false);
|
||||
if(audioData != null && audioData.getAudioPath() != null){
|
||||
Globals.virtualAudioSourceManager.createVirtualAudioSource(audioData.getAudioPath(), VirtualAudioSourceType.CREATURE, false);
|
||||
}
|
||||
} else {
|
||||
//play third person audio
|
||||
if(state.audioData != null && state.audioData.getAudioPath() != null){
|
||||
Globals.virtualAudioSourceManager.createVirtualAudioSource(state.audioData.getAudioPath(), VirtualAudioSourceType.CREATURE, false, EntityUtils.getPosition(parent));
|
||||
if(audioData != null && audioData.getAudioPath() != null){
|
||||
Globals.virtualAudioSourceManager.createVirtualAudioSource(audioData.getAudioPath(), VirtualAudioSourceType.CREATURE, false, EntityUtils.getPosition(parent));
|
||||
}
|
||||
}
|
||||
|
||||
@ -289,6 +294,9 @@ public class StateTransitionUtil {
|
||||
//The audio data
|
||||
TreeDataAudio audioData;
|
||||
|
||||
//Gets the audio to play
|
||||
Supplier<TreeDataAudio> getAudio;
|
||||
|
||||
//The function to fire on completion (ie to transition to the next state)
|
||||
Runnable onComplete;
|
||||
|
||||
@ -331,12 +339,12 @@ public class StateTransitionUtil {
|
||||
private StateTransitionUtilItem(
|
||||
Object stateEnum,
|
||||
Supplier<TreeDataAnimation> getAnimation,
|
||||
TreeDataAudio audioData,
|
||||
Supplier<TreeDataAudio> getAudio,
|
||||
Runnable onComplete
|
||||
){
|
||||
this.stateEnum = stateEnum;
|
||||
this.getAnimation = getAnimation;
|
||||
this.audioData = audioData;
|
||||
this.getAudio = getAudio;
|
||||
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.
|
||||
* @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 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
|
||||
*/
|
||||
public static StateTransitionUtilItem create(
|
||||
Object stateEnum,
|
||||
Supplier<TreeDataAnimation> getAnimation,
|
||||
TreeDataAudio audioData,
|
||||
Supplier<TreeDataAudio> getAudio,
|
||||
Runnable onComplete
|
||||
){
|
||||
return new StateTransitionUtilItem(
|
||||
stateEnum,
|
||||
getAnimation,
|
||||
audioData,
|
||||
getAudio,
|
||||
onComplete
|
||||
);
|
||||
}
|
||||
|
||||
@ -56,19 +56,19 @@ public class ClientBlockTree implements BehaviorTree {
|
||||
StateTransitionUtilItem.create(
|
||||
BlockState.WIND_UP,
|
||||
() -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getWindUpAnimation();},
|
||||
null,
|
||||
() -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getWindUpAudio();},
|
||||
null
|
||||
),
|
||||
StateTransitionUtilItem.create(
|
||||
BlockState.BLOCKING,
|
||||
() -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getMainAnimation();},
|
||||
null,
|
||||
() -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getMainAudio();},
|
||||
null
|
||||
),
|
||||
StateTransitionUtilItem.create(
|
||||
BlockState.COOLDOWN,
|
||||
() -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getCooldownAnimation();},
|
||||
null,
|
||||
() -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getCooldownAudio();},
|
||||
null
|
||||
),
|
||||
});
|
||||
|
||||
@ -3,6 +3,7 @@ package electrosphere.game.data.creature.type.block;
|
||||
import java.util.List;
|
||||
|
||||
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.
|
||||
@ -17,12 +18,21 @@ public class BlockVariant {
|
||||
//the animation to play when winding up
|
||||
TreeDataAnimation windUpAnimation;
|
||||
|
||||
//the audio to play when winding up
|
||||
TreeDataAudio windUpAudio;
|
||||
|
||||
//the main animation to play while blocking
|
||||
TreeDataAnimation mainAnimation;
|
||||
|
||||
//the main audio to play while blocking
|
||||
TreeDataAudio mainAudio;
|
||||
|
||||
//the animation to play when cooling down
|
||||
TreeDataAnimation cooldownAnimation;
|
||||
|
||||
//the audio to play while cooling down
|
||||
TreeDataAudio cooldownAudio;
|
||||
|
||||
//the list of default equipment cases that this variant should be used for
|
||||
List<VariantDefaults> defaults;
|
||||
|
||||
@ -42,6 +52,14 @@ public class BlockVariant {
|
||||
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
|
||||
* @return
|
||||
@ -50,6 +68,14 @@ public class BlockVariant {
|
||||
return mainAnimation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the audio to play when blocking
|
||||
* @return The audio
|
||||
*/
|
||||
public TreeDataAudio getMainAudio(){
|
||||
return mainAudio;
|
||||
}
|
||||
|
||||
/**
|
||||
* The animation to play when cooling down
|
||||
* @return
|
||||
@ -58,6 +84,14 @@ public class BlockVariant {
|
||||
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
|
||||
* @return
|
||||
|
||||
Loading…
Reference in New Issue
Block a user