Class: Table

Inherits:
Object
  • Object
show all
Extended by:
RgssDb::JsonableConstructor
Includes:
RgssDb::Jsonable
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

Overview

The multidimensional array class.

Each element is an integer of 2 signed bytes ranging from -32,768 to 32,767.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RgssDb::JsonableConstructor

json_create, json_new

Methods included from RgssDb::Jsonable

#as_json, #to_json

Constructor Details

#initialize(xsize, ysize = 0, zsize = 0) ⇒ Table

Creates a Table object.

Specifies the size of each dimension in the multidimensional array. 1-, 2-, and 3-dimensional arrays are possible.

Arrays with no parameters are also permitted.

Parameters:

  • xsize (Integer)
  • ysize (Integer) (defaults to: 0)
  • zsize (Integer) (defaults to: 0)


23
24
25
26
27
28
29
30
31
32
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/table.rb', line 23

def initialize(xsize, ysize = 0, zsize = 0)
  # RMXP needs dimensions
  @dim = 1
  @dim = 2 if ysize.positive?
  @dim = 3 if zsize.positive?
  @x = xsize
  @y = ysize
  @z = zsize
  @data = []
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



98
99
100
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/table.rb', line 98

def data
  @data
end

#dimObject

Returns the value of attribute dim.



98
99
100
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/table.rb', line 98

def dim
  @dim
end

#xObject

Returns the value of attribute x.



98
99
100
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/table.rb', line 98

def x
  @x
end

#yObject

Returns the value of attribute y.



98
99
100
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/table.rb', line 98

def y
  @y
end

#zObject

Returns the value of attribute z.



98
99
100
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/table.rb', line 98

def z
  @z
end

Class Method Details

._load(serialized_string) ⇒ Table

Creates a new instance using the given binary data

Note: needed for Marshal module support

Parameters:

  • serialized_string (String)

Returns:



55
56
57
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/table.rb', line 55

def self._load(serialized_string)
  Table.new_serialized(serialized_string)
end

.json_new(*args) ⇒ Table

Returns a table instance for JSON deserialization

Parameters:

  • args (Array)

Returns:



94
95
96
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/table.rb', line 94

def self.json_new(*args)
  Table.new(0, 0, 0)
end

.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

Instance Method Details

#_dumpString

Dumps this instance into a binary string

Note: needed for Marshal module support

Returns:

  • (String)


41
42
43
44
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/table.rb', line 41

def _dump(*)
  # int32_t, int32_t, int32_t, int32_t, int32_t, int16_t *
  [@dim, @x, @y, @z, @x * @y * @z, *@data].pack("llllls*")
end