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 collapse

Attributes included from Scriptable::Scenes

#default_conclusion, #default_scene

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Narrative

#cast, #concluding?, inherited, #introduce, restore, #save

Methods included from Scriptable

#included_scripts, #pick, #pick!

Methods included from Scriptable::Syntaxes

#interpret

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

#meta, #respond, #verbs

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

included, #included_scripts

Methods included from Scripting::Syntaxes

#synonyms

Methods included from Scripting::Scenes

#default_conclusion, #default_scene, #introductions, #named_scenes, #prepare, #scene_class, #scenes

Methods included from Scripting::Seeds

#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

#unproxy

Constructor Details

#initializePlot

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

#chaptersArray<Chapter> (readonly)

Returns:



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

def chapters
  @chapters
end

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_mapObject



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.

Parameters:

Returns:



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

#inspectObject



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

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

#player_output_blocksObject



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

def player_output_blocks
  super + subplots.flat_map(&:player_output_blocks)
end

#ready_blocksObject



66
67
68
# File 'lib/gamefic/plot.rb', line 66

def ready_blocks
  super + subplots.flat_map(&:ready_blocks)
end

#responsesObject



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

#subplotsArray<Subplot>

Get an array of all the current subplots.

Returns:



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

def subplots
  @subplots ||= []
end

#syntaxesObject



86
87
88
# File 'lib/gamefic/plot.rb', line 86

def syntaxes
  super + chapters.flat_map(&:syntaxes)
end

#turnvoid

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_blocksObject



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

def update_blocks
  super + subplots.flat_map(&:update_blocks)
end