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 collapse
- #chapters ⇒ Array<Chapter> readonly
Attributes included from Scriptable::Scenes
#default_conclusion, #default_scene
Class Method Summary collapse
Instance Method Summary collapse
-
#branch(subplot_class = Gamefic::Subplot, introduce: [], **config) ⇒ Gamefic::Subplot
Start a new subplot based on the provided class.
- #find_and_bind(symbol) ⇒ Object
-
#initialize ⇒ Plot
constructor
A new instance of Plot.
- #inspect ⇒ Object
- #player_output_blocks ⇒ Object
- #ready_blocks ⇒ Object
- #responses ⇒ Object
- #responses_for(*verbs) ⇒ Object
-
#subplots ⇒ Array<Subplot>
Get an array of all the current subplots.
- #syntaxes ⇒ Object
-
#turn ⇒ void
Complete a game turn.
- #uncast(actor) ⇒ Object
- #update_blocks ⇒ Object
Methods inherited from Narrative
#cast, #concluding?, inherited, #introduce, restore, #save
Methods included from Scriptable
#included_scripts, #pick, #pick!
Methods included from Scriptable::Syntaxes
Methods included from Scriptable::Seeds
#construct, #make, #seed, #seeds
Methods included from Scriptable::Scenes
#active_choice, #block, #conclusion, #introduction, #introductions, #multiple_choice, #named_scenes, #pause, #scene_classes, #scene_classes_map, #scenes, #select_default_conclusion, #select_default_scene, #yes_or_no
Methods included from Scriptable::Responses
Methods included from Scriptable::Queries
#available, #children, #descendants, #extended, #global, #integer, #myself, #parent, #plaintext, #siblings
Methods included from Scriptable::Hooks
#after_command, #after_commands, #before_command, #before_commands, #conclude_blocks, #on_conclude, #on_player_conclude, #on_player_output, #on_player_ready, #on_player_update, #on_ready, #on_update, #player_conclude_blocks
Methods included from Scripting
Methods included from Scripting::Syntaxes
Methods included from Scripting::Scenes
#default_conclusion, #default_scene, #introductions, #named_scenes, #prepare, #scene_class, #scenes
Methods included from Scripting::Seeds
Methods included from Scripting::Hooks
#after_commands, #before_commands, #conclude_blocks, #player_conclude_blocks
Methods included from Scripting::Entities
#destroy, #entities, #find, #make, #pick, #pick!, #players
Methods included from Scripting::Proxies
Constructor Details
#initialize ⇒ Plot
Returns a new instance of Plot.
11 12 13 14 |
# File 'lib/gamefic/plot.rb', line 11 def initialize super @chapters = self.class.appended_chapter_map.map { |chap, config| chap.new(self, **unproxy(config)) } end |
Instance Attribute Details
Class Method Details
.append(chapter, **config) ⇒ Object
43 44 45 46 47 |
# File 'lib/gamefic/plot.rb', line 43 def self.append(chapter, **config) Gamefic.logger.warn "Overwriting existing chapter #{chapter}" if appended_chapter_map.key?(chapter) appended_chapter_map[chapter] = config end |
.appended_chapter_map ⇒ Object
49 50 51 |
# File 'lib/gamefic/plot.rb', line 49 def self.appended_chapter_map @appended_chapter_map ||= {} end |
Instance Method Details
#branch(subplot_class = Gamefic::Subplot, introduce: [], **config) ⇒ Gamefic::Subplot
Start a new subplot based on the provided class.
34 35 36 37 |
# File 'lib/gamefic/plot.rb', line 34 def branch subplot_class = Gamefic::Subplot, introduce: [], **config subplot_class.new(self, introduce: introduce, **config) .tap { |sub| subplots.push sub } end |
#find_and_bind(symbol) ⇒ Object
90 91 92 |
# File 'lib/gamefic/plot.rb', line 90 def find_and_bind(symbol) super + chapters.flat_map { |chap| chap.find_and_bind(symbol) } end |
#inspect ⇒ Object
39 40 41 |
# File 'lib/gamefic/plot.rb', line 39 def inspect "#<#{self.class}>" end |
#player_output_blocks ⇒ Object
74 75 76 |
# File 'lib/gamefic/plot.rb', line 74 def player_output_blocks super + subplots.flat_map(&:player_output_blocks) end |
#ready_blocks ⇒ Object
66 67 68 |
# File 'lib/gamefic/plot.rb', line 66 def ready_blocks super + subplots.flat_map(&:ready_blocks) end |
#responses ⇒ Object
78 79 80 |
# File 'lib/gamefic/plot.rb', line 78 def responses super + chapters.flat_map(&:responses) end |
#responses_for(*verbs) ⇒ Object
82 83 84 |
# File 'lib/gamefic/plot.rb', line 82 def responses_for(*verbs) super + chapters.flat_map { |chap| chap.responses_for(*verbs) } end |
#subplots ⇒ Array<Subplot>
Get an array of all the current subplots.
24 25 26 |
# File 'lib/gamefic/plot.rb', line 24 def subplots @subplots ||= [] end |
#syntaxes ⇒ Object
86 87 88 |
# File 'lib/gamefic/plot.rb', line 86 def syntaxes super + chapters.flat_map(&:syntaxes) end |
#turn ⇒ void
This method returns an undefined value.
Complete a game turn.
In addition to running its own applicable conclude blocks, the Plot class will also handle conclude blocks for its chapters and subplots.
59 60 61 62 63 64 |
# File 'lib/gamefic/plot.rb', line 59 def turn super subplots.each(&:conclude) if concluding? chapters.delete_if(&:concluding?) subplots.delete_if(&:concluding?) end |
#uncast(actor) ⇒ Object
16 17 18 19 |
# File 'lib/gamefic/plot.rb', line 16 def uncast(actor) subplots.each { |sp| sp.uncast actor } super end |
#update_blocks ⇒ Object
70 71 72 |
# File 'lib/gamefic/plot.rb', line 70 def update_blocks super + subplots.flat_map(&:update_blocks) end |