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
@return [Hash]
@return [Plot]
Public Class Methods
# File lib/gamefic/subplot.rb, line 103 def config Proxy::Config.new end
@param plot [Gamefic::Plot] @param introduce [Gamefic::Actor, Array
<Gamefic::Actor>, nil] @param config [Hash]
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
# File lib/gamefic/subplot.rb, line 31 def self.persist! @persistent = true end
# File lib/gamefic/subplot.rb, line 35 def self.persistent? @persistent ||= false end
Public Instance Methods
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
# 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
Gamefic::Narrative#concluding?
# File lib/gamefic/subplot.rb, line 88 def concluding? return super unless persistent? @concluded end
Subclasses can override this method to handle additional configuration options.
# File lib/gamefic/subplot.rb, line 86 def configure; end
Gamefic::Narrative#included_blocks
# File lib/gamefic/subplot.rb, line 43 def included_blocks super - plot.included_blocks end
# File lib/gamefic/subplot.rb, line 98 def inspect "#<#{self.class}>" end
Gamefic::Narrative#introduce
# File lib/gamefic/subplot.rb, line 94 def introduce player @concluded ? player : super end
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
# File lib/gamefic/subplot.rb, line 39 def persistent? self.class.persistent? end
Gamefic::Narrative#ready
# File lib/gamefic/subplot.rb, line 47 def ready super conclude if concluding? end