Classes and Modules
Module NWN::ErfModule NWN::Gff
Module NWN::Key
Module NWN::Resources
Module NWN::Tlk
Module NWN::TwoDA
Constants
| SETTING_DEFAULT_VALUES | = | { 'NWN_LIB_IN_ENCODING' => 'ISO-8859-1', 'NWN_LIB_OUT_ENCODING' => 'UTF-8' } |
Public class methods
Converts text from Gff format to native/external, such as json (usually UTF-8).
# File lib/nwn/settings.rb, line 62 62: def self.iconv_gff_to_native text 63: if IconvState[:in] != NWN.setting(:in_encoding) || 64: IconvState[:out] != NWN.setting(:out_encoding) 65: IconvState[:out_i] = Iconv.new(NWN.setting(:out_encoding), NWN.setting(:in_encoding)) 66: end 67: IconvState[:out_i].iconv(text) 68: end
# File lib/nwn/settings.rb, line 53 53: def self.iconv_native_to_gff text 54: if IconvState[:in] != NWN.setting(:in_encoding) || 55: IconvState[:out] != NWN.setting(:out_encoding) 56: IconvState[:in_i] = Iconv.new(NWN.setting(:in_encoding), NWN.setting(:out_encoding)) 57: end 58: IconvState[:in_i].iconv(text) 59: end
This writes a internal warnings and debug messages to stderr.
Leaving this on is recommended, since it usually points to (fixable) errors in your resource files. You can turn this off anyways by setting the environment variable NWN_LIB_DEBUG to “0” or “off”.
Will return true when printed, false otherwise.
# File lib/nwn/settings.rb, line 17 17: def self.log_debug msg 18: # Do not print debug messages if explicitly turned off 19: return false if [false, "off"].index(setting(:debug)) 20: 21: if NWN.setting(:debug_traces) 22: $stderr.puts "(nwn-lib): %s" % [msg] 23: $stderr.puts " " + caller.join("\n ") + "\n" 24: else 25: dir = File.expand_path(File.dirname(File.expand_path(__FILE__)) + "/../../") 26: pa = caller.reject {|x| x.index(dir) }[0] 27: pa ||= caller[0] 28: pa ||= "(no frames)" 29: pa = pa[(pa.size - 36) .. -1] if pa.size > 36 30: $stderr.puts "(nwn-lib) %s: %s" % [pa, msg] 31: end 32: 33: true 34: end
Get or set a ENV var setting. Returns false for “0” values. Returns the old value for new assignments.
# File lib/nwn/settings.rb, line 39 39: def self.setting sym, value = :_invalid_ 40: name = "NWN_LIB_#{sym.to_s.upcase}" 41: if value != :_invalid_ 42: ret = setting(sym) 43: ENV[name] = value.to_s if value != :_invalid_ 44: ret 45: else 46: ENV[name] == "0" ? false : (ENV[name] || SETTING_DEFAULT_VALUES[name]) 47: end 48: end