Class: Gamefic::Chapter

Inherits:
Narrative show all
Extended by:
Scriptable::PlotProxies
Defined in:
lib/gamefic/chapter.rb

Overview

Chapters are plot extensions that manage their own namespaces. Authors can use them to encapsulate related content in a separate object instead of adding the required instance variables, methods, and attributes to the plot.

Chapters are similar to subplots with three important exceptions:

  • Chapters normally persist for the duration of a plot.

  • Players do not need to be introduced to a chapter.

  • Chapters share their plot’s entities, players, and rulebook.

Examples:

class MyChapter < Gamefic::Chapter
  def thing
    @thing ||= make Gamefic::Entity, name: 'chapter thing'
  end
end

class MyPlot < Gamefic::Plot
  append MyChapter
end

plot = MyPlot.new
plot.entities             #=> [<#Gamefic::Entity a chapter thing>]
plot.thing                #   raises NoMethodError
plot.chapters.first.thing #=> <#Gamefic::Entity a chapter thing>

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Scriptable::PlotProxies

attr_plot, lazy_plot, plot_pick, plot_pick!

Methods inherited from Narrative

#attach, #cast, #concluding?, #detach, #hydrate, inherited, #introduce, #post_script, #ready, #scenes, #seed, #uncast, #update

Methods included from Scriptable

#attr_seed, #blocks, #lazy_attr, #lazy_ivar, #make_seed, #method_missing, #no_scripts, #pick, #pick!, #proxy, #respond_to_missing?, #seed

Methods included from Scriptable::Scenes

#block, #conclusion, #introduction, #multiple_choice, #pause, #preface, #scene, #scenes, #yes_or_no

Methods included from Scriptable::Events

#on_conclude, #on_player_conclude, #on_player_output, #on_player_ready, #on_player_update, #on_ready, #on_update

Methods included from Scriptable::Actions

#after_action, #before_action, #interpret, #meta, #respond, #synonyms, #syntaxes, #verbs

Methods included from Scriptable::Queries

#abstract, #anywhere, #available, #children, #descendants, #myself, #parent, #plaintext, #siblings

Methods included from Scriptable::Proxies

#unproxy

Methods included from Scriptable::Entities

#destroy, #entities, #find, #make, #pick, #pick!, #players

Methods included from Logging

logger

Constructor Details

#initialize(plot) ⇒ Chapter

Returns a new instance of Chapter.

Parameters:



37
38
39
40
41
# File 'lib/gamefic/chapter.rb', line 37

def initialize(plot)
  @plot = plot
  # The plot is responsible for hydrating chapters
  super(hydrate: false)
end

Instance Attribute Details

#plotPlot (readonly)

Returns:



34
35
36
# File 'lib/gamefic/chapter.rb', line 34

def plot
  @plot
end

Instance Method Details

#branchObject



67
68
69
# File 'lib/gamefic/chapter.rb', line 67

def branch(...)
  plot.branch(...)
end

#entity_vaultObject



55
56
57
# File 'lib/gamefic/chapter.rb', line 55

def entity_vault
  plot.entity_vault
end

#included_blocksObject



47
48
49
# File 'lib/gamefic/chapter.rb', line 47

def included_blocks
  self.class.included_blocks - plot.included_blocks
end

#player_vaultObject



59
60
61
# File 'lib/gamefic/chapter.rb', line 59

def player_vault
  plot.player_vault
end

#rulebookObject



51
52
53
# File 'lib/gamefic/chapter.rb', line 51

def rulebook
  plot.rulebook
end

#scriptObject



43
44
45
# File 'lib/gamefic/chapter.rb', line 43

def script
  included_blocks.select(&:script?).each { |blk| Stage.run self, &blk.code }
end

#subplotsObject



63
64
65
# File 'lib/gamefic/chapter.rb', line 63

def subplots
  plot.subplots
end