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
|
# File 'lib/gamefic/director/parser.rb', line 7
def self.from_tokens(actor, tokens)
options = []
command = tokens.shift
actions = actor.playbook.actions_for(command.to_sym)
actions.each { |action|
if action.queries.length == tokens.length
valid = true
index = 0
action.queries.each { |query|
if query.validate(actor, tokens[index]) == false
valid = false
break
end
index += 1
}
if valid
arguments = []
tokens.each { |token|
arguments.push [token]
}
options.push Order.new(actor, action, arguments)
end
end
}
if options.length == 0
tokens.unshift command
end
options.sort{ |a,b| b.action.specificity <=> a.action.specificity }
end
|