Module: NWN::Gff
Defined Under Namespace
Modules: Cexolocstr, CexolocstrValue, Field, List, Scripting, Struct Classes: GffError, GffPathInvalidError, GffTypeError, Reader, Writer
Constant Summary collapse
- Types =
This hash lists all possible NWN::Gff::Field types.
{ 0 => :byte, 1 => :char, 2 => :word, 3 => :short, 4 => :dword, 5 => :int, 6 => :dword64, 7 => :int64, 8 => :float, 9 => :double, 10 => :cexostr, 11 => :resref, 12 => :cexolocstr, 13 => :void, 14 => :struct, 15 => :list, }.freeze
- ComplexTypes =
:stopdoc: Used internally to figure out if a field is stored directly or by reference.
[6, 7, 9, 10, 11, 12, 13, 14, 15].freeze
- SimpleTypes =
(Types.keys - ComplexTypes)
- Formats =
:startdoc:
{ :byte => "Cxxx", :char => "Cxxx", :word => 'Sxx', :short => 'sxx', :dword => 'I', :int => 'i', :dword64 => 'II', :int64 => 'q', :float => 'f', :double => 'd', }.freeze
- YAMLNonInlineableFields =
These field types can never be inlined in YAML.
[:struct, :list, :cexolocstr]
- FileFormats =
[:gff, :yaml, :kivinen, :marshal]
- FileFormatGuesses =
{ /^ut[cdeimpstw]$/ => :gff, /^(git|are|gic)$/ => :gff, /^(mod|ifo|fac|ssf|dlg|itp)$/ => :gff, /^(bic)$/ => :gff, /^ya?ml$/ => :yaml, /^marshal$/ => :marshal, /^k(ivinen)?$/ => :kivinen, }
Class Method Summary collapse
Class Method Details
.guess_file_format(filename) ⇒ Object
74 75 76 77 |
# File 'lib/nwn/gff.rb', line 74 def self.guess_file_format(filename) extension = File.extname(filename.downcase)[1..-1] FileFormatGuesses[FileFormatGuesses.keys.select {|key| extension =~ key}[0]] end |
.read(io, format) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/nwn/gff.rb', line 79 def self.read(io, format) return case format when :gff NWN::Gff::Reader.read(io) when :yaml YAML.load(io) when :marshal Marshal.load(io) when :kivinen raise NotImplementedError, "Reading kivinen-style data is not supported." else raise NotImplementedError, "Don't know how to read #{format}." end end |
.write(io, format, data) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/nwn/gff.rb', line 94 def self.write(io, format, data) case format when :gff NWN::Gff::Writer.dump(data, io) when :yaml io.puts data.to_yaml when :marshal io.print Marshal.dump(data) when :kivinen data.kivinen_format $options[:types], nil, nil do |l,v| io.puts "%s:\t%s" % [l, v] end else raise NotImplementedError, "Don't know how to write data-format #{format.inspect}" end end |