Module NWN

  1. lib/nwn/key.rb
  2. lib/nwn/twoda.rb
  3. lib/nwn/erf.rb
  4. lib/nwn/settings.rb
  5. lib/nwn/gff.rb
  6. lib/nwn/tlk.rb
  7. lib/nwn/res.rb
  8. show all

Classes and Modules

Module NWN::Erf
Module 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

iconv_gff_to_native (text)

Converts text from Gff format to native/external, such as json (usually UTF-8).

[show source]
    # 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
iconv_native_to_gff (text)

Converts text from native format (such as json) to Gff (required by NWN).

[show source]
    # 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
log_debug (msg)

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.

[show source]
    # 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
setting (sym, value = :_invalid_)

Get or set a ENV var setting. Returns false for “0” values. Returns the old value for new assignments.

[show source]
    # 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