lib/gamefic/plot.rb in gamefic-1.3.2 vs lib/gamefic/plot.rb in gamefic-1.4.0
- old
+ new
@@ -65,19 +65,19 @@
scenes[actor.scene].kind_of?(Scene::Conclusion)
end
# Get an Array of all Actions defined in the Plot.
#
- # @return Array[Action]
+ # @return [Array<Action>]
def actions
@commands.values.flatten
end
# Get an Array of all Actions associated with the specified verb.
#
# @param verb [Symbol] The Symbol for the verb (e.g., :go or :look)
- # @return Array<Action> The verb's associated Actions
+ # @return [Array<Action>] The verb's associated Actions
def actions_with_verb(verb)
@commands[verb].clone || []
end
# Get an Array of all scripts that have been imported into the Plot.
@@ -200,34 +200,24 @@
end
# Update the Plot's current turn of gameplay.
# This method is typically called by the Engine that manages game execution.
def update
- # Update the plot.
@players.each { |player|
- # TODO: This really doesn't belong here. We need a before_update in the plot.
- @before_player_update_procs.each { |p|
- p.call player
- }
- this_scene = player.next_scene || player.scene
- player.prepare nil
- if this_scene != player.scene
- player.cue this_scene
- player.queue.shift
- else
+ @before_player_update_procs.each { |p| p.call player }
+ this_scene = player.next_scene || player.scene
+ player.prepare nil
+ if this_scene != player.scene
+ player.cue this_scene
+ player.queue.shift
+ else
process_input player
end
}
- @entities.each { |e|
- e.update
- }
- @players.each { |player|
- update_player player
- }
- @update_procs.each { |p|
- p.call
- }
+ @entities.each { |e| e.update }
+ @players.each { |player| update_player player }
+ @update_procs.each { |p| p.call }
end
def tell entities, message, refresh = false
entities.each { |entity|
entity.tell message, refresh
@@ -292,17 +282,18 @@
proc.call player
}
end
def rem_entity(entity)
@entities.delete(entity)
+ @players.delete(entity)
end
def recursive_update(entity)
entity.update
entity.children.each { |e|
recursive_update e
}
- end
+ end
def add_syntax syntax
if @commands[syntax.verb] == nil
raise "Action \"#{syntax.verb}\" does not exist."
end
# Delete duplicate syntaxes
@@ -315,28 +306,29 @@
# For syntaxes of the same length, length of action takes precedence
b.first_word <=> a.first_word
else
b.token_count <=> a.token_count
end
- }
+ }
end
def add_action(action)
- if (@commands[action.verb] == nil)
- @commands[action.verb] = Array.new
- end
+ @commands[action.verb] ||= []
@commands[action.verb].unshift action
@commands[action.verb].sort! { |a, b|
if a.specificity == b.specificity
# Newer action takes precedence
b.order_key <=> a.order_key
else
# Higher specificity takes precedence
b.specificity <=> a.specificity
end
}
+ generate_default_syntax action
+ end
+ def generate_default_syntax action
user_friendly = action.verb.to_s.gsub(/_/, ' ')
- args = Array.new
- used_names = Array.new
+ args = []
+ used_names = []
action.queries.each { |c|
num = 1
new_name = ":var"
while used_names.include? new_name
num = num + 1