
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Draco is an Entity Component System for DragonRuby GTK.
An Entity Component System is an architectural framework that decouples game objects from game logic. An allows you to build game objects through composition. This allows you to easily share small logic components between different game objects.
This repository includes sample applications in the samples/
directory.
cp -r draco/samples/ dragonruby/
../dragonruby teeny-tiny
or ./dragonruby gorillas-basic
.lib
directory inside your game's app
directory.lib/draco.rb
into your new lib
directory.main.rb
file, require app/lib/draco.rb
.Draco uses [https://semver.org/].
Components represent small atomic bits of state. It's better to use many small components than few large components. These can be shared across many different types of game objects.
class Visible < Draco::Component; end
Visible
is an example of a tag component. An entity either has it, or it doesn't. We can also associate data with our
components.
class Position < Draco::Component
attribute :x, default: 0
attribute :y, default: 0
end
component = Position.new
The component's attributes add a getter and setter on the component for ease of use.
component.x = 110
component.x
# => 110
The Visible
class above is an example of a tag component. These are common enough that we don't necessarily want to
define a bunch of empty component classes. Draco provides a way to generate these classes at runtime.
Draco::Tag(:visible)
# => Visible
Entities are independant game objects. They consist of a unique id and a list of components.
entity = Draco::Entity.new
entity.components << Position.new(x: 50, y: 50)
Often we have types of entities that are reused throughout the game. We can define our own subclass in order to automate creating these entities.
class Goblin < Draco::Entity
component Position, x: 50, y: 50
component Tag(:visible)
end
goblin = Goblin.new
We can override the default values for the given components when initializing a new entity.
goblin = Goblin.new(position: {x: 100, y: 100})
In order to access the data within our entity's components, the entity has a method named after that component. This is generated based on the
underscored name of the component's class (e.g. MapLayer
would be map_layer
).
goblin.position.x
# => 100
Systems encapsulate all of the logic of your game. The system runs on every tick and it's job is to update the state of the entities.
Each system can set a default filter by passing in a list of components. When the world runs the system, it will set the system's entities to the entities that include all of the given components.
class RenderSpriteSystem < Draco::System
filter Tag(:visible), Position, Sprite
def tick(args)
# You can also access the world that called the system.
camera = world.filter([Camera]).first
sprites = entities.select { |e| entity_in_camera?(e, camera) }.map do |entity|
{
x: entity.position.x - camera.position.x,
y: entity.position.y - camera.position.y,
w: entity.sprite.w,
h: entity.sprite.h,
path: entity.sprite.path
}
end
args.outputs.sprites << sprites
end
def entity_in_camera?(entity, camera)
camera_rect = {x: camera.x, y: camera.y, w: camera.w, h: camera.h}
entity_rect = {x: entity.position.x, y: entity.position.y, w: entity.sprite.w, h: entity.sprite.h}
entity_rect.intersect_rect?(camera_rect)
end
end
A world keeps track of all current entities and runs all of the systems on every tick.
world = Draco::World.new
world.entities << goblin
world.systems << RenderSpriteSystem
world.tick(args)
Just like with entities, we can define a subclassed template for our world.
class Overworld < Draco::World
entity Goblin
entity Player, position: { x: 50, y: 50 }, as: :player
systems RenderSpriteSystem, InputSystem
end
world = Overworld.new
If there are entities that are frequently accessed in our systems, we can give these a name. In the above example, our
player entity has been given the name player
. We can now access this directly from our world:
world.player
In some cases you'll want to keep track of entities by their id, such as when you want to keep track of another entity in a component.
entity = Player.new
entity.id
# => 12
world.entities[12] == entity
# => true
Here are some good resources to learn about Entity Component Systems
Draco is licensed under AGPL. You can purchase the right to use Draco under the commercial license.
Each purchase comes with free upgrades for the current major version of Draco.
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.
Before submitting a pull request, please read the contribution guidelines.
Bug reports and pull requests are welcome on GitHub at https://github.com/guitsaru/draco. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
Everyone interacting in the Draco project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
FAQs
Unknown package
We found that draco demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.