nwn-lib 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/BINARIES CHANGED
@@ -1,28 +1,38 @@
1
1
  == nwn-gff-print
2
2
 
3
- Usage: nwn-gff-print [options] file/- [path]
4
- -y, --yaml Dump as yaml
5
- -k, --kivinen Dump as kivinens dump format (like the perl tools)
6
- -f, --kivinen-full-path Print the full path (implies -k)
7
- -m, --marshal Native ruby marshalling. Warning: raw bytes
8
- -t, --types Dump types as well (only applies to -k, for now)
9
- --type filetype Override the file type (implies --struct 0xffffffff)
10
- --struct id Override struct id (as hex, please)
11
-
12
- This prints out the given file (or stdin, if -) as the specified format (-k, -f, -y, -m).
3
+ Usage: nwn-gff-print [options] file/- [file, file, ..]
4
+ -y, --yaml Dump as yaml
5
+ -k, --kivinen Dump as kivinens dump format (like the perl tools)
6
+ --kivinen-full-path Print the full path (implies -k)
7
+ -b, --print-basename Prefix the file basename to the output
8
+ -f, --print-filename Prefix the full filename to the output
9
+ -t, --print-types Print types as well
10
+ -m, --marshal Native ruby marshalling. Warning: raw bytes
11
+ --postfix P Write output to file postfixed with P instead of stdout
12
+ --float_rounding F Round floating point numbers to the specified number of righthand digits
13
+ --type filetype Override the file type (implies --struct 0xffffffff)
14
+ --struct id Override struct id (as hex, please)
15
+ -p, --path path Only print the given path
16
+ -v, --verbose Be verbose
17
+
18
+ This prints out the given file(s) (or stdin, if -) as the specified format (-y, -k, -m)
13
19
  [-k] is the same as gffprint.pl
14
- [-f] is the same as gffprint.pl -t
15
- [-m] is the native ruby marshal format (_Marshal.dump(obj)_)
20
+ [-kt] is the same as gffprint.pl -t
21
+ [-m] is the native ruby marshal format (see Marshal.dump(obj))
16
22
  [-y] is standard YAML
23
+ [--postfix] will write out each processed file to the same directory as the infile, with the given postfix appended
24
+ [--float_rounding] can be used to truncate FPs to the given precision.
25
+ [-p] will print out a given path within the GFF data (for example <tt>/ItemList[2]</tt>)
17
26
 
18
27
  == nwn-gff-import
19
28
 
20
- Usage: nwn-gff-import [options] file/- outfile/-
21
- -y, --yaml Import as yaml
22
- -m, --marshal Import as native ruby marshal data
29
+ Usage: nwn-gff-import [options] file/- [file, file, file]
30
+ -y, --yaml Import as yaml
31
+ -m, --marshal Import as native ruby marshal data
32
+ -o, --outfile F Write to outfile instead of stdout
33
+ --postfix P Strip the given postfix from file and write to that instead of stdout (overrides -o)
23
34
 
24
- This is the equivalent to gffencode.pl, and takes all output formats that nwn-gff-print
25
- provides. This can be used to transform marshalled gff data back into gff binary data.
35
+ This is the equivalent to gffencode.pl. This can be used to transform marshalled gff data back into gff binary data.
26
36
 
27
37
  Example (save to run on a shell, prints out hex data):
28
38
 
data/CHANGELOG CHANGED
@@ -84,3 +84,12 @@ Bernhard Stoeckner <elven@swordcoast.net> (7):
84
84
  struct to yaml: inline small structs
85
85
  CHEATSHEET: add some hints for nwn-gff-import
86
86
  0.3.4-rel
87
+
88
+ === 0.3.5
89
+ Bernhard Stoeckner <elven@swordcoast.net> (6):
90
+ NWN::Gff::Gff.get_or_set: remove stray debug puts
91
+ add option for fp precision to Gff::Reader, add cli opt to nwn-gff-print
92
+ nwn-gff-print: minor speedup when dumping to yaml without prefixes
93
+ doc: update BINARIES, CHEATSHEET
94
+ nwn-gff-import: fix reading stdin as -
95
+ 0.3.5-rel
data/CHEATSHEET CHANGED
@@ -1,6 +1,6 @@
1
1
  ==== Extract item from creature inventory
2
2
 
3
- nwn-gff-print --type UTI -k -t creature.bic 'ItemList[12]' | gffencode.pl -o item.uti
3
+ nwn-gff-print --type UTI -kt -p 'ItemList[12]' creature.bic | gffencode.pl -o item.uti
4
4
 
5
5
  ==== Convert all item files in the current directory to yaml
6
6
 
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ include FileUtils
9
9
  # Configuration
10
10
  ##############################################################################
11
11
  NAME = "nwn-lib"
12
- VERS = "0.3.4"
12
+ VERS = "0.3.5"
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', \
@@ -46,8 +46,7 @@ ARGV.each do |infile|
46
46
  outfile = File.new(outfile, "w")
47
47
  end
48
48
 
49
- infile = $stdin if infile == "-"
50
- inbytes = IO.read(infile)
49
+ inbytes = infile == "-" ? $stdin.read : IO.read(infile)
51
50
 
52
51
  case format
53
52
  when :yaml
@@ -15,6 +15,7 @@ path = nil
15
15
  prefix = :none
16
16
  postfix = nil
17
17
  verbose = false
18
+ options = {}
18
19
 
19
20
  OptionParser.new do |o|
20
21
  o.banner = "Usage: nwn-gff-print [options] file/- [file, file, ..]"
@@ -50,6 +51,10 @@ OptionParser.new do |o|
50
51
  postfix = p
51
52
  end
52
53
 
54
+ o.on "--float_rounding F", "Round floating point numbers to the specified number of righthand digits" do |fr|
55
+ options[:float_rounding] = fr.to_i
56
+ end
57
+
53
58
  o.on "--type filetype", "Override the file type (implies --struct 0xffffffff)" do |t|
54
59
  if t.size != 3
55
60
  $stderr.puts "Invalid type #{t} passwd."
@@ -84,7 +89,7 @@ ARGV.each {|file|
84
89
  bytes = IO.read(file)
85
90
  end
86
91
 
87
- g = NWN::Gff::Reader.read(bytes)
92
+ g = NWN::Gff::Reader.read(bytes, options)
88
93
 
89
94
  if path
90
95
  begin
@@ -108,7 +113,11 @@ ARGV.each {|file|
108
113
  $stderr.puts "Processing `#{file}`" if verbose
109
114
  case format
110
115
  when :yaml
111
- write_to.puts g.to_yaml.split("\n").map {|ln| my_prefix + ln }.join("\n")
116
+ if prefix == :none
117
+ write_to.puts g.to_yaml
118
+ else
119
+ write_to.puts g.to_yaml.split("\n").map {|ln| my_prefix + ln }.join("\n")
120
+ end
112
121
  when :kivinen
113
122
  NWN::Gff.kivinen_format g, my_prefix + "/", types_too, full, file_type, struct_id do |label, value|
114
123
  write_to.puts "%s:\t%s" % [label, value]
@@ -194,7 +194,6 @@ class NWN::Gff::Gff
194
194
  path << v
195
195
 
196
196
  if current_value.is_a?(Gff::Element) && current_value.type == :list # && v =~ /\[(\d+)\]$/
197
- puts "value = #{$1}"
198
197
  current_value = current_value.value[$1.to_i]
199
198
  end
200
199
 
@@ -506,16 +505,31 @@ class NWN::Gff::Reader
506
505
  attr_reader :hash
507
506
  attr_reader :gff
508
507
 
508
+ # This is a hash containing the following options:
509
+ # [+float_rounding+]
510
+ # Round floating numbers to this many righthand positions.
511
+ # Defaults to nil (for no rounding). This can be set to prevent
512
+ # minor toolset fiddlings from showing up in diffs.
513
+ # Note that this is somewhat experimental and may introduce
514
+ # accumulating rounding errors over periods of time.
515
+ # Suggested values:
516
+ # *.git: 4
517
+ attr_accessor :options
518
+
509
519
  # Create a new Reader with the given +bytes+ and immediately parse it.
510
520
  # This is not needed usually; use Reader.read instead.
511
- def initialize bytes
521
+ def initialize bytes, options = {}
512
522
  @bytes = bytes
523
+ @options = {
524
+ :float_rounding => nil,
525
+ }.merge(options)
526
+
513
527
  read_all
514
528
  end
515
529
 
516
530
  # Reads +bytes+ as gff data and returns a NWN::Gff:Gff object.
517
- def self.read bytes
518
- self.new(bytes).gff
531
+ def self.read bytes, options = {}
532
+ self.new(bytes, options).gff
519
533
  end
520
534
 
521
535
  private
@@ -622,7 +636,8 @@ class NWN::Gff::Reader
622
636
  [data_or_offset].pack("I").unpack("i")[0]
623
637
 
624
638
  when :float
625
- [data_or_offset].pack("V").unpack("f")[0]
639
+ vsx = [data_or_offset].pack("V").unpack("f")[0]
640
+ @options[:float_rounding] ? ("%.#{@options[:float_rounding]}f" % vsx).to_f : vsx
626
641
 
627
642
  when :dword64
628
643
  len = 8
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.4
7
- date: 2008-08-08 00:00:00 +02:00
6
+ version: 0.3.5
7
+ date: 2008-08-11 00:00:00 +02:00
8
8
  summary: a ruby library for accessing Neverwinter Nights resource files
9
9
  require_paths:
10
10
  - lib