diff --git a/cmake/copy_resources.cmake b/cmake/copy_resources.cmake index 1f85d80..22f39db 100644 --- a/cmake/copy_resources.cmake +++ b/cmake/copy_resources.cmake @@ -5,14 +5,14 @@ endif() set(CHARACTERS_DIR "${SRC_DIR}/characters") set(CHARACTERS_ZIP_SCRIPT "${CHARACTERS_DIR}/zip") -if(EXISTS "${CHARACTERS_ZIP_SCRIPT}") +if(EXISTS "${CHARACTERS_ZIP_SCRIPT}" AND NOT WIN32) execute_process( COMMAND "${CHARACTERS_ZIP_SCRIPT}" WORKING_DIRECTORY "${CHARACTERS_DIR}" RESULT_VARIABLE ZIP_SCRIPT_RESULT ) if(NOT ZIP_SCRIPT_RESULT EQUAL 0) - message(FATAL_ERROR "Failed running ${CHARACTERS_ZIP_SCRIPT} (exit code ${ZIP_SCRIPT_RESULT})") + message(WARNING "Failed running ${CHARACTERS_ZIP_SCRIPT} (exit code ${ZIP_SCRIPT_RESULT}); continuing with existing archives") endif() endif() @@ -26,6 +26,25 @@ file(COPY "${SRC_DIR}/" DESTINATION "${DST_DIR}" # Copy only .zip archives from resources/characters. file(MAKE_DIRECTORY "${DST_DIR}/characters") file(GLOB CHARACTER_ZIPS "${CHARACTERS_DIR}/*.zip") + +if(NOT CHARACTER_ZIPS) + file(GLOB CHARACTER_FILES RELATIVE "${CHARACTERS_DIR}" "${CHARACTERS_DIR}/*") + list(FILTER CHARACTER_FILES EXCLUDE REGEX "^zip$") + list(FILTER CHARACTER_FILES EXCLUDE REGEX ".*\\.zip$") + + if(CHARACTER_FILES) + execute_process( + COMMAND "${CMAKE_COMMAND}" -E tar cf "snivy.zip" --format=zip ${CHARACTER_FILES} + WORKING_DIRECTORY "${CHARACTERS_DIR}" + RESULT_VARIABLE ZIP_GENERATE_RESULT + ) + if(NOT ZIP_GENERATE_RESULT EQUAL 0) + message(FATAL_ERROR "Failed generating ${CHARACTERS_DIR}/snivy.zip (exit code ${ZIP_GENERATE_RESULT})") + endif() + file(GLOB CHARACTER_ZIPS "${CHARACTERS_DIR}/*.zip") + endif() +endif() + if(CHARACTER_ZIPS) file(COPY ${CHARACTER_ZIPS} DESTINATION "${DST_DIR}/characters") endif() diff --git a/src/resource/xml/animation_entry.cpp b/src/resource/xml/animation_entry.cpp index 598248c..86e7999 100644 --- a/src/resource/xml/animation_entry.cpp +++ b/src/resource/xml/animation_entry.cpp @@ -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; } } diff --git a/src/resource/xml/animation_entry.hpp b/src/resource/xml/animation_entry.hpp index a816114..f5cae86 100644 --- a/src/resource/xml/animation_entry.hpp +++ b/src/resource/xml/animation_entry.hpp @@ -17,7 +17,7 @@ namespace game::resource::xml class AnimationEntryCollection : public std::vector { public: - const std::string& get(); + std::string* get(); }; } diff --git a/src/resource/xml/sound_entry.cpp b/src/resource/xml/sound_entry.cpp index 946019f..027da0c 100644 --- a/src/resource/xml/sound_entry.cpp +++ b/src/resource/xml/sound_entry.cpp @@ -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(); } } diff --git a/src/resource/xml/sound_entry.hpp b/src/resource/xml/sound_entry.hpp index 0a356a9..baaf3f1 100644 --- a/src/resource/xml/sound_entry.hpp +++ b/src/resource/xml/sound_entry.hpp @@ -18,7 +18,7 @@ namespace game::resource::xml class SoundEntryCollection : public std::vector { public: - Audio& get(); + Audio* get(); void play(); }; } diff --git a/src/state/main/item_manager.cpp b/src/state/main/item_manager.cpp index 8ba3bd8..ff099ae 100644 --- a/src/state/main/item_manager.cpp +++ b/src/state/main/item_manager.cpp @@ -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; diff --git a/src/state/main/world.cpp b/src/state/main/world.cpp index 4e8c01e..d4780c5 100644 --- a/src/state/main/world.cpp +++ b/src/state/main/world.cpp @@ -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);