class Gamefic::Scene::Base
An abstract class for building different types of scenes. It can be extended either through concrete subclasses or by creating anonymous subclasses through a scene helper method like `Gamefic::World::Scenes#custom`.
Attributes
The scene's primary actor.
@return [Gamefic::Actor]
@return [Hash{Symbol => Object}]
The input received from the actor.
@return [String]
The text to display when requesting input.
@return [String]
A human-readable string identifying the type of scene.
@return [String]
Public Class Methods
# File lib/gamefic/scene/base.rb, line 34 def initialize actor, **data @actor = actor @data = data post_initialize end
@yieldparam [Class<Gamefic::Scene::Base>]
# File lib/gamefic/scene/base.rb, line 118 def self.on_start &block @start_block = block end
# File lib/gamefic/scene/base.rb, line 133 def start_block @start_block end
@yieldparam [Class<Gamefic::Actor>] @return [Class<Gamefic::Scene::Base>]
# File lib/gamefic/scene/base.rb, line 96 def self.subclass &block c = Class.new(self) do on_start &block end c end
# File lib/gamefic/scene/base.rb, line 137 def tracked? @tracked ||= false end
Public Instance Methods
A shortcut for the data
hash.
@param key [Symbol] @return [Object]
# File lib/gamefic/scene/base.rb, line 44 def [] key data[key] end
Finish the scene.
# File lib/gamefic/scene/base.rb, line 73 def finish @finish_block.call @actor, self unless @finish_block.nil? @finished = true end
Determine whether the scene's execution is finished.
@return [Boolean]
# File lib/gamefic/scene/base.rb, line 81 def finished? @finished ||= false end
Set
a proc to be executed at the end of the scene.
# File lib/gamefic/scene/base.rb, line 53 def on_finish &block @finish_block = block end
# File lib/gamefic/scene/base.rb, line 48 def post_initialize end
Get the prompt to be displayed to the user when accepting input.
@return [String] The text to be displayed.
# File lib/gamefic/scene/base.rb, line 106 def prompt @prompt ||= '>' end
Start the scene.
# File lib/gamefic/scene/base.rb, line 66 def start self.class.start_block.call @actor, self unless self.class.start_block.nil? @actor.entered self if tracked? end
Get a hash that describes the current state of the scene.
@return [Hash]
# File lib/gamefic/scene/base.rb, line 88 def state { scene: type, prompt: prompt } end
# File lib/gamefic/scene/base.rb, line 126 def tracked= bool self.class.tracked = bool end
# File lib/gamefic/scene/base.rb, line 122 def tracked? self.class.tracked? end
Get a String
that describes the type of scene.
@return [String]
# File lib/gamefic/scene/base.rb, line 113 def type @type ||= 'Scene' end
Update the scene.
# File lib/gamefic/scene/base.rb, line 59 def update @input = actor.queue.shift finish end