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

refactor: registering actions/categories in action.cpp #2672

Merged
merged 9 commits into from
May 11, 2023

Conversation

scarf005
Copy link
Member

@scarf005 scarf005 commented Apr 20, 2023

Summary

SUMMARY: Infrastructure "Refactor registering actions/categories in action.cpp"

Purpose of change

i was bored and the code looked bad.

Describe the solution

replaced REGISTER_ACTION and REGISTER_CATEGORY macro with make_register_actions and make_register_categories.

they are curried functions which capture state then return another function which you can conveniently name register_actions and register_categories. pass it a set and you're good to go. also, it should be fairly performant because it's rvalue refed and uses std::transform under the hood.

Describe alternatives you've considered

put registering action and action for it in same function, because current system is very bug prone

// before

register("SOME_KEY");
// ...
if ( key == "SOME_KEY" ) {
	// do something
}
// after
register("SOME_KEY", [&]() -> void {
	// do something
})

Testing

idk i guess it'd pass tests?

Additional context

@github-actions github-actions bot added the src PR changes related to source code. label Apr 20, 2023
Copy link
Collaborator

@joveeater joveeater left a comment

Choose a reason for hiding this comment

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

Sorry I totally missed this. This looks great. Much cleaner now.

@scarf005 scarf005 merged commit 64f1172 into cataclysmbnteam:upload May 11, 2023
@scarf005 scarf005 deleted the refactor-register branch May 11, 2023 04:49
@scarf005 scarf005 restored the refactor-register branch May 13, 2023 11:44
@scarf005 scarf005 deleted the refactor-register branch May 13, 2023 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
src PR changes related to source code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants