I have made a Table class, equal to the RGSS one, which includes Marshal dump and load methods. You should be asking, why to use this, if it is equal to the RMXP/VX one, but this was designed for pure ruby, where the RGSS classes doens't exist. So with this script you will be able to load some .rxdata/.rvdata, which uses the Table class, with .rb programs, and also edit them and save them again.
And also I include here my BigTable class, which was designed for RPG Advanced Editor. This Table class allows to use upto 4294967296 numbers, insteand of the 65535 of the normal Table class.
Update - 25/03/09
I have made time ago Color and Tone classes with their marshal methods, again for my project RPG Advanced Editor. Here are both classes, and also the last version of the Table class.
Color:
Tone:
And my last version of Table:
- class Table
- def initialize(x,y=1,z=1)
- @xsize,@ysize,@zsize=x,y,z
- @data=Array.new(x*y*z, 0)
- end
- def [](x,y=0,z=0)
- @data[x+y*@xsize+z*@xsize*@ysize]
- end
- def []=(*args)
- x=args[0]
- y=args.size>2 ?args[1]:0
- z=args.size>3 ?args[2]:0
- v=args.pop
- @data[x+y*@xsize+z*@xsize*@ysize]=v
- end
- def _dump(d=0)
- s=[3].pack('L')
- s+=[@xsize].pack('L')+[@ysize].pack('L')+[@zsize].pack('L')
- s+=[@xsize*@ysize*@zsize].pack('L')
- for z in 0...@zsize
- for y in 0...@ysize
- for x in 0...@xsize
- s+=[@data[x+y*@xsize+z*@xsize*@ysize],0,0].pack('L')[0,2]
- end
- end
- end
- s
- end
- attr_reader(:xsize,:ysize,:zsize,:data)
- class << self
- def _load(s)
- size=s[0,4].unpack('L')[0]
- nx=s[4,4].unpack('L')[0]
- ny=s[8,4].unpack('L')[0]
- nz=s[12,4].unpack('L')[0]
- data=[]
- pointer=20
- loop do
- data.push((s[pointer,2]+"\000\000").unpack('L')[0])
- pointer+=2
- break if pointer > s.size-1
- end
- t=Table.new(nx,ny,nz)
- n=0
- for z in 0...nz
- for y in 0...ny
- for x in 0...nx
- t[x,y,z]=data[n]
- n+=1
- end
- end
- end
- t
- end
- end
- end
Expand to see the code.
And also I include here my BigTable class, which was designed for RPG Advanced Editor. This Table class allows to use upto 4294967296 numbers, insteand of the 65535 of the normal Table class.
- class BigTable
- def initialize(x, y = 1, z = 1)
- x = [x, 256 ** 4].min
- y = [y, 256 ** 4].min
- z = [z, 256 ** 4].min
- @xsize, @ysize, @zsize = x, y, z
- @data = Array.new(x * y * z, 0)
- end
- def [](x, y = 0, z = 0)
- x = [x, @xsize].min
- y = [y, @ysize].min
- z = [z, @zsize].min
- @data[x + y * @xsize + z * @xsize * @ysize]
- end
- def []=(*args)
- x = [args[0], @xsize].min
- y = [args.size>2 ?args[1] : 0, @ysize].min
- z = [args.size>3 ?args[2] : 0, @zsize].min
- v = [args.pop, 256 ** 4].min
- @data[x + y * @xsize + z * @xsize * @ysize] = v
- end
- def _dump(d = 0)
- s = [3].pack('L')
- s += [@xsize].pack('L') + [@ysize].pack('L') + [@zsize].pack('L')
- s += [@xsize * @ysize * @zsize].pack('L')
- for z in 0...@zsize
- for y in 0...@ysize
- for x in 0...@xsize
- s += [@data[x + y * @xsize + z * @xsize * @ysize]].pack('L')
- end
- end
- end
- s
- end
- attr_reader(:xsize, :ysize, :zsize, :data)
- class << self
- def _load(s)
- nx = s[0, 4].unpack('L')[0]
- ny = s[4, 4].unpack('L')[0]
- nz = s[8, 4].unpack('L')[0]
- size = s[12, 4].unpack('L')[0]
- data = []
- pointer = 16
- loop do
- data.push(s[pointer, 4].unpack('L')[0])
- pointer += 4
- break if pointer > s.size - 1
- end
- t = BigTable.new(nx, ny, nz)
- n = 0
- for z in 0...nz
- for y in 0...ny
- for x in 0...nx
- t[x, y, z] = data[n]
- n += 1
- end
- end
- end
- t
- end
- end
- end
Expand to see the code.
Update - 25/03/09
I have made time ago Color and Tone classes with their marshal methods, again for my project RPG Advanced Editor. Here are both classes, and also the last version of the Table class.
Color:
- class Color
- def initialize(r, g, b, a = 255)
- @red = r
- @green = g
- @blue = b
- @alpha = a
- end
- def set(r, g, b, a = 255)
- @red = r
- @green = g
- @blue = b
- @alpha = a
- end
- def color
- Color.new(@red, @green, @blue, @alpha)
- end
- def _dump(d = 0)
- [@red, @green, @blue, @alpha].pack('d4')
- end
- def self._load(s)
- Color.new(*s.unpack('d4'))
- end
- attr_accessor(:red, :green, :blue, :alpha)
- end
Expand to see the code.
Tone:
- class Tone
- def initialize(r, g, b, a = 0)
- @red = r
- @green = g
- @blue = b
- @gray = a
- end
- def set(r, g, b, a = 0)
- @red = r
- @green = g
- @blue = b
- @gray = a
- end
- def color
- Color.new(@red, @green, @blue, @gray)
- end
- def _dump(d = 0)
- [@red, @green, @blue, @gray].pack('d4')
- end
- def self._load(s)
- Tone.new(*s.unpack('d4'))
- end
- attr_accessor(:red, :green, :blue, :gray)
- end
Expand to see the code.
And my last version of Table:
- class Table
- def initialize(x, y = 1, z = 1)
- @xsize, @ysize, @zsize = x, y, z
- @data = Array.new(x * y * z, 0)
- end
- def [](x, y = 0, z = 0)
- @data[x + y * @xsize + z * @xsize * @ysize]
- end
- def []=(*args)
- x = args[0]
- y = args.size > 2 ? args[1] :0
- z = args.size > 3 ? args[2] :0
- v = args.pop
- @data[x + y * @xsize + z * @xsize * @ysize] = v
- end
- def _dump(d = 0)
- s = [3].pack('L')
- s += [@xsize].pack('L') + [@ysize].pack('L') + [@zsize].pack('L')
- s += [@xsize * @ysize * @zsize].pack('L')
- for z in 0...@zsize
- for y in 0...@ysize
- for x in 0...@xsize
- s += [@data[x + y * @xsize + z * @xsize * @ysize]].pack('S')
- end
- end
- end
- s
- end
- def self._load(s)
- size = s[0, 4].unpack('L')[0]
- nx = s[4, 4].unpack('L')[0]
- ny = s[8, 4].unpack('L')[0]
- nz = s[12, 4].unpack('L')[0]
- data = []
- pointer = 20
- loop do
- data.push(*s[pointer, 2].unpack('S'))
- pointer += 2
- break if pointer > s.size - 1
- end
- t = Table.new(nx, ny, nz)
- n = 0
- for z in 0...nz
- for y in 0...ny
- for x in 0...nx
- t[x, y, z] = data[n]
- n += 1
- end
- end
- end
- t
- end
- attr_reader(:xsize, :ysize, :zsize, :data)
- end
Expand to see the code.