注释调用系统接入包 1.0 [VX]

#==============================================================================
# ■ 注释调用系统接入包 1.0 [VX]
#   http://orzFly.com/RM/PowerComments
#------------------------------------------------------------------------------
# 为插件脚本的注释调用提供支持。需配合其他脚本使用。
#------------------------------------------------------------------------------
# PowerComments.register_command(args, proc)
#   - args 为 Regexp 或包含 Regexp 的 Array
#   - proc 为 Proc 对象
#          当 args 中任意一个 Regexp 对象能匹配事件注释中的文字时,将会调用 proc
#          调用 proc 时,将会传递下列参数:
#            o 当前事件解释器实例
#            o 成功匹配的 Regexp 的 last_match 数组
#
#          proc 的返回值将决定事件解释器的下一步动作
#            o 若 proc 的执行结果是 true
#                当前事件解释器实例 powercomments_repeat_count 归零
#                将继续执行事件中下一指令
#            o 若 proc 的执行结果是 false
#                当前事件解释器实例 powercomments_repeat_count 累加(+= 1)
#                将重复执行事件中当前指令
#------------------------------------------------------------------------------
# - 1.0 [VX] by orzFly [[email protected]]
#   * 首个版本
#==============================================================================
module PowerComments
  Version = "1.0"
  Commands = {}

  module_function
  def register_command(args, proc)
    if args.is_a?(Array)
      args.each { |arg| register_command_single(arg, proc) }
    else
      register_command_single(args, proc)
    end
  end
  def register_command_single(regexp, proc)
    if Commands.include?(regexp)
      raise("PowerComments Command " + regexp.to_s + " already exists")
    end
    Commands[regexp] = proc
  end
end 

class Game_Interpreter
  alias :execute_command_powercomment :execute_command
  def execute_command
    if @index >= @list.size-1
      command_end
      return true
    else
      @params = @list[@index].parameters
      @indent = @list[@index].indent
      case @list[@index].code
        when 108
          return powercomments(@params[0])
        else
          return execute_command_powercomment
        return true
      end
    end
  end

  def powercomments(text)
    PowerComments::Commands.each {|k, v|
      if k =~ text
        result = v.call(self, *Regexp.last_match.to_a)
        @powercomments_repeat_count += 1 unless result
        @powercomments_repeat_count = 0 if result
        return result
      end
    }
    return true
  end

  attr_accessor :wait_count

  def powercomments_repeat_count
    return @powercomments_repeat_count.nil? ? 0 : @powercomments_repeat_count
  end

  def powercomments_repeat_count=(value)
    @powercomments_repeat_count = value
  end
end

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>