class Gamefic::Scene::Default
The base class for scenes. Authors can instantiate this class directly and customize it with on_start
and on_finish
blocks.
Attributes
name[R]
@return [Symbol]
Public Class Methods
new(name, narrative, on_start: nil, on_finish: nil) { |self| ... }
click to toggle source
@param name [Symbol] @param narrative [Narrative] @param on_start
[Proc, nil] @param on_finish
[Proc, nil] @yieldparam [self]
# File lib/gamefic/scene/default.rb, line 17 def initialize name, narrative, on_start: nil, on_finish: nil @name = name @narrative = narrative @start_blocks = [] @finish_blocks = [] @start_blocks.push on_start if on_start @finish_blocks.push on_finish if on_finish yield(self) if block_given? end
props_class()
click to toggle source
# File lib/gamefic/scene/default.rb, line 67 def self.props_class @props_class ||= Props::Default end
Protected Class Methods
use_props_class(klass)
click to toggle source
# File lib/gamefic/scene/default.rb, line 82 def use_props_class klass @props_class = klass end
Public Instance Methods
conclusion?()
click to toggle source
# File lib/gamefic/scene/default.rb, line 71 def conclusion? is_a?(Conclusion) end
finish(actor, props)
click to toggle source
@param actor [Gamefic::Actor] @param props [Props::Default] @return [void]
# File lib/gamefic/scene/default.rb, line 55 def finish actor, props props.input = actor.queue.shift&.strip end
new_props(**context)
click to toggle source
# File lib/gamefic/scene/default.rb, line 32 def new_props(**context) self.class.props_class.new(self, **context) end
on_finish(&block)
click to toggle source
# File lib/gamefic/scene/default.rb, line 40 def on_finish &block @finish_blocks.push block end
on_start(&block)
click to toggle source
# File lib/gamefic/scene/default.rb, line 36 def on_start &block @start_blocks.push block end
run_finish_blocks(actor, props)
click to toggle source
# File lib/gamefic/scene/default.rb, line 63 def run_finish_blocks actor, props @finish_blocks.each { |blk| Stage.run(@narrative, actor, props, &blk) } end
run_start_blocks(actor, props)
click to toggle source
# File lib/gamefic/scene/default.rb, line 59 def run_start_blocks actor, props @start_blocks.each { |blk| Stage.run(@narrative, actor, props, &blk) } end
start(actor, props)
click to toggle source
@param actor [Gamefic::Actor] @param props [Props::Default] @return [void]
# File lib/gamefic/scene/default.rb, line 47 def start actor, props props.output[:scene] = to_hash props.output[:prompt] = props.prompt end
to_hash()
click to toggle source
# File lib/gamefic/scene/default.rb, line 75 def to_hash { name: name, type: type } end
type()
click to toggle source
@return [String]
# File lib/gamefic/scene/default.rb, line 28 def type @type ||= self.class.to_s.sub(/^Gamefic::Scene::/, '') end