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

feat: add MSU.Class.Event class #321

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open

Conversation

LordMidas
Copy link
Member

This emulates event listeners. Now someone can raise an event without having to know who is listening to the event.

This emulates event listeners. Now someone can raise an event without having to know who is listening to the event.
@LordMidas LordMidas requested review from TaroEld and Enduriel October 7, 2023 02:17
@LordMidas LordMidas marked this pull request as ready for review October 7, 2023 02:17
@LordMidas LordMidas added this to the 1.3.0 milestone Oct 7, 2023
@Enduriel Enduriel modified the milestones: 1.3.0, 1.4.0 Oct 19, 2023
Comment on lines +51 to +52
// Will iterate over every registered function and check _conditionFunction
// if _conditionFunction returns false, stops iteration immediately
Copy link
Member

Choose a reason for hiding this comment

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

Feels to me like this should perhaps be based on the actual functions that are being called,ie if they return false then stop or something along those lines.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nah, those functions can be anything. They don't necessarily have to be Boolean returning functions. This conditionalInvoke is more along the lines of replicating the isAlive feature of skill_container events where the iteration stops if the actor is no longer alive.

Copy link
Member

Choose a reason for hiding this comment

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

Returning false to stop an event from continuing feels quite natural, it's how it's done in JS event bubbling for example. Using some otherwise decoupled thing to check for a state is weird in contrast.

@TaroEld
Copy link
Member

TaroEld commented Oct 22, 2023

Do we have an usecase for this?

@LordMidas
Copy link
Member Author

LordMidas commented Oct 23, 2023

Do we have an usecase for this?

I mean event listeners are a basic thing in programming and I'm sure people will find use cases for this. It will help modders write more decoupled code.

@TaroEld
Copy link
Member

TaroEld commented Oct 23, 2023

I'm wondering if keeping the env around like that doesn't lead to a risk of memory leaks.

@TaroEld
Copy link
Member

TaroEld commented Oct 23, 2023

Also, if this shouldn't keep a dict of events, with arrays for each of course.
Then, we might even consider filling them up with default events/stacks.
One for world_state, one for tactical_state, for example.

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.

3 participants