Module NWN::Gff::Handler::Kivinen

  1. lib/nwn/kivinen_support.rb

Methods

public class

  1. dump
  2. format
  3. load

Public class methods

dump (struct, io)
[show source]
    # File lib/nwn/kivinen_support.rb, line 6
 6:   def self.dump struct, io
 7:     ret = ""
 8:     format struct, $options[:types], nil, nil do |l,v|
 9:       ret += "%s:\t%s\n" % [l, v]
10:     end
11:     io.puts ret
12:     ret.size
13:   end
format (struct, types_too = false, add_prefix = true, file_type = nil, struct_id = nil) {|"/", ""| ...}

Parses s as an arbitary GFF object and yields for each field found, with the proper prefix.

struct
The root-struct to dump
prefix
Supply a prefix to add to the output.
types_too
Yield type definitions as well (gffprint.pl -t).
add_prefix
Add a prefix (unknown type) of no type information can be derived from the input.
file_type
File type override. If non-null, add a global struct header with the given file type (useful for passing to gffencode.pl)
struct_id
Provide a struct_id override (if printing a struct).
[show source]
    # File lib/nwn/kivinen_support.rb, line 24
24:   def self.format struct, types_too = false, add_prefix = true, file_type = nil, struct_id = nil, &block
25: 
26:     if types_too
27:       yield("/", "")
28: 
29:       ftype = file_type ? file_type : struct.data_type
30:       yield("/ ____file_type", ftype) if ftype
31:       yield("/ ____file_version", struct.data_version) if struct.data_version
32: 
33:       yield("/ ____struct_type", struct.struct_id)
34:     end
35: 
36:     struct.each_by_flat_path {|path, field|
37:       case field
38:         when String
39:           yield(path, field)
40: 
41:         when NWN::Gff::Struct
42:           yield(path + "/", path)
43:           yield(path + "/ ____struct_type", field.struct_id)
44: 
45:         when NWN::Gff::Field
46: 
47:           case field.field_type
48:             when :list
49:             when :struct
50:               yield(path + "/", path)
51:               yield(path + "/ ____struct_type", field.field_value.struct_id)
52:             when :cexolocstr
53:             else
54:               yield(path, field.field_value)
55:           end
56: 
57:           yield(path + ". ____string_ref",field.str_ref) if
58:             field.has_str_ref? || field.field_type == :cexolocstr
59: 
60:           yield(path + ". ____type", NWN::Gff::Types.index(field.field_type)) if
61:             types_too
62: 
63:       end
64:     }
65:   end
load (io)
[show source]
   # File lib/nwn/kivinen_support.rb, line 2
2:   def self.load io
3:     raise NotImplementedError, "Reading kivinen not supported"
4:   end