class Mementus::Library::StoryGraph
Demo of an interactive fiction story with passages represented as nodes and choices represented as edges.
Public Class Methods
instance()
click to toggle source
# File lib/mementus/library/story_graph.rb, line 6 def self.instance self.new do create_node do |node| node.id = "start" node.label = :passage node.props[:text] = "The start of a story." end create_node do |node| node.id = "happy-ending" node.label = :passage node.props[:text] = "A happy ending." end create_node do |node| node.id = "tragic-ending" node.label = :passage node.props[:text] = "A tragic ending." end create_edge do |edge| edge.id = "happy-choice" edge.label = :choice edge.from = "start" edge.to = "happy-ending" edge.props[:text] = "Choose wisely." edge.props[:happiness] = 1 end create_edge do |edge| edge.id = "tragic-choice" edge.label = :choice edge.from = "start" edge.to = "tragic-ending" edge.props[:text] = "Choose poorly." edge.props[:happiness] = -1 end end end