Advertisement
Double_X

(Ruby)RMMV Plugin JS Parser

Mar 2nd, 2016
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.21 KB | None | 0 0
  1. # Expected output from the default inputs
  2. plugin_entry = %Q({
  3.     "name" : "DoubleX RMMV Partitioned Random v100b",
  4.     "status" : true,
  5.     "description" : "Lets users changes the number of partitions the RNG being run per             Math.random() call to control the RNG distributions on the fly",
  6.     "parameters" : {
  7.         "parts" : "10"
  8.     }
  9. }, )
  10.  
  11. # Edit these
  12. PLUGIN_NAME = %Q("DoubleX RMMV Partitioned Random v100b")
  13. PLUGIN_STATUS = %Q(true)
  14. PLUGIN_PARAMS = %Q( * @plugindesc Lets users changes the number of partitions the RNG being run per
  15.  *             Math.random() call to control the RNG distributions on the fly
  16.  * @author DoubleX
  17.  *
  18.  * @param parts
  19.  * @desc RNG will be run under each of parts equal-sized partitions
  20.  *       No partition will be run under twice before they've all been run under
  21. *       parts shouldn't be too large nor too small to maximize the chance for
  22.  *       the RNG generated by Math.random() to be more evenly distributed
  23.  *       Larger parts means more resources(mainly time) needed to run it
  24.  * @default 10)
  25. OUTPUT_FILE = "RMMV Plugin.txt"
  26.  
  27. # Don't edit these
  28. data_field = nil
  29. params = true
  30. File.open(OUTPUT_FILE, "a") { |file|
  31.   file.print(%Q({\n    "name" : #{PLUGIN_NAME},\n))
  32.   file.print(%Q(    "status" : #{PLUGIN_STATUS},\n))
  33.   PLUGIN_PARAMS.split(/[\r\n]+/).each { |line|
  34.     line = line[2..-1]
  35.     next if !line || line.empty?
  36.     if line.include?(%Q(@plugindesc))
  37.       data_field = %Q("description")
  38.       next file.print(%Q(    "description" : "#{line.sub(/ @plugindesc /, "")}))
  39.    elsif line.include?(%Q(@author))
  40.      data_field = %Q("parameters")
  41.      next file.print(%Q(",\n    "parameters" : {))
  42.     elsif line.include?(%Q(@param))
  43.       data_field = %Q(#{line.sub(/ @param /, "")})
  44.       next file.print(%Q(",\n        "#{data_field}" : )) unless params
  45.       params = false
  46.       next file.print(%Q(\n        "#{data_field}" : ))
  47.     elsif line.include?(%Q(@default))
  48.       data_field = %Q(@default)
  49.       next file.print(%Q("#{line.sub(/ @default */, "")}))
  50.    end
  51.    next data_field = %Q(@desc) if line.include?(%Q(@desc))
  52.    file.print(line) if data_field != %Q(@desc)
  53.  }
  54.  file.print(params ? %Q(}\n}, ) : %Q("\n    }\n}, ))
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement