Class: Gamefic::Plot

Inherits:
Narrative show all
Defined in:
lib/gamefic/plot.rb

Overview

The plot is the central narrative. It provides a script interface with methods for creating entities, actions, scenes, and hooks.

Instance Attribute Summary

Attributes inherited from Narrative

#rulebook

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Narrative

#cast, #concluding?, #included_blocks, inherited, #initialize, #introduce, #scenes

Methods included from Scriptable

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

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, #entity_vault, #find, #make, #pick, #pick!, #player_vault, #players

Methods included from Logging

logger

Constructor Details

This class inherits a constructor from Gamefic::Narrative

Class Method Details

.append(chapter) ⇒ Object



98
99
100
# File 'lib/gamefic/plot.rb', line 98

def self.append chapter
  appended_chapters.add chapter
end

.appended_chaptersObject



102
103
104
# File 'lib/gamefic/plot.rb', line 102

def self.appended_chapters
  @appended_chapters ||= Set.new
end

.restore(data) ⇒ Object



106
107
108
# File 'lib/gamefic/plot.rb', line 106

def self.restore data
  Snapshot.restore data
end

Instance Method Details

#attach(cache) ⇒ Object



88
89
90
91
# File 'lib/gamefic/plot.rb', line 88

def attach(cache)
  super(cache.shift)
  subplots.each { |subplot| subplot.attach cache.shift }
end

#branch(subplot_class = Gamefic::Subplot, introduce: [], **config) ⇒ Gamefic::Subplot

Start a new subplot based on the provided class.

Parameters:

Returns:



68
69
70
71
# File 'lib/gamefic/plot.rb', line 68

def branch subplot_class = Gamefic::Subplot, introduce: [], **config
  subplot_class.new(self, introduce: introduce, **config)
               .tap { |sub| subplots.push sub }
end

#chaptersObject



24
25
26
# File 'lib/gamefic/plot.rb', line 24

def chapters
  @chapters ||= self.class.appended_chapters.map { |klass| klass.new(self) }
end

#detachObject



81
82
83
84
85
86
# File 'lib/gamefic/plot.rb', line 81

def detach
  cache = [@rulebook]
  @rulebook = nil
  cache.concat subplots.map(&:detach)
  cache
end

#hydrateObject



93
94
95
96
# File 'lib/gamefic/plot.rb', line 93

def hydrate
  super
  subplots.each(&:hydrate)
end

#inspectObject



77
78
79
# File 'lib/gamefic/plot.rb', line 77

def inspect
  "#<#{self.class}>"
end

#post_scriptObject



19
20
21
22
# File 'lib/gamefic/plot.rb', line 19

def post_script
  super
  chapters.freeze
end

#readyObject



28
29
30
31
32
33
34
35
# File 'lib/gamefic/plot.rb', line 28

def ready
  super
  subplots.each(&:ready)
  players.each(&:start_take)
  subplots.each(&:conclude) if concluding?
  players.select(&:concluding?).each { |plyr| rulebook.run_player_conclude_blocks plyr }
  subplots.delete_if(&:concluding?)
end

#saveObject



73
74
75
# File 'lib/gamefic/plot.rb', line 73

def save
  Snapshot.save self
end

#scriptObject



13
14
15
16
17
# File 'lib/gamefic/plot.rb', line 13

def script
  super
  chapters.each(&:script)
  rulebook.scenes.with_defaults self
end

#seedObject



8
9
10
11
# File 'lib/gamefic/plot.rb', line 8

def seed
  super
  chapters.each(&:seed)
end

#subplotsArray<Subplot>

Get an array of all the current subplots.

Returns:



58
59
60
# File 'lib/gamefic/plot.rb', line 58

def subplots
  @subplots ||= []
end

#uncast(actor) ⇒ Actor

Remove an actor from the game.

Calling ‘uncast` on the plot will also remove the actor from its subplots.

Parameters:

Returns:



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

def uncast actor
  subplots.each { |sp| sp.uncast actor }
  super
end

#updateObject



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

def update
  players.each(&:finish_take)
  super
  subplots.each(&:update)
end