Class: Engine::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/engine/component.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#game_objectObject (readonly)

Returns the value of attribute game_object.



9
10
11
# File 'lib/engine/component.rb', line 9

def game_object
  @game_object
end

Class Method Details

.destroyed_componentsObject



59
60
61
# File 'lib/engine/component.rb', line 59

def self.destroyed_components
  @destroyed_components ||= []
end

.erase_destroyed_componentsObject



49
50
51
52
53
54
# File 'lib/engine/component.rb', line 49

def self.erase_destroyed_components
  destroyed_components.each do |object|
    object._erase!
  end
  @destroyed_components = []
end

.method_added(name) ⇒ Object



3
4
5
6
7
# File 'lib/engine/component.rb', line 3

def self.method_added(name)
  @methods ||= Set.new
  return if name == :initialize || name == :destroyed?
  @methods.add(name)
end

Instance Method Details

#_erase!Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/engine/component.rb', line 38

def _erase!
  game_object.components.delete(self)
  class_name = self.class.name.split('::').last
  self.class.instance_variable_get(:@methods).each do |method|
    singleton_class.send(:undef_method, method)
    singleton_class.send(:define_method, method) do |*args, **kwargs|
      raise "This #{class_name} has been destroyed but you are still trying to access #{method}"
    end
  end
end

#destroyObject



56
57
# File 'lib/engine/component.rb', line 56

def destroy
end

#destroy!Object



32
33
34
35
36
# File 'lib/engine/component.rb', line 32

def destroy!
  Component.destroyed_components << self unless @destroyed
  destroy unless @destroyed
  @destroyed = true
end

#destroyed?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/engine/component.rb', line 28

def destroyed?
  @destroyed || false
end

#renderer?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/engine/component.rb', line 11

def renderer?
  false
end

#set_game_object(game_object) ⇒ Object



19
20
21
# File 'lib/engine/component.rb', line 19

def set_game_object(game_object)
  @game_object = game_object
end

#startObject



23
24
# File 'lib/engine/component.rb', line 23

def start
end

#ui_renderer?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/engine/component.rb', line 15

def ui_renderer?
  false
end

#update(delta_time) ⇒ Object



26
# File 'lib/engine/component.rb', line 26

def update(delta_time) end