Skip to content

Namespaced Events #73

@pablomayobre

Description

@pablomayobre

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)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions