Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module DialogTree
- @@conversations = {}
- @@debug = false
- @@eventid = 0
- def self.debug=(val)
- @@debug = val
- end
- def self.conversations
- @@conversations
- end
- def self.run_conversation(id, eventid = 0)
- @@eventid = eventid
- @@conversations[id].execute
- end
- class Actor
- attr_accessor :id
- attr_accessor :name
- attr_accessor :picture
- def initialize(id, name, picture)
- @id = id
- @name = name
- @picture = picture
- end
- end
- class DialogNode
- attr_accessor :id
- attr_accessor :mood
- attr_accessor :script
- attr_accessor :children
- attr_accessor :dialog
- attr_accessor :actor
- def initialize(id, dialog, script, mood, actor)
- @id = id
- @dialog = dialog
- @script = script
- @mood = mood
- @actor = actor
- @children = []
- end
- def execute
- eval(@script)
- if @script != nil && @script != ''
- puts "Running "+@script
- end
- DialogTree::put_message(@dialog, @actor, @mood)
- if(@children.length > 0)
- puts @id.to_s + " -> " + @children[0].id.to_s
- @children[0].execute
- end
- end
- end
- class DecisionNode
- attr_accessor :id
- attr_accessor :condition
- attr_accessor :children
- def initialize(id, condition)
- @id = id
- @condition = condition
- @children = []
- end
- def execute
- val = eval(@condition)
- puts @condition+ "==" + val.to_s
- if val
- @children[1].execute
- else
- @children[0].execute
- end
- end
- end
- class Conversation
- attr_accessor :id
- attr_accessor :title
- attr_accessor :root
- def initialize(id, root, title)
- @id = id
- @title = title
- @root = root
- end
- def execute
- @root.children[0].execute()
- end
- end
- def self.load_dialog_file(filename)
- File.open(filename,'r') do|file|
- @@conversations = Marshal.load(file)
- end
- end
- def self.put_message(str, actor, mood)
- strings = str.split("\r\n")
- script_line = -1
- strings.each_with_index { |text, index|
- t = text.strip
- if t == '\\script'
- puts index.to_s
- script_line = index
- end
- }
- puts script_line.to_s
- if @@debug
- if script_line > -1
- strings[0..(script_line-1)].each { |text|
- if actor != nil
- puts(actor.name + "("+mood.to_s+")" ": "+text)
- else
- puts(text)
- end
- }
- eval(strings[(script_line+1)..strings.length].join("\r\n"))
- else
- strings.each { |text|
- if actor != nil
- puts(actor.name + "("+mood.to_s+")" ": "+text)
- else
- puts(text)
- end
- }
- end
- else
- if actor != nil && actor.name != ''
- $game_message.face_name = actor.name
- else
- $game_message.face_name = ''
- end
- if script_line == 0
- eval(strings[(script_line+1)..strings.length].join("\r\n"))
- elsif script_line > -1
- strings[0..(script_line-1)].each { |text|
- $game_message.add(text)
- }
- eval(strings[(script_line+1)..strings.length].join("\r\n"))
- else
- strings.each { |text|
- $game_message.add(text)
- }
- end
- while $game_message.has_text?
- $gi.wait(1)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement