Class: DDNetSnapItem

Inherits:
Object
  • Object
show all
Defined in:
lib/snapshot/unpacker.rb

Constant Summary collapse

@@registered_types =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(u, id) ⇒ DDNetSnapItem

TODO: rename to register uuid?!



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/snapshot/unpacker.rb', line 38

def initialize(u, id)
  @name = 'ddnet_uuid'
  @notes = []
  len = u.get_int
  p = u.parsed.last
  @notes.push([:green, p[:pos], p[:len], "len=#{len}"])
  (0...len).each do |i|
    val = u.get_int
    p = u.parsed.last
    col = (i % 2).zero? ? :bg_pink : :bg_yellow
    @notes.push([col, p[:pos], p[:len], "val=#{val}"])
  end
  @@registered_types.push(id)
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



33
34
35
# File 'lib/snapshot/unpacker.rb', line 33

def name
  @name
end

#notesObject

Returns the value of attribute notes.



33
34
35
# File 'lib/snapshot/unpacker.rb', line 33

def notes
  @notes
end

Class Method Details

.parse(u, _item_type) ⇒ Object

parses registered ddnet items



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/snapshot/unpacker.rb', line 54

def self.parse(u, _item_type)
  id = u.get_int
  p = u.parsed.last
  notes = []
  notes.push([:cyan, p[:pos], p[:len], "id=#{id}"])
  len = u.get_int
  p = u.parsed.last
  notes.push([:green, p[:pos], p[:len], "len=#{len}"])
  (0...len).each do |i|
    val = u.get_int
    p = u.parsed.last
    col = (i % 2).zero? ? :bg_pink : :bg_yellow
    notes.push([col, p[:pos], p[:len], "val=#{val}"])
  end
  notes
end

.valid_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/snapshot/unpacker.rb', line 71

def self.valid_type?(type)
  @@registered_types.include?(type)
end