a-moonless-night

AMN - Debug - Search

Nov 25th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 18.91 KB | None | 0 0
  1. =begin
  2. #==============================================================================#
  3. #   AMN - Debug - Search
  4. #   Version 1.00
  5. #   Author: AMoonlessNight
  6. #   Date: 26 Nov 2018
  7. #   Latest: 26 Nov 2018
  8. #==============================================================================#
  9. #   UPDATE LOG
  10. #------------------------------------------------------------------------------#
  11. # 26 Nov 2018 - created the script
  12. #==============================================================================#
  13. #   TERMS OF USE
  14. #------------------------------------------------------------------------------#
  15. # - Please credit AMoonlessNight or A-Moonless-Night
  16. # - Free for non-commercial and commercial use
  17. # - I'd love to see your game if you end up using one of my scripts
  18. #==============================================================================#
  19.  
  20. This script is a debugging tool to search through the various texts throughout
  21. the game for a keyword of your choice.
  22.  
  23. This could be useful for finding how many times you use a particular word, or
  24. finding certain words with the intention of changing them later.
  25.  
  26. Use the following script call:
  27.   AMN_Debug.check_ref("x", match)   OR  AMN_Debug.check_ref(x)
  28. where x is the keyword of your choice and match is either true or false.
  29.  
  30. If match is set to true, the game will search for matched case (e.g. ExAmPlEs).
  31. If you leave match out, it will automatically set to false.
  32.  
  33. Data is exported to the following file:
  34.   ref_check x.txt
  35. where x is the keyword that you checked for.
  36.  
  37. You will find it in your project's main folder after running the script call.
  38.  
  39. Please note:
  40.   This script does not offer options for changing the data. You must go into
  41.   the game and do that yourself. It's purely for viewing the selected data in
  42.   one place.
  43.  
  44.   You should remove this script upon releasing your game.
  45.  
  46. #-------------------------------------------------------------------------------
  47.   ** LIST OF TEXT FIELDS CHECKED:
  48. #-------------------------------------------------------------------------------
  49.   ** Database:
  50.       * Actors:
  51.             Name
  52.             Nickname
  53.             Notebox
  54.       * Classes:
  55.             Name
  56.             Notebox
  57.       * Skills:
  58.             Name
  59.             Description
  60.             Notebox
  61.             Message 1
  62.             Message 2
  63.       * Items:
  64.             Name
  65.             Description
  66.             Notebox
  67.       * Weapons:
  68.             Name
  69.             Description
  70.             Notebox
  71.       * Armour:
  72.             Name
  73.             Description
  74.             Notebox
  75.       * Enemies:
  76.             Name
  77.             Description
  78.             Notebox
  79.       * Troops:
  80.           * Each page:
  81.               Comments
  82.               Text + scrolling text
  83.               Choices
  84.               Script calls
  85.       * States:
  86.             Name
  87.             Notebox
  88.             Message 1
  89.             Message 2
  90.             Message 3
  91.             Message 4
  92.       * Tilesets:
  93.             Notebox
  94.       * Common Events:
  95.             Name
  96.             Comments
  97.             Text + scrolling text
  98.             Choices
  99.             Script calls
  100.       * System:
  101.             Game title
  102.             Currency unit
  103.       * Terms:
  104.             Elements
  105.             Weapon Types
  106.             Skill Types
  107.             Armour Types
  108.             Basic Status
  109.             Parameters
  110.             Equip Types
  111.             Commands
  112.   ** Maps:
  113.       Display name
  114.       Notebox
  115.       * Each event:
  116.           Name
  117.           * Each page:
  118.               Comments
  119.               Text + scrolling text
  120.               Choices
  121.               Script calls
  122.  
  123. =end
  124.  
  125. #==============================================================================
  126. #  Please do not edit below this point unless you know what you are doing.
  127. #==============================================================================
  128.  
  129. module AMN_Debug
  130.   def self.check_ref(string, match = false)
  131.     @total_matches = 0
  132.     result = ""
  133.     string = match ? string : string.downcase
  134.     fstring = string.tr('/:*?"<>|', 'x'); fstring.gsub!(/\\/, 'x')
  135.     file_name = "ref_check " + fstring + ".txt"
  136.     File.delete(file_name) if File.exist?(file_name)
  137.     result << check_variable_values(string, match)
  138.     result << $data_system.check_ref(string, match)
  139.     groups = [$data_actors, $data_classes, $data_skills, $data_items,
  140.               $data_weapons, $data_armors, $data_enemies, $data_troops,
  141.               $data_states, $data_tilesets, $data_common_events]
  142.     for group in groups
  143.       for obj in group
  144.         next if obj.nil?
  145.         result << obj.check_ref(string, match)
  146.       end
  147.     end
  148.     $data_mapinfos.keys.sort.each do |k|
  149.       map = load_data(sprintf("Data/Map%03d.rvdata2", k))
  150.       result << map.check_ref(string, match, k)
  151.     end
  152.     result << "\n\n Total Matches: #{@total_matches}"
  153.     File.open(file_name, "a+") do |f|
  154.       f << result
  155.     end
  156.     puts "AMN Debug - scan complete: see '#{file_name}' in your game folder."
  157.   end
  158.  
  159.   def self.check_variable_values(string, match)
  160.     title = "\nLocation: Variables\n"
  161.     result = ""
  162.     for i in 1...$data_system.variables.size
  163.       res = scan($game_variables[i], string, match)
  164.       result << match_vocab("  Variable #{i}", res) unless res.empty?
  165.     end
  166.     return title + result unless result.empty?
  167.     return result
  168.   end
  169.  
  170.   def self.scan(obj, string, match)
  171.     return [] unless obj.is_a?(String)
  172.     r = match ? obj.scan(string) : obj.downcase.scan(string)
  173.     @total_matches += r.length
  174.     return r
  175.   end
  176.  
  177.   def self.array_scan(array, string, match)
  178.     arr = []
  179.     array.each do |i|
  180.       r = scan(i, string, match)
  181.       arr << r
  182.     end
  183.     return arr.flatten
  184.   end
  185.  
  186.   def self.match_vocab(title, amt)
  187.     match = amt.length > 1 ? "%d matches" %[amt.length] : "%d match" %[amt.length]
  188.     list = "\n    Word matches: " + amt.join(", ")
  189.     sprintf("%s: %s  %s\n", title, match, list)
  190.   end
  191.  
  192. end
  193.  
  194. module RPG
  195.   class System
  196.     def check_ref(string, match)
  197.       title = "\nLocation: Database - System\n"
  198.       result = ""
  199.       res = AMN_Debug.scan(@game_title, string, match)
  200.       result << AMN_Debug.match_vocab("  Game Title", res) unless res.empty?
  201.       #
  202.       res = AMN_Debug.scan(@currency_unit, string, match)
  203.       result << AMN_Debug.match_vocab("  Currency Unit", res) unless res.empty?
  204.       #
  205.       res = AMN_Debug.array_scan(@elements, string, match)
  206.       result << AMN_Debug.match_vocab("  Elements", res) unless res.empty?
  207.       #
  208.       res = AMN_Debug.array_scan(@skill_types, string, match)
  209.       result << AMN_Debug.match_vocab("  Skill Types", res) unless res.empty?
  210.       #
  211.       res = AMN_Debug.array_scan(@weapon_types, string, match)
  212.       result << AMN_Debug.match_vocab("  Weapon Types", res) unless res.empty?
  213.       #
  214.       res = AMN_Debug.array_scan(@armor_types, string, match)
  215.       result << AMN_Debug.match_vocab("  Armour Types", res) unless res.empty?
  216.       #
  217.       res = AMN_Debug.array_scan(@terms.basic, string, match)
  218.       result << AMN_Debug.match_vocab("  Terms:  Basic", res) unless res.empty?
  219.       #
  220.       res = AMN_Debug.array_scan(@terms.params, string, match)
  221.       result << AMN_Debug.match_vocab("  Terms:  Params", res) unless res.empty?
  222.       #
  223.       res = AMN_Debug.array_scan(@terms.etypes, string, match)
  224.       result << AMN_Debug.match_vocab("  Terms:  Equip Types", res) unless res.empty?
  225.       #
  226.       return title + result unless result.empty?
  227.       return result
  228.     end
  229.   end
  230.  
  231.   class BaseItem
  232.     def check_ref(string, match)
  233.       title = "\nLocation: Database - #{self.class} ID #{@id} #{@name}\n"
  234.       result = ""
  235.       res = AMN_Debug.scan(@name, string, match)
  236.       result << AMN_Debug.match_vocab("  Name", res) unless res.empty?
  237.       #
  238.       res = AMN_Debug.scan(@description, string, match)
  239.       result << AMN_Debug.match_vocab("  Description", res) unless res.empty?
  240.       #
  241.       res = AMN_Debug.scan(@note, string, match)
  242.       result << AMN_Debug.match_vocab("  Notebox", res) unless res.empty?
  243.       #
  244.       return title + result unless result.empty?
  245.       return result
  246.     end
  247.     # Enemy, Class, Armour, Weapon
  248.   end
  249.    
  250.   class Skill
  251.     def check_ref(string, match)
  252.       title = "\nLocation: Database - #{self.class} ID #{@id} #{@name}\n"
  253.       result = ""
  254.       res = AMN_Debug.scan(@name, string, match)
  255.       result << AMN_Debug.match_vocab("  Name", res) unless res.empty?
  256.       #
  257.       res = AMN_Debug.scan(@description, string, match)
  258.       result << AMN_Debug.match_vocab("  Description", res) unless res.empty?
  259.       #
  260.       res = AMN_Debug.scan(@note, string, match)
  261.       result << AMN_Debug.match_vocab("  Notebox", res) unless res.empty?
  262.       #
  263.       res = AMN_Debug.scan(@message1, string, match)
  264.       result << AMN_Debug.match_vocab("  Message 1", res) unless res.empty?
  265.       #
  266.       res = AMN_Debug.scan(@message2, string, match)
  267.       result << AMN_Debug.match_vocab("  Message 2", res) unless res.empty?
  268.       #
  269.       return title + result unless result.empty?
  270.       return result
  271.     end
  272.   end
  273.  
  274.   class State
  275.     def check_ref(string, match)
  276.       title = "\nLocation: Database - #{self.class} ID #{@id}: #{@name}\n"
  277.       result = ""
  278.       res = AMN_Debug.scan(@name, string, match)
  279.       result << AMN_Debug.match_vocab("  Name", res) unless res.empty?
  280.       #
  281.       res = AMN_Debug.scan(@note, string, match)
  282.       result << AMN_Debug.match_vocab("  Notebox", res) unless res.empty?
  283.       #
  284.       res = AMN_Debug.scan(@message1, string, match)
  285.       result << AMN_Debug.match_vocab("  Message 1", res) unless res.empty?
  286.       #
  287.       res = AMN_Debug.scan(@message2, string, match)
  288.       result << AMN_Debug.match_vocab("  Message 2", res) unless res.empty?
  289.       #
  290.       res = AMN_Debug.scan(@message3, string, match)
  291.       result << AMN_Debug.match_vocab("  Message 3", res) unless res.empty?
  292.       #
  293.       res = AMN_Debug.scan(@message4, string, match)
  294.       result << AMN_Debug.match_vocab("  Message 4", res) unless res.empty?
  295.       #
  296.       return title + result unless result.empty?
  297.       return result
  298.     end
  299.     # @message1, @message2, @message3, @message4
  300.   end
  301.  
  302.   class Tileset
  303.     def check_ref(string, match)
  304.       title = "\nLocation: Database - #{self.class} ID #{@id}: #{@name}\n"
  305.       result = ""
  306.       res = AMN_Debug.scan(@note, string, match)
  307.       result << AMN_Debug.match_vocab("  Notebox", res) unless res.empty?
  308.       #
  309.       return title + result unless result.empty?
  310.       return result
  311.     end
  312.     # @note
  313.   end
  314.  
  315.   class Troop
  316.     def check_ref(string, match)
  317.       title = "\nLocation: Database - #{self.class} ID #{@id}: #{@name}\n"
  318.       result = ""
  319.       @pages.each_with_index do |pg, i|
  320.         res = AMN_Debug.scan(pg.note, string, match)
  321.         result << AMN_Debug.match_vocab("  Page #{i+1} Comments", res) unless res.empty?
  322.         #
  323.         res = AMN_Debug.scan(pg.texts, string, match)
  324.         result << AMN_Debug.match_vocab("  Page #{i+1} Texts", res) unless res.empty?
  325.         #
  326.         res = AMN_Debug.scan(pg.choices, string, match)
  327.         result << AMN_Debug.match_vocab("  Page #{i+1} Choices", res) unless res.empty?
  328.         #
  329.         res = AMN_Debug.scan(pg.script_calls, string, match)
  330.         result << AMN_Debug.match_vocab("  Page #{i+1} Script Calls", res) unless res.empty?
  331.       end
  332.       #
  333.       return title + result unless result.empty?
  334.       return result
  335.     end
  336.     #
  337.   end
  338.  
  339.   class CommonEvent
  340.     def note
  341.       @note = ""
  342.       return @note if !@list || @list.size <= 0
  343.       note_list = []
  344.       @list.each { |item|
  345.         next unless item && [108, 408].include?(item.code)
  346.         note_list << item.parameters[0]
  347.       }
  348.       @note = note_list.join("\r\n")
  349.       return @note
  350.     end
  351.    
  352.     def script_calls
  353.       @s_calls = ""
  354.       return @s_calls if !@list || @list.size <= 0
  355.       note_list = []
  356.       @list.each { |item|
  357.         next unless item && [355, 655].include?(item.code)
  358.         note_list << item.parameters[0]
  359.       }
  360.       @s_calls = note_list.join("\r\n")
  361.       return @s_calls
  362.     end
  363.    
  364.     def texts
  365.       @texts = ""
  366.       return @texts if !@list || @list.size <= 0
  367.       note_list = []
  368.       @list.each { |item|
  369.         next unless item && [101, 401, 105, 405].include?(item.code)
  370.         note_list << item.parameters[0]
  371.       }
  372.       @texts = note_list.join("\r\n")
  373.       return @texts
  374.     end
  375.    
  376.     def choices
  377.       @choices = ""
  378.       return @choices if !@list || @list.size <= 0
  379.       note_list = []
  380.       @list.each { |item|
  381.         next unless item && item.code == 102
  382.         item.parameters[0].each {|s| note_list << s }
  383.       }
  384.       @choices = note_list.join("\r\n")
  385.       return @choices
  386.     end
  387.    
  388.     def check_ref(string, match)
  389.       title = "\nLocation: Database - #{self.class} ID #{@id}: #{@name}\n"
  390.       result = ""
  391.       res = AMN_Debug.scan(@name, string, match)
  392.       result << AMN_Debug.match_vocab("  Name", res) unless res.empty?
  393.       #
  394.       res = AMN_Debug.scan(note, string, match)
  395.       result << AMN_Debug.match_vocab("  Comments", res) unless res.empty?
  396.       #
  397.       res = AMN_Debug.scan(texts, string, match)
  398.       result << AMN_Debug.match_vocab("  Texts", res) unless res.empty?
  399.       #
  400.       res = AMN_Debug.scan(choices, string, match)
  401.       result << AMN_Debug.match_vocab("  Choices", res) unless res.empty?
  402.       #
  403.       res = AMN_Debug.scan(script_calls, string, match)
  404.       result << AMN_Debug.match_vocab("  Script Calls", res) unless res.empty?
  405.       #
  406.       return title + result unless result.empty?
  407.       return result
  408.     end
  409.     # @list - A list of event commands
  410.   end
  411.  
  412.   class Map
  413.     def check_ref(string, match, id)
  414.       title = "\nLocation: #{self.class} ID #{id}: #{$data_mapinfos[id].name}\n"
  415.       result = ""
  416.       res = AMN_Debug.scan(@display_name, string, match)
  417.       result << AMN_Debug.match_vocab("  Display Name", res) unless res.empty?
  418.       #
  419.       res = AMN_Debug.scan(@note, string, match)
  420.       result << AMN_Debug.match_vocab("  Notebox", res) unless res.empty?
  421.       #
  422.       @events.each_key do |ev|
  423.         unless @events[ev].check_ref(string, match, id).empty?
  424.           result << @events[ev].check_ref(string, match, id)
  425.         end
  426.       end
  427.       #
  428.       return title + result unless result.empty?
  429.       return result
  430.     # display_name, @map.note
  431.     # @events
  432.     end
  433.   end
  434.  
  435.   class Event
  436.     def check_ref(string, match, id)
  437.       title = " MAP #{id} #{self.class} ID #{@id}: #{@name}\n"
  438.       result = ""
  439.       res = AMN_Debug.scan(@name, string, match)
  440.       result << AMN_Debug.match_vocab("  Name", res) unless res.empty?
  441.       #
  442.       @pages.each_with_index do |pg, i|
  443.         res = AMN_Debug.scan(pg.note, string, match)
  444.         result << AMN_Debug.match_vocab("  Page #{i+1} Comments", res) unless res.empty?
  445.         #
  446.         res = AMN_Debug.scan(pg.texts, string, match)
  447.         result << AMN_Debug.match_vocab("  Page #{i+1} Texts", res) unless res.empty?
  448.         #
  449.         res = AMN_Debug.scan(pg.choices, string, match)
  450.         result << AMN_Debug.match_vocab("  Page #{i+1} Choices", res) unless res.empty?
  451.         #
  452.         res = AMN_Debug.scan(pg.script_calls, string, match)
  453.         result << AMN_Debug.match_vocab("  Page #{i+1} Script Calls", res) unless res.empty?
  454.         #
  455.       end
  456.       return title + result unless result.empty?
  457.       return result
  458.     end
  459.   end
  460. end
  461.  
  462. class Game_Actor < Game_Battler
  463.   def check_ref(string, match)
  464.     title = "\nLocation: Database - #{self.class} ID #{@id}: #{@name}\n"
  465.     result = ""
  466.     res = AMN_Debug.scan(@name, string, match)
  467.     result << AMN_Debug.match_vocab("  Name", res) unless res.empty?
  468.     #
  469.     res = AMN_Debug.scan(@nickname, string, match)
  470.     result << AMN_Debug.match_vocab("  Nickname", res) unless res.empty?
  471.     #
  472.     res = AMN_Debug.scan(actor.note, string, match)
  473.     result << AMN_Debug.match_vocab("  Notebox", res) unless res.empty?
  474.     #
  475.     return title + result unless result.empty?
  476.     return result
  477.   # @name, @nickname, actor.note
  478.   end
  479. end
  480.  
  481. class RPG::Event::Page
  482.   def note
  483.     @note = ""
  484.     return @note if !@list || @list.size <= 0
  485.     note_list = []
  486.     @list.each { |item|
  487.       next unless item && [108, 408].include?(item.code)
  488.       note_list << item.parameters[0]
  489.     }
  490.     @note = note_list.join("\r\n")
  491.     return @note
  492.   end
  493.  
  494.   def script_calls
  495.     @s_calls = ""
  496.     return @s_calls if !@list || @list.size <= 0
  497.     note_list = []
  498.     @list.each { |item|
  499.       next unless item && [355, 655].include?(item.code)
  500.       note_list << item.parameters[0]
  501.     }
  502.     @s_calls = note_list.join("\r\n")
  503.     return @s_calls
  504.   end
  505.  
  506.   def texts
  507.     @texts = ""
  508.     return @texts if !@list || @list.size <= 0
  509.     note_list = []
  510.     @list.each { |item|
  511.       next unless item && [101, 401, 105, 405].include?(item.code)
  512.       note_list << item.parameters[0]
  513.     }
  514.     @texts = note_list.join("\r\n")
  515.     return @texts
  516.   end
  517.  
  518.   def choices
  519.     @choices = ""
  520.     return @choices if !@list || @list.size <= 0
  521.     note_list = []
  522.     @list.each { |item|
  523.       next unless item && item.code == 102
  524.       item.parameters[0].each {|s| note_list << s }
  525.     }
  526.     @choices = note_list.join("\r\n")
  527.     return @choices
  528.   end
  529. end
  530.  
  531. class RPG::Troop::Page
  532.   def note
  533.     @note = ""
  534.     return @note if !@list || @list.size <= 0
  535.     note_list = []
  536.     @list.each { |item|
  537.       next unless item && [108, 408].include?(item.code)
  538.       note_list << item.parameters[0]
  539.     }
  540.     @note = note_list.join("\r\n")
  541.     return @note
  542.   end
  543.  
  544.   def script_calls
  545.     @s_calls = ""
  546.     return @s_calls if !@list || @list.size <= 0
  547.     note_list = []
  548.     @list.each { |item|
  549.       next unless item && [355, 655].include?(item.code)
  550.       note_list << item.parameters[0]
  551.     }
  552.     @s_calls = note_list.join("\r\n")
  553.     return @s_calls
  554.   end
  555.  
  556.   def texts
  557.     @texts = ""
  558.     return @texts if !@list || @list.size <= 0
  559.     note_list = []
  560.     @list.each { |item|
  561.       next unless item && [101, 401, 105, 405].include?(item.code)
  562.       note_list << item.parameters[0]
  563.     }
  564.     @texts = note_list.join("\r\n")
  565.     return @texts
  566.   end
  567.  
  568.   def choices
  569.     @choices = ""
  570.     return @choices if !@list || @list.size <= 0
  571.     note_list = []
  572.     @list.each { |item|
  573.       next unless item && item.code == 102
  574.       item.parameters[0].each {|s| note_list << s }
  575.     }
  576.     @choices = note_list.join("\r\n")
  577.     return @choices
  578.   end
  579. end
  580.  
  581. class Game_Event < Game_Character
  582.   attr_reader   :event
  583.  
  584.   def note
  585.     return "" if !@page || !@page.list || @page.list.size <= 0
  586.     @page.note
  587.   end
  588.  
  589.   def script_calls
  590.     return "" if !@page || !@page.list || @page.list.size <= 0
  591.     @page.script_calls
  592.   end
  593.  
  594.   def texts
  595.     return "" if !@page || !@page.list || @page.list.size <= 0
  596.     @page.texts
  597.   end
  598.  
  599.   def choices
  600.     return "" if !@page || !@page.list || @page.list.size <= 0
  601.     @page.choices
  602.   end
  603.  
  604. end
Add Comment
Please, Sign In to add comment