nwn-lib 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/CHANGELOG +5 -0
  2. data/Rakefile +1 -1
  3. data/lib/nwn/gff.rb +34 -3
  4. metadata +2 -2
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ === 0.3.2
2
+
3
+ * Gff: fix reading some type fields raising an exception in rare conditions
4
+ * Add NWN::Gff::Struct#set for easy label setting
5
+
1
6
  === 0.3.1
2
7
 
3
8
  * Bugfix release only
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ include FileUtils
9
9
  # Configuration
10
10
  ##############################################################################
11
11
  NAME = "nwn-lib"
12
- VERS = "0.3.1"
12
+ VERS = "0.3.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', \
data/lib/nwn/gff.rb CHANGED
@@ -385,6 +385,37 @@ class NWN::Gff::Struct
385
385
  def method_missing meth, *a, &block
386
386
  @hash.method(meth).call(*a, &block)
387
387
  end
388
+
389
+ # Sets a NWN::Gff::Element on this struct.
390
+ # Overwrites existing labels.
391
+
392
+ # args can be the following:
393
+ # * A single NWN::Gff::Element
394
+ # * A single NWN::Gff::Struct, in which case it will be merged into this one
395
+ # * label, type
396
+ # * label, type, value
397
+ def set *args
398
+ if args.size == 1
399
+ arg = args[0]
400
+ case arg
401
+ when NWN::Gff::Struct
402
+ @hash.merge!(addme)
403
+
404
+ when NWN::Gff::Element
405
+ @hash[arg.label] = arg
406
+ else
407
+ raise ArgumentError, "Cannot determine how to handle #{arg.class.to_s}."
408
+ end
409
+
410
+ elsif args.size == 2 || args.size == 3
411
+ element = NWN::Gff::Element.new(*args)
412
+
413
+ @hash[element.label] = element
414
+ else
415
+ raise ArgumentError, "Cannot determine how to handle #{args.inspect}."
416
+ end
417
+ end
418
+
388
419
  end
389
420
 
390
421
  # A CExoLocString is a localised CExoString.
@@ -518,13 +549,13 @@ class NWN::Gff::Reader
518
549
  raise GffError, "Label index #{label_index} outside of label array" if
519
550
  label_index > @labels.size
520
551
 
521
- raise GffError, "Field data offset #{data_or_offset} outside of field data block (#{@field_data.size})" if
522
- ComplexTypes.index(type) && data_or_offset > @field_data.size
552
+ label = @labels[label_index]
523
553
 
524
554
  raise GffError, "Unknown field type #{type}." unless Types[type]
525
555
  type = Types[type]
526
556
 
527
- label = @labels[label_index]
557
+ raise GffError, "Field '#{label}' (type: #{type} )data offset #{data_or_offset} outside of field data block (#{@field_data.size})" if
558
+ ComplexTypes.index(type) && data_or_offset > @field_data.size
528
559
 
529
560
  value = case type
530
561
  when :byte, :char
metadata CHANGED
@@ -3,8 +3,8 @@ 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.3.1
7
- date: 2008-07-09 00:00:00 +02:00
6
+ version: 0.3.2
7
+ date: 2008-07-10 00:00:00 +02:00
8
8
  summary: a ruby library for accessing Neverwinter Nights resource files
9
9
  require_paths:
10
10
  - lib