Class: Fictive::Story

Inherits:
Object
  • Object
show all
Defined in:
lib/fictive/story.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(graph, start_id) ⇒ Story

Returns a new instance of Story.



33
34
35
36
37
38
39
40
41
42
43
# 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

Class Method Details

._demoObject



3
4
5
6
7
8
# 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

.demoObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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

Instance Method Details

#choose_path(id) ⇒ Object



64
65
66
67
# File 'lib/fictive/story.rb', line 64

def choose_path(id)
  @current = @graph.edge(id).to
  Passage.new(@current)
end

#has_next?Boolean

Returns:

  • (Boolean)


55
56
57
58
# File 'lib/fictive/story.rb', line 55

def has_next?
  #[email protected](@index).nil? && [email protected](@index + 1).nil?
  @current.out_e.all.count > 0
end

#nextObject



60
61
62
# File 'lib/fictive/story.rb', line 60

def next
  Passage.new(@current)
end

#resumeObject

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



51
52
53
# File 'lib/fictive/story.rb', line 51

def resume
  # TODO
end

#startObject

Initiate a new story graph traversal from the starting point.



46
47
48
# File 'lib/fictive/story.rb', line 46

def start
  # TODO
end