Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #__END__
- ##
- # This script extracts the map list from the MapInfos.rxdata file and shows them
- # in the same order and indent as in the editor.
- ##
- # Copyright (c) 2017 Zeriab
- #
- # This software is provided 'as-is', without any express or implied
- # warranty. In no event will the authors be held liable for any damages
- # arising from the use of this software.
- #
- # Permission is granted to anyone to use this software for any purpose,
- # including commercial applications, and to alter it and redistribute it
- # freely, subject to the following restrictions:
- #
- # 1. The origin of this software must not be misrepresented; you must not
- # claim that you wrote the original software. If you use this software
- # in a product, an acknowledgement in the product documentation would be
- # appreciated but is not required.
- # 2. Altered source versions must be plainly marked as such, and must not be
- # misrepresented as being the original software.
- # 3. This notice may not be removed or altered from any source distribution.
- #
- class Module
- # Prevent adding the method again should it already be present.
- unless self.method_defined?('attr_sec_accessor')
- def attr_sec_accessor(sym, default = 0)
- attr_writer sym
- attr_sec_reader sym, default
- end
- def attr_sec_reader(sym, default = 0)
- sym = sym.id2name
- string = "def #{sym};" +
- " @#{sym} = #{default} if @#{sym}.nil?;" +
- " @#{sym};" +
- "end;"
- module_eval(string)
- end
- end
- end
- Map = Struct.new(:name, :map_id, :parent_id, :order)
- class Map
- attr_sec_accessor :children, '[]'
- attr_sec_accessor :indent, 0
- def prefix
- return '' if indent <= 0
- whitespace = ' ' * indent
- return whitespace + '^- '
- end
- def write_to_stream(io)
- io.print prefix
- io.print "Map #{map_id} ~ #{name}\r\n"
- for child in children
- child.write_to_stream(io)
- end
- end
- end
- ######
- ######
- infos = load_data('Data\MapInfos.rxdata')
- map_map = {}
- maps = []
- for map_id, map_info in infos
- current_map = Map.new(map_info.name, map_id, map_info.parent_id, map_info.order)
- map_map[map_id] = current_map
- maps << current_map if current_map.parent_id == 0
- end
- maps.sort! {|a,b| a.order <=> b.order}
- for map_id, map in map_map
- if map.parent_id > 0
- map_map[map.parent_id].children << map
- end
- end
- def sort_map(map)
- if map.children.size > 0
- map.children.sort! {|a,b| a.order <=> b.order}
- for child in map.children
- sort_map(child)
- end
- end
- end
- def set_indent(map, indent)
- map.indent = indent
- for child in map.children
- set_indent(child, indent + 1)
- end
- end
- for map in maps
- sort_map(map)
- set_indent(map, 0)
- end
- File.open('Map list.txt', 'wb') {|f|
- f.print "THIS FILE CONTAINS THE MAPS AS LISTED IN THE EDITOR\r\n\r\n"
- for map in maps
- map.write_to_stream(f)
- end
- }
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement