class Fictive::Story

Public Class Methods

_demo() click to toggle source
# File lib/fictive/story.rb, line 3
def self._demo
  self.new([
    Passage.new({id: 'hello', choices: [Choice.new({id: 'goodbye'})]}, 'Hello world'),
    Passage.new({id: 'goodbye'}, 'Goodbye world')
  ])
end
demo() click to toggle source
# File lib/fictive/story.rb, line 10
def self.demo
  self.new(Mementus::Graph.new do
    create_node do |node|
      node.id = 'hello'
      node[:text] = 'Hello world'
      node.label = :passage
    end

    create_node do |node|
      node.id = 'goodbye'
      node[:text] = 'Goodbye world'
      node.label = :passage
    end

    create_edge do |edge|
      edge.id = 'say_goodbye'
      edge.from = 'hello'
      edge.to = 'goodbye'
      edge.label = :choice
    end
  end, 'hello')
end
new(graph, start_id) click to toggle source
# File lib/fictive/story.rb, line 33
def initialize(graph, start_id)
  # @passages = passages
  # @passages_index = {}
  # @passages.each_with_index do |passage, id|
  #   @passages_index[passage.id] = id
  # end
  #
  # @index = 0
  @graph = graph
  @current = graph.n(start_id)
end

Public Instance Methods

choose_path(id) click to toggle source
# File lib/fictive/story.rb, line 64
def choose_path(id)
  @current = @graph.edge(id).to
  Passage.new(@current)
end
has_next?() click to toggle source
# File lib/fictive/story.rb, line 55
def has_next?
  #!@passages.at(@index).nil? && !@passages.at(@index + 1).nil?
  @current.out_e.all.count > 0
end
next() click to toggle source
# File lib/fictive/story.rb, line 60
def next
  Passage.new(@current)
end
resume() click to toggle source

Resume a story graph traversal from a bookmarked place in the story.

# File lib/fictive/story.rb, line 51
def resume
  # TODO
end
start() click to toggle source

Initiate a new story graph traversal from the starting point.

# File lib/fictive/story.rb, line 46
def start
  # TODO
end