diff --git a/data/images/objects/ispy/i-hiding-up.png b/data/images/objects/ispy/i-hiding-up.png deleted file mode 100644 index cedbe799ad9..00000000000 Binary files a/data/images/objects/ispy/i-hiding-up.png and /dev/null differ diff --git a/data/images/objects/ispy/i-idle-up.png b/data/images/objects/ispy/i-idle-up.png deleted file mode 100644 index 001bf1785b1..00000000000 Binary files a/data/images/objects/ispy/i-idle-up.png and /dev/null differ diff --git a/data/images/objects/ispy/i-shaking-up.png b/data/images/objects/ispy/i-shaking-up.png deleted file mode 100644 index 614c45e08c0..00000000000 Binary files a/data/images/objects/ispy/i-shaking-up.png and /dev/null differ diff --git a/data/images/objects/ispy/i-shaking2-up.png b/data/images/objects/ispy/i-shaking2-up.png deleted file mode 100644 index 3ef9eb7668d..00000000000 Binary files a/data/images/objects/ispy/i-shaking2-up.png and /dev/null differ diff --git a/data/images/objects/ispy/i-shaking3-up.png b/data/images/objects/ispy/i-shaking3-up.png deleted file mode 100644 index 927b8d6b7b2..00000000000 Binary files a/data/images/objects/ispy/i-shaking3-up.png and /dev/null differ diff --git a/data/images/objects/ispy/i-showing1-up.png b/data/images/objects/ispy/i-showing1-up.png deleted file mode 100644 index 47903b4302a..00000000000 Binary files a/data/images/objects/ispy/i-showing1-up.png and /dev/null differ diff --git a/data/images/objects/ispy/i-showing2-up.png b/data/images/objects/ispy/i-showing2-up.png deleted file mode 100644 index c573c1e25be..00000000000 Binary files a/data/images/objects/ispy/i-showing2-up.png and /dev/null differ diff --git a/data/images/objects/ispy/i-showing3-up.png b/data/images/objects/ispy/i-showing3-up.png deleted file mode 100644 index 98c3e497460..00000000000 Binary files a/data/images/objects/ispy/i-showing3-up.png and /dev/null differ diff --git a/data/images/objects/ispy/ispy.sprite b/data/images/objects/ispy/ispy.sprite index d5d089b591a..9745f7560d5 100644 --- a/data/images/objects/ispy/ispy.sprite +++ b/data/images/objects/ispy/ispy.sprite @@ -144,63 +144,22 @@ (action (name "idle-up") (hitbox 0 0 34 28) - (fps 14) - (images - "i-idle-up.png" - ) + (flip-action "idle-down") ) (action (name "alert-up") (hitbox 0 0 34 28) - (fps 14) - (images - "i-idle-up.png" - "i-idle-up.png" - "i-idle-up.png" - "i-idle-up.png" - "i-shaking-up.png" - "i-shaking2-up.png" - "i-shaking-up.png" - "i-shaking2-up.png" - "i-shaking-up.png" - "i-shaking2-up.png" - "i-shaking-up.png" - "i-shaking2-up.png" - "i-shaking3-up.png" - "i-showing2-up.png" - "i-showing1-up.png" - "i-hiding-up.png" - ) + (flip-action "alert-down") ) (action (name "hiding-up") (hitbox 0 0 34 28) - (fps 14) - (images - "i-hiding-up.png" - "i-hiding-up.png" - "i-hiding-up.png" - "i-hiding-up.png" - "i-hiding-up.png" - "i-hiding-up.png" - "i-hiding-up.png" - "i-hiding-up.png" - "i-hiding-up.png" - "i-hiding-up.png" - ) + (flip-action "hiding-down") ) (action (name "showing-up") (hitbox 0 0 34 28) - (fps 14) - (images - "i-hiding-up.png" - "i-showing1-up.png" - "i-showing2-up.png" - "i-showing3-up.png" - "i-idle-up.png" - "i-idle-up.png" - ) + (flip-action "showing-down") ) ) diff --git a/src/sprite/sprite_data.cpp b/src/sprite/sprite_data.cpp index 15935aecdff..b0d66ed8124 100644 --- a/src/sprite/sprite_data.cpp +++ b/src/sprite/sprite_data.cpp @@ -49,7 +49,8 @@ SpriteData::SpriteData(const ReaderMapping& mapping) : name() { auto iter = mapping.get_iter(); - while (iter.next()) { + while (iter.next()) + { if (iter.get_key() == "name") { iter.get(name); } else if (iter.get_key() == "action") { @@ -102,14 +103,15 @@ SpriteData::parse_action(const ReaderMapping& mapping) { auto action = std::make_unique(); - if (!mapping.get("name", action->name)) { + if (!mapping.get("name", action->name)) + { if (!actions.empty()) - throw std::runtime_error( - "If there are more than one action, they need names!"); + throw std::runtime_error("If there are more than one action, they need names!"); } std::vector hitbox; - if (mapping.get("hitbox", hitbox)) { + if (mapping.get("hitbox", hitbox)) + { switch (hitbox.size()) { case 4: @@ -145,18 +147,24 @@ SpriteData::parse_action(const ReaderMapping& mapping) } std::string mirror_action; + std::string flip_action; std::string clone_action; - if (mapping.get("mirror-action", mirror_action)) { + if (mapping.get("mirror-action", mirror_action)) + { const auto act_tmp = get_action(mirror_action); - if (act_tmp == nullptr) { + if (act_tmp == nullptr) + { std::ostringstream msg; msg << "Could not mirror action. Action not found: \"" << mirror_action << "\"\n" << "Mirror actions must be defined after the real one!"; throw std::runtime_error(msg.str()); - } else { + } + else + { float max_w = 0; float max_h = 0; - for (const auto& surf : act_tmp->surfaces) { + for (const auto& surf : act_tmp->surfaces) + { auto surface = surf->clone(HORIZONTAL_FLIP); max_w = std::max(max_w, static_cast(surface->get_width())); max_h = std::max(max_h, static_cast(surface->get_height())); @@ -182,18 +190,70 @@ SpriteData::parse_action(const ReaderMapping& mapping) action->fps = act_tmp->fps; } + if (action->family_name == "::" + action->name) + { + action->family_name = act_tmp->family_name; + } + } + } + else if (mapping.get("flip-action", flip_action)) + { + const auto act_tmp = get_action(flip_action); + if (act_tmp == nullptr) + { + std::ostringstream msg; + msg << "Could not flip action. Action not found: \"" << flip_action << "\"\n" + << "Flip actions must be defined after the real one!"; + throw std::runtime_error(msg.str()); + } + else + { + float max_w = 0; + float max_h = 0; + for (const auto& surf : act_tmp->surfaces) + { + auto surface = surf->clone(VERTICAL_FLIP); + max_w = std::max(max_w, static_cast(surface->get_width())); + max_h = std::max(max_h, static_cast(surface->get_height())); + action->surfaces.push_back(surface); + } + + if (action->hitbox_w < 1 && action->hitbox_h < 1) + { + action->hitbox_w = act_tmp->hitbox_w; + action->hitbox_h = act_tmp->hitbox_h; + action->x_offset = act_tmp->x_offset; + action->y_offset = act_tmp->y_offset; + } + + if (!action->has_custom_loops && act_tmp->has_custom_loops) + { + action->has_custom_loops = act_tmp->has_custom_loops; + action->loops = act_tmp->loops; + } + + if (action->fps == 0) + { + action->fps = act_tmp->fps; + } + if (action->family_name == "::" + action->name) { action->family_name = act_tmp->family_name; } } - } else if (mapping.get("clone-action", clone_action)) { + } + else if (mapping.get("clone-action", clone_action)) + { const auto* act_tmp = get_action(clone_action); - if (act_tmp == nullptr) { + if (act_tmp == nullptr) + { std::ostringstream msg; msg << "Could not clone action. Action not found: \"" << clone_action << "\"\n" << "Clone actions must be defined after the real one!"; throw std::runtime_error(msg.str()); - } else { + } + else + { // copy everything except the name (Semphris: and the family name) const std::string oldname = action->name; const std::string oldfam = action->family_name; @@ -205,14 +265,17 @@ SpriteData::parse_action(const ReaderMapping& mapping) action->family_name = act_tmp->family_name; } } - } else { // Load images + } + else + { // Load images std::optional surfaces_collection; std::vector images; if (mapping.get("images", images)) { float max_w = 0; float max_h = 0; - for (const auto& image : images) { + for (const auto& image : images) + { auto surface = Surface::from_file(FileSystem::join(mapping.get_doc().get_directory(), image)); max_w = std::max(max_w, static_cast(surface->get_width())); max_h = std::max(max_h, static_cast(surface->get_height()));