This library provides an event bus and observer functionality for Draco.
class World < Draco::Worldinclude Draco::Eventsobserve CleanupDestroyedobserve GameOverScreen, component: Dead, on: :addobserve PlayMusic, component: Mute, on: :removeendworld = World.newworld.dispatch(ShowMenu)world.dispatch(SellUnit, [unit_one, unit_two])
Dispatch allows you to run a System on demand rather than on every tick. These will run at the beginning of the next click.
There are two ways to dispatch an event:
world.dispatch(System)will run the system using the System's filter on all the entities in the world.
world.dispatch(System, entities)will run the system on the entities you gave it.
Observers let you automatically dispatch an event any time a component is added or removed.
observe Systemwill run
Systemevery time a component is added that causes the entity to match the system's filter.
observe System, component: AnotherComponentwill run
AnotherComponentis added or removed and the entity matches the system's filter.
observe System, component: AnotherComponent, on: :addwill run
AnotherComponentis added and the entity matches the system's filter.
observe System, component: AnotherComponent, on: :removewill run
AnotherComponentis removed and the entity matches the system's filter.
Add this line to your application's Gemfile:
And then execute:
$ bundle install
Or install it yourself as:
$ gem install draco-events
After checking out the repo, run
bin/setup to install dependencies. Then, run
rake spec to run the tests. You can also run
bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run
bundle exec rake install. To release a new version, update the version number in
version.rb, and then run
bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the
.gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/draco-events. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the Draco::Events project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
5 months ago