public
Description: voice commanded servant
Homepage:
Clone URL: git://github.com/floere/james.git
Click here to lend your support to: james and make a donation at www.pledgie.com !
Florian Hanke (author)
Mon Mar 31 11:29:51 -0700 2008
james / dialogue_plugin.rb
100755 66 lines (54 sloc) 1.334 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require 'rubycocoa'
 
# superclass for dialogue modules
# dialogues move along the moves
# if a state is entered, enter_#{state_name} is called
# if a state is exited, exit_#{state_name} is called
class DialoguePlugin
  
  # automatically adds a hook phrase
  # meaning: adds a move from :awake to this hook word
  # and also a method
  def initialize
    # actual state in this module
    @state = nil
    # defines possible moves from one state to another
    @moves = {
      
    }
  end
  
  # returns the possible states of this dialogue
  def possible_states
    @moves.keys
  end
  
  # next possible phrases
  def expects_phrases
    @moves[@state].keys
  end
  
  def next_state(phrase)
    @moves[@state][phrase]
  end
  
  def hear(phrase)
    # if next state
    return unless next_state(phrase)
    # call exit method
    response = send("exit_#{@state}".intern, phrase)
    say response
    # set actual state
    @state = next_state(phrase)
    # call entry method
    response = send("enter_#{@state}")
    say response
  end
  
  def say(text)
    # TODO blah
  end
  
  # hook words - these define when this dialogue is entered
  def hook_words(names = nil)
    names.each do |name|
       # TODO
    end
  end
  
  def initial_state(initial)
    define_method(:reset) do
      @state = initial
    end
  end
  
end