Sha256: 74ac0cf8a3834bc1331ed03dc525fdf5d24081e6c0654b6f6d97388acd52d853

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

module Baku
  class Entity
    attr_reader :id, :components, :tags
    
    def initialize(world, tags = [])
      @world = world
      @tags = tags
      
      @id = SecureRandom.uuid
      @components = {}
    end

    def add_component(component)
      if @components.has_key?(component.class)
        raise StandardError.
          new("Entity already has component: #{component.class}")
      end

      # TODO: this is some pretty ugly coupling, figure out if there's a cleaner
      # way to do this. Callbacks or something.
      @world.entity_manager.entity_add_component(self, component)
    end

    def remove_component(component_class)
      if !@components.has_key?(component_class)
        raise StandardError.
          new("Entity does not have component: #{component_class}")
      end

      # TODO: this is some pretty ugly coupling, figure out if there's a cleaner
      # way to do this. Callbacks or something.
      @world.entity_manager.entity_remove_component(self, get_component(component_class))
    end
    
    def get_component(component_class)
      @components[component_class]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
baku-0.1.0 lib/baku/entity.rb