Module NWN::Gff::List

  1. lib/nwn/gff/list.rb

Methods

public instance

  1. add_struct

Public instance methods

add_struct (struct_id_or_struct = 0) {|struct| ...}

Add a new struct member to this list. You can either add an existing struct to this list (which will reparent it by setting .element), or specify a new struct with a block, or both:

root = Gff::Struct.new 0xffffffff, "UTI", "V3.2"
list = root.add_list 'test', []
list.add_struct 1 do |l|
  l.add_byte 'inner_test', 5
  l.add_cexolocstr 'exolocstr', { 0 => 'Hello', 4 => 'Hallo' }
end
y root

results in:

--- !nwn-lib.elv.es,2008-12/struct
__data_type: UTI
__struct_id: 4294967295
test:
type: :list
  value:
  - !nwn-lib.elv.es,2008-12/struct
    __data_type: UTI/test
    __struct_id: 1
    exolocstr:
      type: :cexolocstr
      value:
        0: Hello
        4: Hallo
    inner_test: {type: :byte, value: 5}}
[show source]
    # File lib/nwn/gff/list.rb, line 32
32:   def add_struct struct_id_or_struct = 0, &block
33:     struct = case struct_id_or_struct
34:       when Integer
35:         s = NWN::Gff::Struct.new
36:         s.struct_id = struct_id_or_struct
37:         s
38: 
39:       when NWN::Gff::Struct
40:         struct_id_or_struct
41: 
42:       else
43:         raise ArgumentError, "specify either a struct_id or an existing struct"
44:     end
45: 
46:     struct.element = self
47: 
48:     yield(struct) if block_given?
49: 
50:     self.v << struct
51:     struct
52:   end