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.
Methods included from Gamefic::Serialize
instances, serialized_class, string_to_constant, to_serial
Constructor Details
#initialize(actor, **data) ⇒ Base
Returns a new instance of Base.
32 33 34 35 36 |
# File 'lib/gamefic/scene/base.rb', line 32 def initialize actor, **data @actor = actor @data = data post_initialize end |
Class Attribute Details
.tracked=(value) ⇒ Object (writeonly)
Sets the attribute tracked
129 130 131 |
# File 'lib/gamefic/scene/base.rb', line 129 def tracked=(value) @tracked = value end |
Instance Attribute Details
#actor ⇒ Gamefic::Actor (readonly)
The scene’s primary actor.
12 13 14 |
# File 'lib/gamefic/scene/base.rb', line 12 def actor @actor end |
#data ⇒ Hash{Symbol => Object} (readonly)
30 31 32 |
# File 'lib/gamefic/scene/base.rb', line 30 def data @data end |
#input ⇒ String (readonly)
The input received from the actor.
27 28 29 |
# File 'lib/gamefic/scene/base.rb', line 27 def input @input end |
#prompt ⇒ String
Get the prompt to be displayed to the user when accepting input.
104 105 106 |
# File 'lib/gamefic/scene/base.rb', line 104 def prompt @prompt ||= '>' end |
#type ⇒ String
Get a String that describes the type of scene.
111 112 113 |
# File 'lib/gamefic/scene/base.rb', line 111 def type @type ||= 'Scene' end |
Class Method Details
.on_start {|| ... } ⇒ Object
116 117 118 |
# File 'lib/gamefic/scene/base.rb', line 116 def self.on_start &block @start_block = block end |
.start_block ⇒ Object
131 132 133 |
# File 'lib/gamefic/scene/base.rb', line 131 def start_block @start_block end |
.subclass {|| ... } ⇒ Class<Gamefic::Scene::Base>
94 95 96 97 98 99 |
# File 'lib/gamefic/scene/base.rb', line 94 def self.subclass &block c = Class.new(self) do on_start &block end c end |
.tracked? ⇒ Boolean
135 136 137 |
# File 'lib/gamefic/scene/base.rb', line 135 def tracked? @tracked ||= false end |
Instance Method Details
#[](key) ⇒ Object
A shortcut for the #data hash.
42 43 44 |
# File 'lib/gamefic/scene/base.rb', line 42 def [] key data[key] end |
#finish ⇒ Object
Finish the scene.
71 72 73 74 |
# File 'lib/gamefic/scene/base.rb', line 71 def finish @finish_block.call @actor, self unless @finish_block.nil? @finished = true end |
#finished? ⇒ Boolean
Determine whether the scene’s execution is finished.
79 80 81 |
# File 'lib/gamefic/scene/base.rb', line 79 def finished? @finished ||= false end |
#on_finish(&block) ⇒ Object
Set a proc to be executed at the end of the scene.
51 52 53 |
# File 'lib/gamefic/scene/base.rb', line 51 def on_finish &block @finish_block = block end |
#post_initialize ⇒ Object
46 47 |
# File 'lib/gamefic/scene/base.rb', line 46 def post_initialize end |
#start ⇒ Object
Start the scene.
64 65 66 67 |
# File 'lib/gamefic/scene/base.rb', line 64 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.
86 87 88 89 90 |
# File 'lib/gamefic/scene/base.rb', line 86 def state { scene: type, prompt: prompt } end |
#tracked=(bool) ⇒ Object
124 125 126 |
# File 'lib/gamefic/scene/base.rb', line 124 def tracked= bool self.class.tracked = bool end |
#tracked? ⇒ Boolean
120 121 122 |
# File 'lib/gamefic/scene/base.rb', line 120 def tracked? self.class.tracked? end |
#update ⇒ Object
Update the scene.
57 58 59 60 |
# File 'lib/gamefic/scene/base.rb', line 57 def update @input = actor.queue.shift finish end |