class Gamefic::Narrative
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.
Public Class Methods
Source
# 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
Source
# File lib/gamefic/narrative.rb, line 17 def initialize seeds.each { |blk| instance_exec(&blk) } end
Source
# File lib/gamefic/narrative.rb, line 79 def self.restore(snapshot) Marshal.load(snapshot) end
@param snapshot [String] @return [self]
Public Instance Methods
Source
# File lib/gamefic/narrative.rb, line 43 def cast(active) active.narratives.add self player_set.add active entity_set.add active active end
Add an active entity to the narrative.
@param active [Gamefic::Active] @return [Gamefic::Active]
Source
# File lib/gamefic/narrative.rb, line 35 def concluding? players.empty? || players.all?(&:concluding?) end
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.
Source
# File lib/gamefic/narrative.rb, line 25 def introduce(player = Gamefic::Actor.new) cast player introductions.each { |blk| blk[player] } player end
Introduce an actor to the story.
@param player [Gamefic::Actor] @return [Gamefic::Actor]
Source
# File lib/gamefic/narrative.rb, line 73 def save Marshal.dump(self) end
@return [String]
Source
# 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
Complete a game turn.
In the base Narrative
class, this method runs all applicable player conclude blocks and the narrative’s own conclude blocks.
@return [void]
Source
# File lib/gamefic/narrative.rb, line 54 def uncast(active) active.narratives.delete self player_set.delete active entity_set.delete active active end
Remove an active entity from the narrative.
@param active [Gamefic::Active] @return [Gamefic::Active]