Module: Draco::Scenes::InstanceMethods
- Defined in:
- lib/draco/scenes.rb
Overview
Internal: The plugin code for a Draco::World
Instance Method Summary collapse
- #after_initialize ⇒ Object
- #before_tick(context) ⇒ Object
- #default_scene ⇒ Object
- #filter(*components) ⇒ Object
- #scene ⇒ Object
- #scene=(name) ⇒ Object
- #scene_definitions ⇒ Object
- #scenes ⇒ Object
Instance Method Details
#after_initialize ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/draco/scenes.rb', line 27 def after_initialize @scenes = {} scene_definitions.each do |name, klass| @scenes[name] = klass.new end @current_scene = default_scene end |
#before_tick(context) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/draco/scenes.rb', line 37 def before_tick(context) super + @current_scene.systems.map do |system| entities = filter(system.filter) system.new(entities: entities, world: self) end end |
#default_scene ⇒ Object
63 64 65 66 67 68 |
# File 'lib/draco/scenes.rb', line 63 def default_scene defined = self.class.instance_variable_get(:@default_scene) raise UndefinedSceneError, "No scene defined with name #{defined.inspect}" unless @scenes[defined] @scenes[defined] end |
#filter(*components) ⇒ Object
45 46 47 |
# File 'lib/draco/scenes.rb', line 45 def filter(*components) super.merge(@current_scene.filter(*components)) end |
#scene ⇒ Object
53 54 55 |
# File 'lib/draco/scenes.rb', line 53 def scene @current_scene end |
#scene=(name) ⇒ Object
57 58 59 60 61 |
# File 'lib/draco/scenes.rb', line 57 def scene=(name) raise UndefinedSceneError, "No scene defined with name #{name.inspect}" unless @scenes[name] @current_scene = @scenes[name] end |
#scene_definitions ⇒ Object
70 71 72 |
# File 'lib/draco/scenes.rb', line 70 def scene_definitions self.class.instance_variable_get(:@scene_definitions) || {} end |
#scenes ⇒ Object
49 50 51 |
# File 'lib/draco/scenes.rb', line 49 def scenes @scenes end |