Class: Engine::Component

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Serializable

allowed_class?, #awake, get_class, included, register_class, #uuid

Instance Attribute Details

#game_objectObject (readonly)

Returns the value of attribute game_object.



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

def game_object
  @game_object
end

Class Method Details

.destroyed_componentsObject



61
62
63
# File 'lib/engine/component.rb', line 61

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

.erase_destroyed_componentsObject



51
52
53
54
55
56
# File 'lib/engine/component.rb', line 51

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

.method_added(name) ⇒ Object



5
6
7
8
9
# File 'lib/engine/component.rb', line 5

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

Instance Method Details

#_erase!Object



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

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



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

def destroy
end

#destroy!Object



34
35
36
37
38
# File 'lib/engine/component.rb', line 34

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

#destroyed?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/engine/component.rb', line 30

def destroyed?
  @destroyed || false
end

#renderer?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/engine/component.rb', line 13

def renderer?
  false
end

#set_game_object(game_object) ⇒ Object



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

def set_game_object(game_object)
  @game_object = game_object
end

#startObject



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

def start
end

#ui_renderer?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/engine/component.rb', line 17

def ui_renderer?
  false
end

#update(delta_time) ⇒ Object



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

def update(delta_time) end