Class: Gamefic::Narrative
- Inherits:
-
Object
- Object
- Gamefic::Narrative
- Extended by:
- Scriptable
- Includes:
- Logging, Scriptable::Actions, Scriptable::Entities, Scriptable::Events, Scriptable::Proxies, 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
- #included_blocks ⇒ Array<Module>
-
#initialize(hydrate: true) ⇒ Narrative
constructor
A new instance of Narrative.
-
#introduce(player = Gamefic::Actor.new) ⇒ Gamefic::Actor
Introduce an actor to the story.
- #post_script ⇒ Object
- #ready ⇒ Object
- #scenes ⇒ Array<Symbol>
- #script ⇒ Object
- #seed ⇒ Object
-
#uncast(active) ⇒ Gamefic::Active
Remove an active entity from the narrative.
- #update ⇒ Object
Methods included from Scriptable
attr_seed, blocks, lazy_attr, lazy_ivar, make_seed, method_missing, no_scripts, pick, pick!, proxy, respond_to_missing?
Methods included from Scriptable::Scenes
#block, #conclusion, #introduction, #multiple_choice, #pause, #preface, #scene, #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
#abstract, #anywhere, #available, #children, #descendants, #myself, #parent, #plaintext, #siblings
Methods included from Scriptable::Proxies
Methods included from Scriptable::Entities
#destroy, #entities, #entity_vault, #find, #make, #pick, #pick!, #player_vault, #players
Methods included from Logging
Constructor Details
#initialize(hydrate: true) ⇒ Narrative
Returns a new instance of Narrative.
23 24 25 26 27 28 29 |
# File 'lib/gamefic/narrative.rb', line 23 def initialize(hydrate: true) return unless hydrate seed script post_script end |
Instance Attribute Details
#rulebook ⇒ Object (readonly)
Returns the value of attribute rulebook.
21 22 23 |
# File 'lib/gamefic/narrative.rb', line 21 def rulebook @rulebook end |
Class Method Details
.inherited(klass) ⇒ Object
121 122 123 124 |
# File 'lib/gamefic/narrative.rb', line 121 def self.inherited klass super klass.blocks.concat blocks end |
Instance Method Details
#attach(cache) ⇒ Object
112 113 114 |
# File 'lib/gamefic/narrative.rb', line 112 def attach cache @rulebook = cache end |
#cast(active) ⇒ Gamefic::Active
Add an active entity to the narrative.
79 80 81 82 83 84 |
# File 'lib/gamefic/narrative.rb', line 79 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.
71 72 73 |
# File 'lib/gamefic/narrative.rb', line 71 def concluding? players.empty? || players.all?(&:concluding?) end |
#detach ⇒ Object
106 107 108 109 110 |
# File 'lib/gamefic/narrative.rb', line 106 def detach cache = @rulebook @rulebook = nil cache end |
#hydrate ⇒ Object
116 117 118 119 |
# File 'lib/gamefic/narrative.rb', line 116 def hydrate script post_script end |
#included_blocks ⇒ Array<Module>
41 42 43 |
# File 'lib/gamefic/narrative.rb', line 41 def included_blocks self.class.included_blocks end |
#introduce(player = Gamefic::Actor.new) ⇒ Gamefic::Actor
Introduce an actor to the story.
59 60 61 62 63 64 65 |
# File 'lib/gamefic/narrative.rb', line 59 def introduce(player = Gamefic::Actor.new) cast player rulebook.scenes.introductions.each do |scene| scene.run_start_blocks player, nil end player end |
#post_script ⇒ Object
45 46 47 48 |
# File 'lib/gamefic/narrative.rb', line 45 def post_script entity_vault.lock rulebook.freeze end |
#ready ⇒ Object
97 98 99 |
# File 'lib/gamefic/narrative.rb', line 97 def ready rulebook.run_ready_blocks end |
#scenes ⇒ Array<Symbol>
51 52 53 |
# File 'lib/gamefic/narrative.rb', line 51 def scenes rulebook.scenes.names end |
#script ⇒ Object
35 36 37 38 |
# File 'lib/gamefic/narrative.rb', line 35 def script @rulebook = Rulebook.new included_blocks.select(&:script?).each { |blk| Stage.run self, &blk.code } end |
#seed ⇒ Object
31 32 33 |
# File 'lib/gamefic/narrative.rb', line 31 def seed included_blocks.select(&:seed?).each { |blk| Stage.run self, &blk.code } end |
#uncast(active) ⇒ Gamefic::Active
Remove an active entity from the narrative.
90 91 92 93 94 95 |
# File 'lib/gamefic/narrative.rb', line 90 def uncast active active.epic.delete self player_vault.delete active entity_vault.delete active active end |
#update ⇒ Object
101 102 103 |
# File 'lib/gamefic/narrative.rb', line 101 def update rulebook.run_update_blocks end |