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
- #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.
57 58 59 |
# File 'lib/gamefic/scene/base.rb', line 57 def prompt @prompt ||= '>' end |
#type ⇒ Object
61 62 63 |
# File 'lib/gamefic/scene/base.rb', line 61 def type @type ||= 'Scene' end |
Class Method Details
.initialize_block ⇒ Object
70 71 72 |
# File 'lib/gamefic/scene/base.rb', line 70 def initialize_block @initialize_block end |
.on_initialize(&block) ⇒ Object
65 66 67 |
# File 'lib/gamefic/scene/base.rb', line 65 def self.on_initialize &block @initialize_block = block end |
.subclass(&block) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/gamefic/scene/base.rb', line 47 def self.subclass &block c = Class.new(self) do on_initialize &block end c end |
Instance Method Details
#finish ⇒ Object
33 34 35 |
# File 'lib/gamefic/scene/base.rb', line 33 def finish @finish_block.call @actor, self unless @finish_block.nil? end |
#flush ⇒ Object
37 38 39 |
# File 'lib/gamefic/scene/base.rb', line 37 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.initialize_block.call @actor, self unless self.class.initialize_block.nil? end |
#state ⇒ Object
41 42 43 44 45 |
# File 'lib/gamefic/scene/base.rb', line 41 def state { scene: type, prompt: prompt, input: input #, output: actor.messages, busy: !actor.queue.empty? } end |
#update ⇒ Object
24 25 26 27 |
# File 'lib/gamefic/scene/base.rb', line 24 def update @input = actor.queue.shift finish end |