Class: ShatteredController::Base

Inherits:
ShatteredSupport::Base
  • Object
show all
Defined in:
lib/base.rb

Overview

When obtaining a result from a delegated method, the result will be the a response in the following order

  • Model (first)

  • View (last)

They are sorted so that you get the most useful response first.

Direct Known Subclasses

State

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object

Controller delegates all unknown methods to the view and model.

Raises:

  • (NoMethodError)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/base.rb', line 42

def method_missing(method_name, *args, &block)
  return if disabled?
  raise_no_method_error = true
  result = nil
  [view, model].each do |delegate|
    if delegate.method_defined?(method_name)
      result = delegate.send(method_name, *args, &block)
      raise_no_method_error = false
     end
  end
  
  raise NoMethodError, "Model, View, and Controller have no method defined named '#{method_name}'" if raise_no_method_error
  return result
end

Instance Attribute Details

#modelObject

Returns the value of attribute model.



37
38
39
# File 'lib/base.rb', line 37

def model
  @model
end

#viewObject

Returns the value of attribute view.



37
38
39
# File 'lib/base.rb', line 37

def view
  @view
end

Instance Method Details

#disabled?Boolean

An object is disabled when it has been unloaded.

Returns:

  • (Boolean)


78
79
80
# File 'lib/base.rb', line 78

def disabled?
  super
end

#unload!Object

Unloading a controller will completely unload an object from the scene.



73
74
75
# File 'lib/base.rb', line 73

def unload!
  super
end

#update_timer(time_elapsed) ⇒ Object

:nodoc:



58
59
60
61
62
63
# File 'lib/base.rb', line 58

def update_timer(time_elapsed)
#:nodoc:
  return if @timer == :unloaded
  timer.update(time_elapsed)
  model.timer.update(time_elapsed)
unless model.nil?
  view.timer.update(time_elapsed)
 unless view.nil?
end

#update_timers(time_elapsed) ⇒ Object

This is called to the State every frame by the main game loop. All update events are now run through Timers.



67
68
69
70
# File 'lib/base.rb', line 67

def update_timers(time_elapsed) #:nodoc:
  update_timer(time_elapsed)
  actors.each { |actor| actor.update_timers(time_elapsed) }
end