Class: Gamefic::Narrative
- Inherits:
-
Object
- Object
- Gamefic::Narrative
- 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.
Instance Attribute Summary collapse
-
#rulebook ⇒ Object
readonly
Returns the value of attribute rulebook.
Class Method Summary collapse
Instance Method Summary collapse
- #attach(cache) ⇒ Object
-
#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.
- #detach ⇒ Object
- #hydrate ⇒ Object
-
#initialize ⇒ Narrative
constructor
A new instance of Narrative.
-
#introduce(player = Gamefic::Actor.new) ⇒ Gamefic::Actor
Introduce an actor to the story.
- #ready ⇒ Object
- #scenes ⇒ Object
-
#uncast(active) ⇒ Gamefic::Active
Remove an active entity from the narrative.
- #update ⇒ Object
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
Methods included from Scriptable::Entities
#destroy, #entities, #entity_vault, #make, #pick, #pick!, #player_vault, #players
Methods included from Logging
Constructor Details
Instance Attribute Details
#rulebook ⇒ Object (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.
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.
48 49 50 |
# File 'lib/gamefic/narrative.rb', line 48 def concluding? players.empty? || players.all?(&:concluding?) end |
#detach ⇒ Object
83 84 85 86 87 |
# File 'lib/gamefic/narrative.rb', line 83 def detach cache = @rulebook @rulebook = nil cache end |
#hydrate ⇒ Object
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.
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 |
#ready ⇒ Object
74 75 76 |
# File 'lib/gamefic/narrative.rb', line 74 def ready rulebook.run_ready_blocks end |
#scenes ⇒ Object
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.
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 |
#update ⇒ Object
78 79 80 |
# File 'lib/gamefic/narrative.rb', line 78 def update rulebook.run_update_blocks end |