class Gamefic::Subplot

Subplots are disposable plots that run inside a parent plot. They can be started and concluded at any time during the parent plot’s runtime.

Attributes

config[R]

@return [Hash]

plot[R]

@return [Plot]

Public Class Methods

config() click to toggle source
# File lib/gamefic/subplot.rb, line 103
def config
  Proxy::Config.new
end
new(plot, introduce: [], **config) click to toggle source

@param plot [Gamefic::Plot] @param introduce [Gamefic::Actor, Array<Gamefic::Actor>, nil] @param config [Hash]

Calls superclass method Gamefic::Narrative::new
# File lib/gamefic/subplot.rb, line 21
def initialize plot, introduce: [], **config
  @plot = plot
  @config = config
  configure
  @config.freeze
  super()
  @concluded = false
  [introduce].flatten.each { |plyr| self.introduce plyr }
end
persist!() click to toggle source
# File lib/gamefic/subplot.rb, line 31
def self.persist!
  @persistent = true
end
persistent?() click to toggle source
# File lib/gamefic/subplot.rb, line 35
def self.persistent?
  @persistent ||= false
end

Public Instance Methods

branch(subplot_class = Gamefic::Subplot, introduce: [], **config) click to toggle source

Start a new subplot based on the provided class.

@note A subplot’s host is always the base plot, regardless of whether

it was branched from another subplot.

@param subplot_class [Class<Gamefic::Subplot>] The Subplot class @param introduce [Gamefic::Actor, Array<Gamefic::Actor>, nil] Players to introduce @param config [Hash] Subplot configuration @return [Gamefic::Subplot]

# File lib/gamefic/subplot.rb, line 79
def branch subplot_class = Gamefic::Subplot, introduce: [], **config
  plot.branch subplot_class, introduce: introduce, **config
end
conclude() click to toggle source
# File lib/gamefic/subplot.rb, line 52
def conclude
  rulebook.run_conclude_blocks
  players.each do |plyr|
    rulebook.run_player_conclude_blocks plyr
    uncast plyr
  end
  entities.each { |ent| destroy ent }
  @concluded = true
end
concluding?() click to toggle source
Calls superclass method Gamefic::Narrative#concluding?
# File lib/gamefic/subplot.rb, line 88
def concluding?
  return super unless persistent?

  @concluded
end
configure() click to toggle source

Subclasses can override this method to handle additional configuration options.

# File lib/gamefic/subplot.rb, line 86
def configure; end
included_blocks() click to toggle source
Calls superclass method Gamefic::Narrative#included_blocks
# File lib/gamefic/subplot.rb, line 43
def included_blocks
  super - plot.included_blocks
end
inspect() click to toggle source
# File lib/gamefic/subplot.rb, line 98
def inspect
  "#<#{self.class}>"
end
introduce(player) click to toggle source
Calls superclass method Gamefic::Narrative#introduce
# File lib/gamefic/subplot.rb, line 94
def introduce player
  @concluded ? player : super
end
persist(klass, **args) click to toggle source

Make an entity that persists in the subplot’s parent plot.

@see Plot#make

# File lib/gamefic/subplot.rb, line 66
def persist klass, **args
  plot.make klass, *args
end
persistent?() click to toggle source
# File lib/gamefic/subplot.rb, line 39
def persistent?
  self.class.persistent?
end
ready() click to toggle source
Calls superclass method Gamefic::Narrative#ready
# File lib/gamefic/subplot.rb, line 47
def ready
  super
  conclude if concluding?
end