New component field type to support files
Also fixed Audio System to work with this new supported component field type
This commit is contained in:
@@ -1,11 +1,20 @@
|
||||
#include "AudioEmitterComponent.h"
|
||||
|
||||
#include "src/FileSystem/FileSystem.h"
|
||||
|
||||
namespace Nuake {
|
||||
|
||||
json AudioEmitterComponent::Serialize()
|
||||
{
|
||||
BEGIN_SERIALIZE();
|
||||
SERIALIZE_VAL(FilePath);
|
||||
|
||||
bool validFile = FilePath.file != nullptr && FilePath.file->Exist();
|
||||
j["validFile"] = validFile;
|
||||
if (validFile)
|
||||
{
|
||||
j["file"] = FilePath.file->GetRelativePath();
|
||||
}
|
||||
|
||||
SERIALIZE_VAL(IsPlaying);
|
||||
SERIALIZE_VAL(Volume);
|
||||
SERIALIZE_VAL(Pan);
|
||||
@@ -20,7 +29,16 @@ namespace Nuake {
|
||||
|
||||
bool AudioEmitterComponent::Deserialize(const json& j)
|
||||
{
|
||||
DESERIALIZE_VAL(FilePath);
|
||||
if (j.contains("validFile"))
|
||||
{
|
||||
bool validFile = j["validFile"];
|
||||
if (validFile)
|
||||
{
|
||||
std::string filePath = j["file"];
|
||||
FilePath.file = FileSystem::GetFile(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
DESERIALIZE_VAL(Volume);
|
||||
DESERIALIZE_VAL(IsPlaying);
|
||||
DESERIALIZE_VAL(Pan);
|
||||
@@ -32,4 +50,4 @@ namespace Nuake {
|
||||
DESERIALIZE_VAL(Loop);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "Component.h"
|
||||
#include "FieldTypes.h"
|
||||
|
||||
#include "src/Core/Core.h"
|
||||
#include "src/FileSystem/File.h"
|
||||
#include "src/Resource/Resource.h"
|
||||
#include "src/Resource/Serializable.h"
|
||||
|
||||
namespace Nuake {
|
||||
@@ -13,6 +16,11 @@ namespace Nuake {
|
||||
|
||||
static void InitializeComponentClass()
|
||||
{
|
||||
BindComponentField<&AudioEmitterComponent::File>("FilePath", "File Path");
|
||||
|
||||
BindComponentField<&AudioEmitterComponent::FilePath>("FilePath", "File Path");
|
||||
ResourceFileRestriction("_AudioFile");
|
||||
|
||||
BindComponentField<&AudioEmitterComponent::IsPlaying>("IsPlaying", "Is Playing");
|
||||
BindComponentField<&AudioEmitterComponent::Loop>("Loop", "Loop");
|
||||
|
||||
@@ -34,7 +42,8 @@ namespace Nuake {
|
||||
}
|
||||
|
||||
public:
|
||||
std::string FilePath;
|
||||
Ref<File> File;
|
||||
ResourceFile FilePath;
|
||||
|
||||
bool IsPlaying = false;
|
||||
bool Loop = false;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/Core/Core.h"
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
class File;
|
||||
|
||||
struct ResourceFile
|
||||
{
|
||||
ResourceFile() {}
|
||||
ResourceFile(const Ref<File>& inFile) : file(inFile) {}
|
||||
|
||||
Ref<File> file = nullptr;
|
||||
};
|
||||
}
|
||||
@@ -44,14 +44,14 @@ namespace Nuake
|
||||
{
|
||||
auto [transformComponent, audioEmitterComponent] = view.get<TransformComponent, AudioEmitterComponent>(e);
|
||||
|
||||
if (audioEmitterComponent.FilePath.empty())
|
||||
if (audioEmitterComponent.FilePath.file == nullptr || !audioEmitterComponent.FilePath.file->Exist())
|
||||
{
|
||||
// Doesn't have a file
|
||||
continue;
|
||||
}
|
||||
|
||||
const bool isPlaying = audioEmitterComponent.IsPlaying;
|
||||
const std::string absoluteFilePath = FileSystem::RelativeToAbsolute(audioEmitterComponent.FilePath);
|
||||
const std::string absoluteFilePath = audioEmitterComponent.FilePath.file->GetAbsolutePath();
|
||||
const bool isVoiceActive = audioManager.IsVoiceActive(absoluteFilePath);
|
||||
|
||||
AudioRequest audioRequest;
|
||||
|
||||
Reference in New Issue
Block a user