Method: Table.new_serialized

Defined in:
lib/rgss_db/model/rpg_maker_data/vx/rgss/table.rb,
lib/rgss_db/model/rpg_maker_data/xp/rgss/table.rb,
lib/rgss_db/model/rpg_maker_data/vx_ace/rgss/table.rb

.new_serialized(serialized_string) ⇒ Table

Creates a new instance from a serialized string

Note: needed for Marshal module support

Parameters:

  • serialized_string (String)

Returns:



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/table.rb', line 68

def self.new_serialized(serialized_string)
  # int32_t, int32_t, int32_t, int32_t, int32_t, int16_t *
  dim, x, y, z, size, *data = serialized_string.unpack("llllls*")

  # Checks if written size value matches the actual size of the table
  raise "Table: bad file format (size mismatch)" unless size == (x * y * z)
  # Double check no data was lost
  raise "Table: bad file format (data length mismatch)" unless size == data.length

  # Creates the instance
  table = Table.new(0, 0, 0)
  table.dim = dim
  table.x = x
  table.y = y
  table.z = z
  table.data = data
  table
end