lib/gamefic/world/playbook.rb in gamefic-2.2.3 vs lib/gamefic/world/playbook.rb in gamefic-2.3.0
- old
+ new
@@ -8,23 +8,30 @@
# An array of available syntaxes.
#
# @return [Array<Gamefic::Syntax>]
attr_reader :syntaxes
- # An array of defined validators.
+ # An array of blocks to execute before actions.
#
# @return [Array<Proc>]
- attr_reader :validators
+ attr_reader :before_actions
+ # An array of blocks to execute after actions.
+ #
+ # @return [Array<Proc>]
+ attr_reader :after_actions
+
# @param commands [Hash]
# @param syntaxes [Array<Syntax>, Set<Syntax>]
- # @param validators [Array]
- def initialize commands: {}, syntaxes: [], validators: []
+ # @param before_actions [Array]
+ # @param after_actions [Array]
+ def initialize commands: {}, syntaxes: [], before_actions: [], after_actions: []
@commands = commands
@syntax_set = syntaxes.to_set
sort_syntaxes
- @validators = validators
+ @before_actions = before_actions
+ @after_actions = after_actions
end
# An array of available actions.
#
# @return [Array<Gamefic::Action>]
@@ -37,13 +44,22 @@
# @return [Array<Symbol>]
def verbs
@commands.keys
end
- # Add a block that determines whether an action can be executed.
+ # Add a proc to be evaluated before a character executes an action.
#
- def validate &block
- @validators.push block
+ # @yieldparam [Gamefic::Action]
+ def before_action &block
+ @before_actions.push block
+ end
+ alias validate before_action
+
+ # Add a proc to be evaluated after a character executes an action.
+ #
+ # @yieldparam [Gamefic::Action]
+ def after_action &block
+ @after_actions.push block
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)