A library for Neverwinter Nights 1/2 resource files
This package provides a library for reading, changing, and writing common file formats that are found with NWN, a Bioware game.
They should work with NWN2 just as well, since the file format specifications did not change.
There are various things included in this distribution:
-
some binaries under bin/ (see BINARIES)
-
the actual library under lib/nwn
Quickstart
It is easiest to just use the gem, which is available through rubyforge (sudo gem install nwn-lib
).
As an alternative, fetch the latest development files with git.
require 'rubygems'
require 'nwn/gff'
# Read a GFF file
o = NWN::Gff::Reader.read(IO.read('/tmp/test-creature.gff'))
# Do some modifications to it
o['/Tag'] = 'testtag'
# And write it somewhere else
bytes = NWN::Gff::Writer.dump(o)
File.open('/tmp/test-creature-2.gff', 'w') {|f| f.write(bytes) }
Modification API is fairly limited, for now, but will improve soon.
GFF data structures: Quick Intro
Ruby GFF data structures are nearly a 1:1 wrapper around the known format.
Each GFF object has a root structure with a struct_id
of 0.
Label
A Label is a string of up to 16 bytes, and occurs as keys in Structs.
Struct
A struct is a hash. It is a unordered collection of key => value pairs. Keys are Labels, values are either:
-
Structs
-
Lists
-
Elements
List
A list is an ordered array of Structs.
Element
A Element is a distinct value of a given type. For all possible types, see the Types
hash in the NWN::Gff module.