class Gamefic::Scene::Base
The base class for scenes. Authors can instantiate this class directly and customize it with on_start
and on_finish
blocks.
Attributes
@todo Code smell
Public Class Methods
Source
# File lib/gamefic/scene/base.rb, line 94 def finish_blocks @finish_blocks ||= [] end
@return [Array<Proc>]
Source
# File lib/gamefic/scene/base.rb, line 52 def self.inherited(klass) super klass.use_props_class props_class klass.start_blocks.concat start_blocks klass.finish_blocks.concat finish_blocks end
Calls superclass method
Source
# File lib/gamefic/scene/base.rb, line 17 def initialize(actor, narrative = nil, props = nil, **context) @actor = actor @narrative = narrative @props = props || self.class.props_class.new @context = context end
@param actor [Actor] @param narrative [Narrative, nil] @param props [Props::Default, nil]
Source
# File lib/gamefic/scene/base.rb, line 110 def on_finish(&block) finish_blocks.push block end
@yieldparam actor [Actor] The scene’s actor @yieldparam props [Props::Default] The scene’s props @yieldparam context [Hash] Additional context @yieldreceiver [Narrative]
Source
# File lib/gamefic/scene/base.rb, line 102 def on_start(&block) start_blocks.push block end
@yieldparam actor [Actor] The scene’s actor @yieldparam props [Props::Default] The scene’s props @yieldparam context [Hash] Additional context @yieldreceiver [Narrative]
Source
# File lib/gamefic/scene/base.rb, line 80 def props_class @props_class ||= Props::Default end
Source
# File lib/gamefic/scene/base.rb, line 84 def rename(nickname) @nickname = nickname end
Source
# File lib/gamefic/scene/base.rb, line 89 def start_blocks @start_blocks ||= [] end
@return [Array<Proc>]
Protected Class Methods
Source
# File lib/gamefic/scene/base.rb, line 119 def use_props_class(klass) @props_class = klass end
@param klass [Class<Props::Default>]
Public Instance Methods
Source
# File lib/gamefic/scene/base.rb, line 44 def finish run_finish_blocks end
@return [void]
Source
# File lib/gamefic/scene/base.rb, line 38 def start run_start_blocks props end
@return [Props::Default]
Source
# File lib/gamefic/scene/base.rb, line 48 def to_hash { name: name, type: type } end
Source
# File lib/gamefic/scene/base.rb, line 33 def type self.class.type end
@return [String]
Private Instance Methods
Source
# File lib/gamefic/scene/base.rb, line 61 def execute(block) Binding.new(narrative, block).call(actor, props, context) end
Source
# File lib/gamefic/scene/base.rb, line 69 def run_finish_blocks self.class.finish_blocks.each { |blk| execute(blk) } end
Source
# File lib/gamefic/scene/base.rb, line 65 def run_start_blocks self.class.start_blocks.each { |blk| execute(blk) } end