Class: Table
- Inherits:
-
Object
- Object
- Table
- 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
-
#data ⇒ Object
Returns the value of attribute data.
-
#dim ⇒ Object
Returns the value of attribute dim.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
-
#z ⇒ Object
Returns the value of attribute z.
Class Method Summary collapse
-
._load(serialized_string) ⇒ Table
Creates a new instance using the given binary data.
-
.json_new(*args) ⇒ Table
Returns a table instance for JSON deserialization.
-
.new_serialized(serialized_string) ⇒ Table
Creates a new instance from a serialized string.
Instance Method Summary collapse
-
#_dump ⇒ String
Dumps this instance into a binary string.
-
#initialize(xsize, ysize = 0, zsize = 0) ⇒ Table
constructor
Creates a Table object.
Methods included from RgssDb::JsonableConstructor
Methods included from RgssDb::Jsonable
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.
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
#data ⇒ Object
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 |
#dim ⇒ Object
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 |
#x ⇒ Object
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 |
#y ⇒ Object
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 |
#z ⇒ Object
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
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
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
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
#_dump ⇒ String
Dumps this instance into a binary string
Note: needed for Marshal module support
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 |