SHARE
TWEET

RMXP Hidden Classes

ForeverZer0 Jul 28th, 2014 220 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Sprite
  2. end
  3.  
  4. class Table
  5.   attr_reader :xsize, :ysize, :zsize
  6.  
  7.   # 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.
  8.  
  9.   def initialize(xsize, ysize=1, zsize=1)
  10.     @xsize = xsize
  11.     @ysize = ysize
  12.     @zsize = zsize
  13.     @data  = Array.new(@xsize*@ysize*@zsize, 0)
  14.   end
  15.  
  16.   # Changes the size of the array. All data from before the size change is retained.
  17.  
  18.   def resize(xsize, ysize=1, zsize=1)
  19.  
  20.         xsize = [1, xsize].max
  21.         ysize = [1, ysize].max
  22.         zsize = [1, zsize].max
  23.        
  24.     copyX = [@xsize, xsize].min
  25.         copyY = [@ysize, ysize].min
  26.         copyZ = [@zsize, zsize].min
  27.  
  28.         data = Array.new(xsize * ysize * zsize, 0)
  29.         (0...copyX).each {|x| (0...copyY).each {|y| (0...copyZ).each {|z|
  30.           data[x + xsize * (y + ysize * z)] = @data[x + @xsize * (y + @ysize * z)];
  31.         }}}
  32.         @xsize = xsize
  33.         @ysize = ysize
  34.         @zsize = zsize
  35.         @data = data
  36.   end
  37.  
  38.   # :call-seq:
  39.   # self[x]
  40.   # self[x, y]
  41.   # self[x, y, z]
  42.   #
  43.   # Accesses the array's elements. Pulls the same number of arguments as there are dimensions in the created array. Returns nil if the specified element does not exist.
  44.  
  45.   def [](x, y=0, z=0)
  46.     return 0 if x >= @xsize or y >= @ysize
  47.     v = @data[x + y * @xsize + z * @xsize * @ysize]
  48.         return v == nil ? 0 : v
  49.   end
  50.  
  51.   def []=(x, y=0, z=0, v) #:nodoc:
  52.     @data[x + y * @xsize + z * @xsize * @ysize]=v
  53.   end
  54.  
  55.   def self._load(s) #:nodoc:
  56.     Table.new(1).instance_eval {
  57.       @size, @xsize, @ysize, @zsize, xx, *@data = s.unpack('LLLLLS*')
  58.       self
  59.     }
  60.   end
  61.  
  62.   def _dump(d = 0) #:nodoc:
  63.     [@size, @xsize, @ysize, @zsize, @xsize*@ysize*@zsize, *@data].pack('LLLLLS*')
  64.   end
  65. end
  66.  
  67.  
  68. class Tone
  69.    def initialize(r, g, b, a = 0)
  70.       @red = r
  71.       @green = g
  72.       @blue = b
  73.       @gray = a
  74.    end
  75.    def set(r, g, b, a = 0)
  76.       @red = r
  77.       @green = g
  78.       @blue = b
  79.       @gray = a
  80.    end
  81.    def color
  82.       Color.new(@red, @green, @blue, @gray)
  83.    end
  84.    def _dump(d = 0)
  85.       [@red, @green, @blue, @gray].pack('d4')
  86.    end
  87.    def self._load(s)
  88.       Tone.new(*s.unpack('d4'))
  89.    end
  90.    attr_accessor(:red, :green, :blue, :gray)
  91. end
  92.  
  93.  
  94. class Color
  95.    def initialize(r, g, b, a = 255)
  96.       @red = r
  97.       @green = g
  98.       @blue = b
  99.       @alpha = a
  100.    end
  101.    def set(r, g, b, a = 255)
  102.       @red = r
  103.       @green = g
  104.       @blue = b
  105.       @alpha = a
  106.    end
  107.    def color
  108.       Color.new(@red, @green, @blue, @alpha)
  109.    end
  110.    def _dump(d = 0)
  111.       [@red, @green, @blue, @alpha].pack('d4')
  112.    end
  113.    def self._load(s)
  114.       Color.new(*s.unpack('d4'))
  115.    end
  116.    attr_accessor(:red, :green, :blue, :alpha)
  117. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top