Skip to content

Commit

Permalink
Fix missing (or rather, not loading) editor sprite actions (#2590)
Browse files Browse the repository at this point in the history
Right now, some badguys in the editor show the wrong sprite action (mostly for Direction::AUTO, but fish with "swim" actions for all directions). There was also a bug that the editor checked m_dir instead of m_start_dir for the badguys with Direction::AUTO. (m_dir is the current direction when the level is running, m_start_dir is the direction saved in the .stl level file that the enemy starts in).
Some would show facing in the wrong direction, some would show the wrong sprite action (eg. woken up sleeping spiky instead of sleeping, burning toads, etc.)

This fixes that.
  • Loading branch information
Narre committed Aug 19, 2023
1 parent 2f5c6ec commit 1ffe32d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 49 deletions.
76 changes: 27 additions & 49 deletions src/badguy/badguy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1064,59 +1064,37 @@ BadGuy::after_editor_set()
{
MovingSprite::after_editor_set();

if (m_dir == Direction::AUTO)
const std::string direction_str = m_start_dir == Direction::AUTO ? "left" : dir_to_string(m_start_dir);
const std::string actions[] = {"editor", "normal", "idle", "flying", "walking", "standing", "swim"};
bool action_set = false;

for (const auto& action_str : actions)
{
if (m_sprite->has_action("editor-left")) {
set_action("editor-left");
} else if (m_sprite->has_action("editor-right")) {
set_action("editor-right");
} else if (m_sprite->has_action("left")) {
set_action("left");
} else if (m_sprite->has_action("normal")) {
set_action("normal");
} else if (m_sprite->has_action("idle")) {
set_action("idle");
} else if (m_sprite->has_action("idle-left")) {
set_action("idle-left");
} else if (m_sprite->has_action("flying-left")) {
set_action("flying-left");
} else if (m_sprite->has_action("walking-left")) {
set_action("walking-left");
} else if (m_sprite->has_action("flying")) {
set_action("flying");
} else if (m_sprite->has_action("standing-left")) {
set_action("standing-left");
} else {
log_warning << "couldn't find editor sprite for badguy direction='auto': " << get_class_name() << std::endl;
const std::string test_action = action_str + "-" + direction_str;
if (m_sprite->has_action(test_action))
{
set_action(test_action);
action_set = true;
break;
}
else if (m_sprite->has_action(action_str))
{
set_action(action_str);
action_set = true;
break;
}
}
else
{
std::string action_str = dir_to_string(m_start_dir);

if (m_sprite->has_action("editor-" + action_str)) {
set_action("editor-" + action_str);
} else if (m_sprite->has_action(action_str)) {
set_action(action_str);
} else if (m_sprite->has_action("idle-" + action_str)) {
set_action("idle-" + action_str);
} else if (m_sprite->has_action("flying-" + action_str)) {
set_action("flying-" + action_str);
} else if (m_sprite->has_action("standing-" + action_str)) {
set_action("standing-" + action_str);
} else if (m_sprite->has_action("walking-" + action_str)) {
set_action("walking-" + action_str);
} else if (m_sprite->has_action("left")) {
set_action("left");
} else if (m_sprite->has_action("normal")) {
set_action("normal");
} else if (m_sprite->has_action("idle")) {
set_action("idle");
} else if (m_sprite->has_action("flying")) {
set_action("flying");
} else {
log_warning << "couldn't find editor sprite for badguy direction='" << action_str << "': "
<< get_class_name() << std::endl;
if (!action_set)
{
if (m_sprite->has_action(direction_str))
{
set_action(direction_str);
}
else
{
log_warning << "Couldn't find editor sprite action for badguy direction='"
<< dir_to_string(m_start_dir) << "': " << get_class_name() << "." << std::endl;
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/badguy/sspiky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,12 @@ SSpiky::is_flammable() const
return state != SSPIKY_SLEEPING;
}

void
SSpiky::after_editor_set()
{
WalkingBadguy::after_editor_set();
if (m_start_dir == Direction::AUTO)
set_action("sleeping-left");
}

/* EOF */
1 change: 1 addition & 0 deletions src/badguy/sspiky.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class SSpiky final : public WalkingBadguy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Sleeping Spiky"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual void after_editor_set() override;

protected:
enum SSpikyState {
Expand Down

0 comments on commit 1ffe32d

Please sign in to comment.