fix for empty sounds/animation collections
Some checks failed
Build / Build Game (push) Has been cancelled
Some checks failed
Build / Build Game (push) Has been cancelled
This commit is contained in:
@@ -4,8 +4,9 @@
|
||||
|
||||
namespace game::resource::xml
|
||||
{
|
||||
const std::string& AnimationEntryCollection::get()
|
||||
std::string* AnimationEntryCollection::get()
|
||||
{
|
||||
return at(util::vector::random_index_weighted(*this, [](const auto& entry) { return entry.weight; })).animation;
|
||||
if (empty()) return nullptr;
|
||||
return &at(util::vector::random_index_weighted(*this, [](const auto& entry) { return entry.weight; })).animation;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace game::resource::xml
|
||||
class AnimationEntryCollection : public std::vector<AnimationEntry>
|
||||
{
|
||||
public:
|
||||
const std::string& get();
|
||||
std::string* get();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -4,13 +4,15 @@
|
||||
|
||||
namespace game::resource::xml
|
||||
{
|
||||
Audio& SoundEntryCollection::get()
|
||||
Audio* SoundEntryCollection::get()
|
||||
{
|
||||
return at(util::vector::random_index_weighted(*this, [](const auto& entry) { return entry.weight; })).sound;
|
||||
if (empty()) return nullptr;
|
||||
return &at(util::vector::random_index_weighted(*this, [](const auto& entry) { return entry.weight; })).sound;
|
||||
}
|
||||
|
||||
void SoundEntryCollection::play()
|
||||
{
|
||||
at(util::vector::random_index_weighted(*this, [](const auto& entry) { return entry.weight; })).play();
|
||||
if (empty()) return;
|
||||
if (auto audio = get()) audio->play();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace game::resource::xml
|
||||
class SoundEntryCollection : public std::vector<SoundEntry>
|
||||
{
|
||||
public:
|
||||
Audio& get();
|
||||
Audio* get();
|
||||
void play();
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user