Class: Gamefic::Narrative

Inherits:
Object
  • Object
show all
Extended by:
Scriptable
Includes:
Scripting
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

Chapter, Plot, Subplot

Instance Attribute Summary

Attributes included from Scriptable::Scenes

#default_conclusion, #default_scene

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Scriptable

included_scripts, pick, pick!

Methods included from Scriptable::Syntaxes

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

#meta, #respond, #responses, #responses_for, #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, #player_output_blocks, #ready_blocks, #update_blocks

Methods included from Scripting

#find_and_bind, included, #included_scripts

Methods included from Scripting::Syntaxes

#synonyms, #syntaxes

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::Responses

#responses, #responses_for

Methods included from Scripting::Hooks

#after_commands, #before_commands, #conclude_blocks, #player_conclude_blocks, #player_output_blocks, #ready_blocks, #update_blocks

Methods included from Scripting::Entities

#destroy, #entities, #find, #make, #pick, #pick!, #players

Methods included from Scripting::Proxies

#unproxy

Constructor Details

#initializeNarrative

Returns a new instance of Narrative.



17
18
19
# File 'lib/gamefic/narrative.rb', line 17

def initialize
  seeds.each { |blk| instance_exec(&blk) }
end

Class Method Details

.inherited(klass) ⇒ Object



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

def self.inherited(klass)
  super
  klass.seeds.concat seeds
  klass.select_default_scene default_scene
  klass.select_default_conclusion default_conclusion
end

.restore(snapshot) ⇒ self

Parameters:

Returns:

  • (self)


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

def self.restore(snapshot)
  Marshal.load(snapshot)
end

Instance Method Details

#cast(active) ⇒ Gamefic::Active

Add an active entity to the narrative.

Parameters:

Returns:



43
44
45
46
47
48
# File 'lib/gamefic/narrative.rb', line 43

def cast(active)
  active.narratives.add self
  player_set.add active
  entity_set.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)


35
36
37
# File 'lib/gamefic/narrative.rb', line 35

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

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

Introduce an actor to the story.

Parameters:

Returns:



25
26
27
28
29
# File 'lib/gamefic/narrative.rb', line 25

def introduce(player = Gamefic::Actor.new)
  cast player
  introductions.each { |blk| blk[player] }
  player
end

#saveString

Returns:



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

def save
  Marshal.dump(self)
end

#turnvoid

This method returns an undefined value.

Complete a game turn.

In the base Narrative class, this method runs all applicable player conclude blocks and the narrative’s own conclude blocks.



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

def turn
  players.select(&:concluding?).each { |plyr| player_conclude_blocks.each { |blk| blk[plyr] } }
  conclude_blocks.each(&:call) if concluding?
end

#uncast(active) ⇒ Gamefic::Active

Remove an active entity from the narrative.

Parameters:

Returns:



54
55
56
57
58
59
# File 'lib/gamefic/narrative.rb', line 54

def uncast(active)
  active.narratives.delete self
  player_set.delete active
  entity_set.delete active
  active
end