Class: Gamefic::Narrative
- Inherits:
-
Object
- Object
- Gamefic::Narrative
- 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.
Instance Attribute Summary
Attributes included from Scriptable::Scenes
#default_conclusion, #default_scene
Class Method Summary collapse
Instance Method Summary collapse
-
#cast(active) ⇒ Gamefic::Active
Add an active entity to the narrative.
-
#concluding? ⇒ Boolean
A narrative is considered to be concluding when all of its players are in a conclusion scene.
-
#initialize ⇒ Narrative
constructor
A new instance of Narrative.
-
#introduce(player = Gamefic::Actor.new) ⇒ Gamefic::Actor
Introduce an actor to the story.
- #save ⇒ String
-
#turn ⇒ void
Complete a game turn.
-
#uncast(active) ⇒ Gamefic::Active
Remove an active entity from the narrative.
Methods included from Scriptable
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
#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
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::Responses
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
Constructor Details
#initialize ⇒ Narrative
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
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.
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.
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.
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 |
#turn ⇒ void
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.
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 |