Class: Gamefic::Plot
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
Class Method Summary collapse
Instance Method Summary collapse
- #attach(cache) ⇒ Object
-
#branch(subplot_class = Gamefic::Subplot, introduce: [], **config) ⇒ Gamefic::Subplot
Start a new subplot based on the provided class.
- #chapters ⇒ Object
- #detach ⇒ Object
- #hydrate ⇒ Object
- #inspect ⇒ Object
- #post_script ⇒ Object
- #ready ⇒ Object
- #save ⇒ Object
- #script ⇒ Object
- #seed ⇒ Object
-
#subplots ⇒ Array<Subplot>
Get an array of all the current subplots.
-
#uncast(actor) ⇒ Actor
Remove an actor from the game.
- #update ⇒ Object
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
Methods included from Scriptable::Entities
#destroy, #entities, #entity_vault, #find, #make, #pick, #pick!, #player_vault, #players
Methods included from Logging
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_chapters ⇒ Object
102 103 104 |
# File 'lib/gamefic/plot.rb', line 102 def self.appended_chapters @appended_chapters ||= Set.new 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.
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 |
#chapters ⇒ Object
24 25 26 |
# File 'lib/gamefic/plot.rb', line 24 def chapters @chapters ||= self.class.appended_chapters.map { |klass| klass.new(self) } end |
#detach ⇒ Object
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 |
#hydrate ⇒ Object
93 94 95 96 |
# File 'lib/gamefic/plot.rb', line 93 def hydrate super subplots.each(&:hydrate) end |
#inspect ⇒ Object
77 78 79 |
# File 'lib/gamefic/plot.rb', line 77 def inspect "#<#{self.class}>" end |
#post_script ⇒ Object
19 20 21 22 |
# File 'lib/gamefic/plot.rb', line 19 def post_script super chapters.freeze end |
#ready ⇒ Object
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 |
#script ⇒ Object
13 14 15 16 17 |
# File 'lib/gamefic/plot.rb', line 13 def script super chapters.each(&:script) rulebook.scenes.with_defaults self end |
#seed ⇒ Object
8 9 10 11 |
# File 'lib/gamefic/plot.rb', line 8 def seed super chapters.each(&:seed) end |
#subplots ⇒ Array<Subplot>
Get an array of all the current subplots.
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.
50 51 52 53 |
# File 'lib/gamefic/plot.rb', line 50 def uncast actor subplots.each { |sp| sp.uncast actor } super end |
#update ⇒ Object
37 38 39 40 41 |
# File 'lib/gamefic/plot.rb', line 37 def update players.each(&:finish_take) super subplots.each(&:update) end |