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();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -74,7 +74,11 @@ namespace game::state::main
|
||||
}
|
||||
queuedItemIDs.clear();
|
||||
|
||||
if (isMouseRightDown) cursor.queue_play({cursorSchema.animations.return_.get()});
|
||||
if (isMouseRightDown)
|
||||
{
|
||||
auto animation = cursorSchema.animations.return_.get();
|
||||
if (animation) cursor.queue_play({*animation});
|
||||
}
|
||||
|
||||
if (auto heldItem = vector::find(items, heldItemIndex))
|
||||
{
|
||||
@@ -208,7 +212,7 @@ namespace game::state::main
|
||||
if (math::is_point_in_rectf(item.rect(), cursorPosition) && !isImguiCaptureMouse)
|
||||
{
|
||||
isItemHovered = true;
|
||||
cursor.queue_play({cursorSchema.animations.hover.get()});
|
||||
if (auto animation = cursorSchema.animations.hover.get()) cursor.queue_play({*animation});
|
||||
cursor.state = entity::Cursor::HOVER;
|
||||
|
||||
if (isMouseLeftClicked)
|
||||
@@ -220,7 +224,7 @@ namespace game::state::main
|
||||
if (isMouseLeftDown)
|
||||
{
|
||||
isItemHeld = true;
|
||||
cursor.queue_play({cursorSchema.animations.grab.get()});
|
||||
if (auto animation = cursorSchema.animations.grab.get()) cursor.queue_play({*animation});
|
||||
cursor.state = entity::Cursor::ACTION;
|
||||
heldItemIndex = i;
|
||||
heldItemMoveIndex = i;
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace game::state::main
|
||||
{
|
||||
if ((isMouseMiddleDown) || (isMouseLeftDown && isCtrlDown))
|
||||
{
|
||||
cursor.queue_play({cursorSchema.animations.pan.get()});
|
||||
if (auto animation = cursorSchema.animations.pan.get()) cursor.queue_play({*animation});
|
||||
pan -= imgui::to_vec2(io.MouseDelta) * panMultiplier;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace game::state::main
|
||||
auto zoomFactorBefore = math::to_unit(zoomBefore);
|
||||
auto cursorWorld = pan + (cursorPos / zoomFactorBefore);
|
||||
|
||||
cursor.queue_play({cursorSchema.animations.zoom.get()});
|
||||
if (auto animation = cursorSchema.animations.zoom.get()) cursor.queue_play({*animation});
|
||||
|
||||
zoom = glm::clamp(ZOOM_MIN, zoom + (io.MouseWheel * ZOOM_STEP), ZOOM_MAX);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user