Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trigger direction property to script trigger #3041

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

tobbi
Copy link
Member

@tobbi tobbi commented Aug 9, 2024

Adds a direction property to script trigger:
"auto" means that the trigger can be triggered from all sides.

"left" means only from the left side, "right" only from the right side etc.

Copy link
Member

@MatusGuy MatusGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. I'll test this soon.

Copy link
Member

@MatusGuy MatusGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script only runs once with oneshot off.

Also it'd be cool if the editor drew a line that says which direction it's checking for, but this is just a suggestion.

Lots of people have been asking for this and im excited aswell!

@tobbi tobbi force-pushed the scripttrigger_trigger_direction branch from 9c17696 to eb6dce0 Compare January 11, 2025 14:25
@tobbi tobbi requested review from MatusGuy and Vankata453 January 11, 2025 15:32
@tobbi
Copy link
Member Author

tobbi commented Jan 11, 2025

The script only runs once with oneshot off.

I could not reproduce this.

Also it'd be cool if the editor drew a line that says which direction it's checking for, but this is just a suggestion.

Added that in the latest commit.

@tobbi
Copy link
Member Author

tobbi commented Jan 11, 2025

I just found something: We could technically move the code to the trigger base class and support directions for all available triggers.

@MatusGuy
Copy link
Member

Good idea

src/trigger/trigger_base.cpp Show resolved Hide resolved
Comment on lines +148 to +184
const float indicator_width = 2.0f;
const float indicator_length = 50.0f;
std::vector<Rectf> indicators;

Rectf left_indicator = Rectf(bbox.get_left() - indicator_length,
bbox.get_middle().y - indicator_width,
bbox.get_left(),
bbox.get_middle().y + indicator_width);

Rectf right_indicator = Rectf(bbox.get_right(),
bbox.get_middle().y - indicator_width,
bbox.get_right() + indicator_length,
bbox.get_middle().y + indicator_width);

Rectf up_indicator = Rectf(bbox.get_middle().x - indicator_width,
bbox.get_top() - indicator_length,
bbox.get_middle().x + indicator_width,
bbox.get_top());

Rectf down_indicator = Rectf(bbox.get_middle().x - indicator_width,
bbox.get_bottom(),
bbox.get_middle().x + indicator_width,
bbox.get_bottom() + indicator_length);

if(m_trigger_direction == Direction::LEFT || m_trigger_direction == Direction::AUTO)
indicators.push_back(left_indicator);
if(m_trigger_direction == Direction::RIGHT || m_trigger_direction == Direction::AUTO)
indicators.push_back(right_indicator);
if(m_trigger_direction == Direction::UP || m_trigger_direction == Direction::AUTO)
indicators.push_back(up_indicator);
if(m_trigger_direction == Direction::DOWN || m_trigger_direction == Direction::AUTO)
indicators.push_back(down_indicator);

for(const auto& dir_indicator : indicators)
{
context.color().draw_filled_rect(dir_indicator, color, transparency, layer);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you just draw these rectangles directly? And you don't need to draw 4 indicators if a direction isn't specified, it's already implied.


context.color().draw_filled_rect(bbox, color, transparency, layer);

if (!Editor::is_active() || m_trigger_direction == Direction::NONE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_trigger_direction == Direction::NONE is never true. Is it?

Comment on lines +121 to +128
if (object_bbox.get_left() < bbox.get_left())
object_direction = Direction::LEFT;
if (object_bbox.get_right() > bbox.get_right())
object_direction = Direction::RIGHT;
if (object_bbox.get_top() < bbox.get_top())
object_direction = Direction::UP;
if (object_bbox.get_bottom() > bbox.get_bottom())
object_direction = Direction::DOWN;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This algorithm doesn't look right. Is it possible to instead use the CollisionHit given in collision instead? You could save the direction to a member variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants