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?, inherited, #initialize, #introduce, #scenes

Methods included from Scriptable

#attr_seed, #blocks, #included_blocks, #make_seed, #method_missing, #no_scripts, #respond_to_missing?, #script, #seed

Methods included from Scriptable::Scenes

#block, #conclusion, #introduction, #multiple_choice, #pause, #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

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

Methods included from Scriptable::Proxy

#proxy, #unproxy

Methods included from Scriptable::Entities

#destroy, #entities, #entity_vault, #make, #pick, #pick!, #player_vault, #players

Methods included from Logging

logger

Constructor Details

This class inherits a constructor from Gamefic::Narrative

Class Method Details

.restore(data) ⇒ Object



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

def self.restore data
  Snapshot.restore data
end

Instance Method Details

#attach(cache) ⇒ Object



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

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:



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

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

#detachObject



60
61
62
63
64
65
# File 'lib/gamefic/plot.rb', line 60

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

#hydrateObject



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

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

#inspectObject



56
57
58
# File 'lib/gamefic/plot.rb', line 56

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

#readyObject



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

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

#saveObject



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

def save
  Snapshot.save self
end

#subplotsArray<Subplot>

Get an array of all the current subplots.

Returns:



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

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:



29
30
31
32
# File 'lib/gamefic/plot.rb', line 29

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

#updateObject



16
17
18
19
20
# File 'lib/gamefic/plot.rb', line 16

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