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.

Attributes

rulebook[R]

Public Class Methods

inherited(klass) click to toggle source
Calls superclass method
# File lib/gamefic/narrative.rb, line 121
def self.inherited klass
  super
  klass.blocks.concat blocks
end
new(hydrate: true) click to toggle source
# File lib/gamefic/narrative.rb, line 23
def initialize(hydrate: true)
  return unless hydrate

  seed
  script
  post_script
end

Public Instance Methods

attach(cache) click to toggle source
# File lib/gamefic/narrative.rb, line 112
def attach cache
  @rulebook = cache
end
cast(active) click to toggle source

Add an active entity to the narrative.

@param [Gamefic::Active] @return [Gamefic::Active]

# 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?() click to toggle source

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.

# File lib/gamefic/narrative.rb, line 71
def concluding?
  players.empty? || players.all?(&:concluding?)
end
detach() click to toggle source

@return [Object]

# File lib/gamefic/narrative.rb, line 106
def detach
  cache = @rulebook
  @rulebook = nil
  cache
end
hydrate() click to toggle source
# File lib/gamefic/narrative.rb, line 116
def hydrate
  script
  post_script
end
included_blocks() click to toggle source

@return [Array<Module>]

# File lib/gamefic/narrative.rb, line 41
def included_blocks
  self.class.included_blocks
end
introduce(player = Gamefic::Actor.new) click to toggle source

Introduce an actor to the story.

@param player [Gamefic::Actor] @return [Gamefic::Actor]

# 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() click to toggle source
# File lib/gamefic/narrative.rb, line 45
def post_script
  entity_vault.lock
  rulebook.freeze
end
ready() click to toggle source
# File lib/gamefic/narrative.rb, line 97
def ready
  rulebook.run_ready_blocks
end
scenes() click to toggle source

@return [Array<Symbol>]

# File lib/gamefic/narrative.rb, line 51
def scenes
  rulebook.scenes.names
end
script() click to toggle source
# 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() click to toggle source
# File lib/gamefic/narrative.rb, line 31
def seed
  included_blocks.select(&:seed?).each { |blk| Stage.run self, &blk.code }
end
uncast(active) click to toggle source

Remove an active entity from the narrative.

@param [Gamefic::Active] @return [Gamefic::Active]

# 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() click to toggle source
# File lib/gamefic/narrative.rb, line 101
def update
  rulebook.run_update_blocks
end