Class: Gamefic::Scene::Base
- Inherits:
-
Object
- Object
- Gamefic::Scene::Base
- Defined in:
- lib/gamefic/scene/base.rb
Overview
The Base Scene is not intended for instantiation. Other Scene classes should inherit from it.
Instance Attribute Summary collapse
-
#actor ⇒ Object
readonly
Returns the value of attribute actor.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#prompt ⇒ String
Get the prompt to be displayed to the user when accepting input.
- #type ⇒ Object
Class Method Summary collapse
Instance Method Summary collapse
- #finish ⇒ Object
- #finished? ⇒ Boolean
- #flush ⇒ Object
-
#initialize(actor) ⇒ Base
constructor
A new instance of Base.
- #on_finish(&block) ⇒ Object
- #post_initialize ⇒ Object
- #start ⇒ Object
- #state ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(actor) ⇒ Base
Returns a new instance of Base.
12 13 14 15 |
# File 'lib/gamefic/scene/base.rb', line 12 def initialize actor @actor = actor post_initialize end |
Instance Attribute Details
#actor ⇒ Object (readonly)
Returns the value of attribute actor.
7 8 9 |
# File 'lib/gamefic/scene/base.rb', line 7 def actor @actor end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
10 11 12 |
# File 'lib/gamefic/scene/base.rb', line 10 def input @input end |
#prompt ⇒ String
Get the prompt to be displayed to the user when accepting input.
62 63 64 |
# File 'lib/gamefic/scene/base.rb', line 62 def prompt @prompt ||= '>' end |
#type ⇒ Object
66 67 68 |
# File 'lib/gamefic/scene/base.rb', line 66 def type @type ||= 'Scene' end |
Class Method Details
.on_start(&block) ⇒ Object
70 71 72 |
# File 'lib/gamefic/scene/base.rb', line 70 def self.on_start &block @start_block = block end |
.start_block ⇒ Object
75 76 77 |
# File 'lib/gamefic/scene/base.rb', line 75 def start_block @start_block end |
.subclass(&block) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/gamefic/scene/base.rb', line 52 def self.subclass &block c = Class.new(self) do on_start &block end c end |
Instance Method Details
#finish ⇒ Object
33 34 35 36 |
# File 'lib/gamefic/scene/base.rb', line 33 def finish @finish_block.call @actor, self unless @finish_block.nil? @finished = true end |
#finished? ⇒ Boolean
38 39 40 |
# File 'lib/gamefic/scene/base.rb', line 38 def finished? @finished ||= false end |
#flush ⇒ Object
42 43 44 |
# File 'lib/gamefic/scene/base.rb', line 42 def flush @state.clear end |
#on_finish(&block) ⇒ Object
20 21 22 |
# File 'lib/gamefic/scene/base.rb', line 20 def on_finish &block @finish_block = block end |
#post_initialize ⇒ Object
17 18 |
# File 'lib/gamefic/scene/base.rb', line 17 def post_initialize end |
#start ⇒ Object
29 30 31 |
# File 'lib/gamefic/scene/base.rb', line 29 def start self.class.start_block.call @actor, self unless self.class.start_block.nil? end |
#state ⇒ Object
46 47 48 49 50 |
# File 'lib/gamefic/scene/base.rb', line 46 def state { scene: type, prompt: prompt } end |
#update ⇒ Object
24 25 26 27 |
# File 'lib/gamefic/scene/base.rb', line 24 def update @input = actor.queue.shift finish end |