nwn-lib 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/CHANGELOG +7 -0
  2. data/Rakefile +2 -2
  3. data/bin/nwn-gff-irb +44 -0
  4. data/lib/nwn/gff.rb +13 -13
  5. metadata +3 -1
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ === 0.2.2
2
+
3
+ * Binary: nwn-gff-irb: interactive gff inspection/editing shell
4
+ * Gff: Errors are now RuntimeErrors instead of Exceptions
5
+ * Gff::Reader: properly read structures with no labels inside
6
+ * Gff::Reader: void datatype support
7
+
1
8
  === 0.2.1
2
9
 
3
10
  * TwoDA allows creation of tables and proper writing, HAS NEW API. (sorry!)
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ include FileUtils
9
9
  # Configuration
10
10
  ##############################################################################
11
11
  NAME = "nwn-lib"
12
- VERS = "0.2.1"
12
+ VERS = "0.2.2"
13
13
  CLEAN.include ["**/.*.sw?", "pkg", ".config", "rdoc", "coverage"]
14
14
  RDOC_OPTS = ["--quiet", "--line-numbers", "--inline-source", '--title', \
15
15
  'nwn-lib: a ruby library for accessing NWN resource files', \
@@ -37,7 +37,7 @@ spec = Gem::Specification.new do |s|
37
37
  s.author = "Bernhard Stoeckner"
38
38
  s.email = "elven@swordcoast.net"
39
39
  s.homepage = "http://nwn-lib.elv.es"
40
- s.executables = ["nwn-gff-print"]
40
+ s.executables = ["nwn-gff-print", "nwn-gff-irb"]
41
41
  s.required_ruby_version = ">= 1.8.4"
42
42
  s.files = %w(COPYING CHANGELOG README Rakefile) + Dir.glob("{bin,doc,spec,lib}/**/*")
43
43
  s.require_path = "lib"
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/ruby
2
+ require 'rubygems'
3
+ require 'optparse'
4
+ require 'nwn/gff'
5
+ require 'nwn/twoda'
6
+ require 'yaml'
7
+ require 'irb'
8
+
9
+ OptionParser.new do |o|
10
+ o.banner = "Usage: nwn-gff-irb file"
11
+ end.parse!
12
+
13
+ file = ARGV.shift or begin
14
+ $stderr.puts "Required argument: filename to process, or - for stdin (try -h)."
15
+ exit 1
16
+ end
17
+
18
+ if file == "-"
19
+ bytes = $stdin.read
20
+ else
21
+ bytes = IO.read(file)
22
+ end
23
+ $file = File.expand_path(file)
24
+
25
+ GFF = NWN::Gff::Reader.read(bytes)
26
+
27
+ def save destination = nil
28
+ destination ||= $file
29
+ puts "Saving to ´#{destination}' .."
30
+ bytes = NWN::Gff::Writer.dump(GFF)
31
+ File.open(destination, "w") {|f|
32
+ f.write(bytes)
33
+ }
34
+ puts "saved."
35
+ end
36
+
37
+ include NWN::Gff
38
+
39
+ puts "Your GFF file is in `GFF' (type: #{GFF.type.inspect})."
40
+ puts "Type `save' to save to the filename it came from (make a backup!), `exit' (or Ctrl+D) to exit (without saving)."
41
+ puts "To save to a different location, type `save \"path/to/new/location.ext\"'."
42
+ puts ""
43
+
44
+ IRB.start
@@ -1,7 +1,7 @@
1
1
  module NWN
2
2
  module Gff
3
3
  # This error gets thrown if reading or writing fails.
4
- class GffError < Exception; end
4
+ class GffError < RuntimeError; end
5
5
 
6
6
  # This error gets thrown if a supplied value does not
7
7
  # fit into the given data type, or you are trying to assign
@@ -9,11 +9,11 @@ module NWN
9
9
  #
10
10
  # Example: You're trying to pass a value greater than 2**32
11
11
  # into a int.
12
- class GffTypeError < Exception; end
12
+ class GffTypeError < RuntimeError; end
13
13
 
14
14
  # Gets raised if you are trying to access a path that does
15
15
  # not exist.
16
- class GffPathInvalidError < Exception; end
16
+ class GffPathInvalidError < RuntimeError; end
17
17
 
18
18
  # This hash lists all possible NWN::Gff::Element types.
19
19
  Types = {
@@ -460,13 +460,14 @@ class NWN::Gff::Reader
460
460
  lbl, vl = * read_field(data_or_offset)
461
461
  struct[lbl] = vl
462
462
  else
463
- return 1 if count == 0
464
- raise GffError, "struct index not divisable by 4" if
465
- data_or_offset % 4 != 0
466
- data_or_offset /= 4
467
- for i in data_or_offset...(data_or_offset+count)
468
- lbl, vl = * read_field(@field_indices[i])
469
- struct[lbl] = vl
463
+ if count > 0
464
+ raise GffError, "struct index not divisable by 4" if
465
+ data_or_offset % 4 != 0
466
+ data_or_offset /= 4
467
+ for i in data_or_offset...(data_or_offset+count)
468
+ lbl, vl = * read_field(@field_indices[i])
469
+ struct[lbl] = vl
470
+ end
470
471
  end
471
472
  end
472
473
 
@@ -555,9 +556,8 @@ class NWN::Gff::Reader
555
556
  r
556
557
 
557
558
  when :void
558
- len = @field_data[data_or_offset, 4].unpack("V")
559
- void = @field_data[data_or_offset + 4, len].unpack("H*")
560
- raise "void: #{void.inspect}"
559
+ len = @field_data[data_or_offset, 4].unpack("V")[0]
560
+ @field_data[data_or_offset + 4, len].unpack("H*")[0]
561
561
 
562
562
  when :struct
563
563
  read_struct data_or_offset
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: nwn-lib
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.1
6
+ version: 0.2.2
7
7
  date: 2008-07-03 00:00:00 +02:00
8
8
  summary: a ruby library for accessing Neverwinter Nights resource files
9
9
  require_paths:
@@ -33,6 +33,7 @@ files:
33
33
  - CHANGELOG
34
34
  - README
35
35
  - Rakefile
36
+ - bin/nwn-gff-irb
36
37
  - bin/nwn-gff-print
37
38
  - spec/spec.opts
38
39
  - spec/rcov.opts
@@ -57,6 +58,7 @@ extra_rdoc_files:
57
58
  - COPYING
58
59
  executables:
59
60
  - nwn-gff-print
61
+ - nwn-gff-irb
60
62
  extensions: []
61
63
 
62
64
  requirements: []