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

Namespaced Events #73

Open
pablomayobre opened this issue Aug 29, 2023 · 1 comment
Open

Namespaced Events #73

pablomayobre opened this issue Aug 29, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@pablomayobre
Copy link
Collaborator

pablomayobre commented Aug 29, 2023

This is an idea for now, but I plan to experiment around it.

The idea would be that from now on Systems have names like so:

-- System definition with a name
local RenderSystem = System("Render", {pool = {"position", "texture"}})

-- Event definition
function RenderSystem:draw ()
  for _, entity in ipairs(self.pool) do
    love.graphics.draw(entity.texture.image, entity.position.x, entity.position.y)
  end
end

Now to emit the draw event we would usually call it like this

World:emit('draw', ...)

But this may also call other Systems that also define draw, if we only intended to call draw on the Render system we have no way to do so, with my proposal we would now call it like so:

World:emit('Render.draw', ...)

This means that now you have a way to call an event for a given System without calling events on other systems that may accidentally share the same name.

We can still target multiple systems if we don't specify the system name like so:

World:emit('draw', ...)

This makes the change backwards compatible, except for the addition of names for systems (which may also help with a debugger if we make one)

@pablomayobre pablomayobre self-assigned this Aug 29, 2023
@pablomayobre
Copy link
Collaborator Author

pablomayobre commented Aug 30, 2023

Something to keep in mind is that the arguments for beforeEmit and afterEmit will be changed as well.

Previously it was:

function World:beforeEmit (event, listeners, ...)

Now it will be

function World:beforeEmit (systemName, event, listeners, ...)

beforeEmit and afterEmit are fairly new and I expect more users to not use them in their code yet, plus the change is fairly small anyways so this shouldn't be a blocker to roll this feature out.

@pablomayobre pablomayobre added enhancement New feature or request feature and removed feature labels Jul 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant