Class: Gamefic::Narrative

Inherits:
Object
  • Object
show all
Extended by:
Scriptable
Includes:
Logging, Scriptable::Actions, Scriptable::Entities, Scriptable::Events, Scriptable::Proxy, Scriptable::Queries, Scriptable::Scenes
Defined in:
lib/gamefic/narrative.rb

Overview

A base class for building and managing the resources that compose a story. The Plot and Subplot classes inherit from Narrative and provide additional functionality.

Direct Known Subclasses

Plot, Subplot

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, #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

#initializeNarrative

Returns a new instance of Narrative.



21
22
23
24
25
26
# File 'lib/gamefic/narrative.rb', line 21

def initialize
  self.class.included_blocks.select(&:seed?).each { |blk| Stage.run self, &blk.code }
  entity_vault.lock
  @rulebook = nil
  hydrate
end

Instance Attribute Details

#rulebookObject (readonly)

Returns the value of attribute rulebook.



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

def rulebook
  @rulebook
end

Class Method Details

.inherited(klass) ⇒ Object



99
100
101
102
# File 'lib/gamefic/narrative.rb', line 99

def self.inherited klass
  super
  klass.blocks.concat blocks
end

Instance Method Details

#attach(cache) ⇒ Object



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

def attach cache
  @rulebook = cache
end

#cast(active) ⇒ Gamefic::Active

Add an active entity to the narrative.

Parameters:

Returns:



56
57
58
59
60
61
# File 'lib/gamefic/narrative.rb', line 56

def cast active
  active.epic.add self
  player_vault.add active
  entity_vault.add active
  active
end

#concluding?Boolean

A narrative is considered to be concluding when all of its players are in a conclusion scene. Engines can use this method to determine whether the game is ready to end.

Returns:

  • (Boolean)


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

def concluding?
  players.empty? || players.all?(&:concluding?)
end

#detachObject

Returns:

  • (Object)


83
84
85
86
87
# File 'lib/gamefic/narrative.rb', line 83

def detach
  cache = @rulebook
  @rulebook = nil
  cache
end

#hydrateObject



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

def hydrate
  @rulebook = Rulebook.new(self)
  @rulebook.script_with_defaults
  @rulebook.freeze
end

#introduce(player = Gamefic::Actor.new) ⇒ Gamefic::Actor

Introduce an actor to the story.

Parameters:

Returns:



36
37
38
39
40
41
42
# File 'lib/gamefic/narrative.rb', line 36

def introduce(player = Gamefic::Actor.new)
  cast player
  rulebook.scenes.introductions.each do |scene|
    scene.run_start_blocks player, nil
  end
  player
end

#readyObject



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

def ready
  rulebook.run_ready_blocks
end

#scenesObject



28
29
30
# File 'lib/gamefic/narrative.rb', line 28

def scenes
  rulebook.scenes.names
end

#uncast(active) ⇒ Gamefic::Active

Remove an active entity from the narrative.

Parameters:

Returns:



67
68
69
70
71
72
# File 'lib/gamefic/narrative.rb', line 67

def uncast active
  active.epic.delete self
  player_vault.delete active
  entity_vault.delete active
  active
end

#updateObject



78
79
80
# File 'lib/gamefic/narrative.rb', line 78

def update
  rulebook.run_update_blocks
end