Class: Gamefic::Scene::Base
Overview
The Base Scene is not intended for instantiation. Other Scene classes should inherit from it.
Class Attribute Summary collapse
-
.tracked ⇒ Object
writeonly
Sets the attribute tracked.
Instance Attribute Summary collapse
-
#actor ⇒ Gamefic::Actor
readonly
The scene’s primary actor.
- #data ⇒ Hash{Symbol => Object} readonly
-
#input ⇒ String
readonly
The input received from the actor.
-
#prompt ⇒ String
Get the prompt to be displayed to the user when accepting input.
-
#type ⇒ String
Get a String that describes the type of scene.
Class Method Summary collapse
- .on_start {|| ... } ⇒ Object
- .start_block ⇒ Object
- .subclass {|| ... } ⇒ Class<Gamefic::Scene::Base>
- .tracked? ⇒ Boolean
Instance Method Summary collapse
-
#[](key) ⇒ Object
A shortcut for the #data hash.
-
#finish ⇒ Object
Finish the scene.
-
#finished? ⇒ Boolean
Determine whether the scene’s execution is finished.
-
#initialize(actor, **data) ⇒ Base
constructor
A new instance of Base.
-
#on_finish(&block) ⇒ Object
Set a proc to be executed at the end of the scene.
- #post_initialize ⇒ Object
-
#start ⇒ Object
Start the scene.
-
#state ⇒ Hash
Get a hash that describes the current state of the scene.
- #tracked=(bool) ⇒ Object
- #tracked? ⇒ Boolean
-
#update ⇒ Object
Update the scene.
Constructor Details
#initialize(actor, **data) ⇒ Base
29 30 31 32 33 |
# File 'lib/gamefic/scene/base.rb', line 29 def initialize actor, **data @actor = actor @data = data post_initialize end |
Class Attribute Details
.tracked=(value) ⇒ Object (writeonly)
Sets the attribute tracked
126 127 128 |
# File 'lib/gamefic/scene/base.rb', line 126 def tracked=(value) @tracked = value end |
Instance Attribute Details
#actor ⇒ Gamefic::Actor (readonly)
The scene’s primary actor.
9 10 11 |
# File 'lib/gamefic/scene/base.rb', line 9 def actor @actor end |
#data ⇒ Hash{Symbol => Object} (readonly)
27 28 29 |
# File 'lib/gamefic/scene/base.rb', line 27 def data @data end |
#input ⇒ String (readonly)
The input received from the actor.
24 25 26 |
# File 'lib/gamefic/scene/base.rb', line 24 def input @input end |
#prompt ⇒ String
Get the prompt to be displayed to the user when accepting input.
101 102 103 |
# File 'lib/gamefic/scene/base.rb', line 101 def prompt @prompt ||= '>' end |
#type ⇒ String
Get a String that describes the type of scene.
108 109 110 |
# File 'lib/gamefic/scene/base.rb', line 108 def type @type ||= 'Scene' end |
Class Method Details
.on_start {|| ... } ⇒ Object
113 114 115 |
# File 'lib/gamefic/scene/base.rb', line 113 def self.on_start &block @start_block = block end |
.start_block ⇒ Object
128 129 130 |
# File 'lib/gamefic/scene/base.rb', line 128 def start_block @start_block end |
.subclass {|| ... } ⇒ Class<Gamefic::Scene::Base>
91 92 93 94 95 96 |
# File 'lib/gamefic/scene/base.rb', line 91 def self.subclass &block c = Class.new(self) do on_start &block end c end |
.tracked? ⇒ Boolean
132 133 134 |
# File 'lib/gamefic/scene/base.rb', line 132 def tracked? @tracked ||= false end |
Instance Method Details
#[](key) ⇒ Object
A shortcut for the #data hash.
39 40 41 |
# File 'lib/gamefic/scene/base.rb', line 39 def [] key data[key] end |
#finish ⇒ Object
Finish the scene.
68 69 70 71 |
# File 'lib/gamefic/scene/base.rb', line 68 def finish @finish_block.call @actor, self unless @finish_block.nil? @finished = true end |
#finished? ⇒ Boolean
Determine whether the scene’s execution is finished.
76 77 78 |
# File 'lib/gamefic/scene/base.rb', line 76 def finished? @finished ||= false end |
#on_finish(&block) ⇒ Object
Set a proc to be executed at the end of the scene.
48 49 50 |
# File 'lib/gamefic/scene/base.rb', line 48 def on_finish &block @finish_block = block end |
#post_initialize ⇒ Object
43 44 |
# File 'lib/gamefic/scene/base.rb', line 43 def post_initialize end |
#start ⇒ Object
Start the scene.
61 62 63 64 |
# File 'lib/gamefic/scene/base.rb', line 61 def start self.class.start_block.call @actor, self unless self.class.start_block.nil? @actor.entered self if tracked? end |
#state ⇒ Hash
Get a hash that describes the current state of the scene.
83 84 85 86 87 |
# File 'lib/gamefic/scene/base.rb', line 83 def state { scene: type, prompt: prompt } end |
#tracked=(bool) ⇒ Object
121 122 123 |
# File 'lib/gamefic/scene/base.rb', line 121 def tracked= bool self.class.tracked = bool end |
#tracked? ⇒ Boolean
117 118 119 |
# File 'lib/gamefic/scene/base.rb', line 117 def tracked? self.class.tracked? end |
#update ⇒ Object
Update the scene.
54 55 56 57 |
# File 'lib/gamefic/scene/base.rb', line 54 def update @input = actor.queue.shift finish end |