Advertisement
Zeriab

[RGSS][Extract] Map list

Jan 22nd, 2017
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.93 KB | None | 0 0
  1. #__END__
  2. ##
  3. # This script extracts the map list from the MapInfos.rxdata file and shows them
  4. # in the same order and indent as in the editor.
  5. ##
  6. # Copyright (c) 2017 Zeriab
  7. #
  8. # This software is provided 'as-is', without any express or implied
  9. # warranty. In no event will the authors be held liable for any damages
  10. # arising from the use of this software.
  11. #
  12. # Permission is granted to anyone to use this software for any purpose,
  13. # including commercial applications, and to alter it and redistribute it
  14. # freely, subject to the following restrictions:
  15. #
  16. # 1. The origin of this software must not be misrepresented; you must not
  17. #    claim that you wrote the original software. If you use this software
  18. #    in a product, an acknowledgement in the product documentation would be
  19. #    appreciated but is not required.
  20. # 2. Altered source versions must be plainly marked as such, and must not be
  21. #    misrepresented as being the original software.
  22. # 3. This notice may not be removed or altered from any source distribution.
  23. #
  24.  
  25. class Module
  26.   # Prevent adding the method again should it already be present.
  27.   unless self.method_defined?('attr_sec_accessor')
  28.     def attr_sec_accessor(sym, default = 0)
  29.       attr_writer sym
  30.       attr_sec_reader sym, default
  31.     end
  32.    
  33.     def attr_sec_reader(sym, default = 0)
  34.       sym = sym.id2name
  35.       string = "def #{sym};" +
  36.                "  @#{sym} = #{default}  if @#{sym}.nil?;" +
  37.                "  @#{sym};" +
  38.                "end;"
  39.       module_eval(string)
  40.     end
  41.   end
  42. end
  43.  
  44.  
  45.  
  46. Map = Struct.new(:name, :map_id, :parent_id, :order)
  47.  
  48. class Map
  49.   attr_sec_accessor :children, '[]'
  50.   attr_sec_accessor :indent, 0
  51.  
  52.   def prefix
  53.     return '' if indent <= 0
  54.     whitespace = '  ' * indent
  55.     return whitespace + '^- '
  56.   end
  57.  
  58.  
  59.   def write_to_stream(io)
  60.     io.print prefix
  61.     io.print "Map #{map_id} ~ #{name}\r\n"
  62.     for child in children
  63.       child.write_to_stream(io)
  64.     end
  65.   end
  66. end
  67.  
  68. ######
  69. ######
  70.  
  71. infos = load_data('Data\MapInfos.rxdata')
  72.  
  73. map_map = {}
  74. maps = []
  75. for map_id, map_info in infos
  76.   current_map = Map.new(map_info.name, map_id, map_info.parent_id, map_info.order)
  77.   map_map[map_id] = current_map
  78.   maps << current_map if current_map.parent_id == 0
  79. end
  80.  
  81. maps.sort! {|a,b| a.order <=> b.order}
  82.  
  83. for map_id, map in map_map
  84.   if map.parent_id > 0
  85.     map_map[map.parent_id].children << map
  86.   end
  87. end
  88.  
  89. def sort_map(map)
  90.   if map.children.size > 0
  91.     map.children.sort! {|a,b| a.order <=> b.order}
  92.     for child in map.children
  93.       sort_map(child)
  94.     end
  95.   end
  96. end
  97.  
  98. def set_indent(map, indent)
  99.   map.indent = indent
  100.   for child in map.children
  101.     set_indent(child, indent + 1)
  102.   end
  103. end
  104.  
  105. for map in maps
  106.   sort_map(map)
  107.   set_indent(map, 0)
  108. end
  109.  
  110. File.open('Map list.txt', 'wb') {|f|
  111.   f.print "THIS FILE CONTAINS THE MAPS AS LISTED IN THE EDITOR\r\n\r\n"
  112.   for map in maps
  113.     map.write_to_stream(f)
  114.   end
  115. }
  116.  
  117. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement