require 'json' require 'fileutils' $res_root = (lambda { dir = File.dirname(__FILE__) loop do parent_dir = File.expand_path('..', dir) break if dir.empty? || parent_dir == dir dir = parent_dir break if File.exist?("#{dir}/project.godot") end return dir }).call CONFIG_ROOT = "#{$res_root}/.tbl" def get_options(tool_file) options = {} name = File.basename(tool_file, ".rb") JSON.parse(File.read("#{CONFIG_ROOT}/#{name}.json"))['options'].each do |unit| key, value = unit['name'], unit['value'] value.gsub!('res:', $res_root) if value.is_a?(String) options[key] = value end return options end def convert_case(source) return source.split('_').collect(&:capitalize).join end def origin_case(source) source.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end def ensure_dir(dir) return if Dir.exist?(dir) FileUtils.mkdir_p dir end def recreate_dir(dir) FileUtils.rm_rf dir FileUtils.mkdir_p dir end