Built in Color Class
Version -
Author Enterbrain/cmpsr2000
Release Date August 15, 2008
Exclusive Script at RPG RPG RevolutionIntroductionThis is a reverse-engineered equivalent of the RGSS2 built in Color Class. The RGSS equivalent would be identical, minus the alpha attribute. Using this along with the equivalent Table Class over at RMXP.org and the RPG module will allow developers to fully interact with the .rvdata files in the Ruby runtime in order to build their own applications on top of the RGSS2 data structures.
ScriptCODE
#================================================================
#
# Enterbrain's RGSS2 Color Class
# by cmpsr2000 @ rpgrevolution.com
#
#================================================================
class Color
#=============================================================
# initialize - creates a new Color object
# red : the RGB red value of this color : 0-255(F)
# green : the RGB green value of this color : 0-255(F)
# blue : the RGB blue value of this color : 0-255(F)
# alpha : the alpha value of this color : 0-255(F)
#=============================================================
def initialize(red, green, blue, alpha = 255)
set(red, green, blue, alpha)
end
#=============================================================
# set - sets all attributes simultaneously
# red : the RGB red value of this color : 0-255(F)
# green : the RGB green value of this color : 0-255(F)
# blue : the RGB blue value of this color : 0-255(F)
# alpha : the alpha value of this color : 0-255(F)
#=============================================================
def set(red, green, blue, alpha = 255)
self.red = red
self.green = green
self.blue = blue
self.alpha = alpha
end
#=============================================================
# attr_accessor :red - includes OOR value checking
def red
@red
end
def red=(amount)
if amount < 0
amount = 0
elsif amount > 255
amount = 255
end
@red = amount.to_f
end
#
#==============================================================
#==============================================================
# attr_accessor :blue - includes OOR value checking
def blue
@blue
end
def blue=(amount)
if amount < 0
amount = 0
elsif amount > 255
amount = 255
end
@blue = amount.to_f
end
#
#==============================================================
#==============================================================
# attr_accessor :green - includes OOR value checking
def green
@green
end
def green=(amount)
if amount < 0
amount = 0
elsif amount > 255
amount = 255
end
@green = amount.to_f
end
#
#==============================================================
#==============================================================
# attr_accessor :alpha - includes OOR value checking
def alpha
@alpha
end
def alpha=(amount)
if amount < 0
amount = 0
elsif amount > 255
amount = 255
end
@alpha = amount.to_f
end
#
#==============================================================
#==============================================================
# _dump - handler for Marshal.dump, serializes this object
# d : depth level
# RETURNS : string
#==============================================================
def _dump(d = 0)
s = [@red, @green, @blue, @alpha].pack("DDDD")
return s
end
#==============================================================
# self._load - static handler for Marshal.load, deserializes
# this object
# s : string to deserialize
# RETURNS : Color
#==============================================================
def self._load(s)
vals = s.unpack("DDDD")
c = Color.new(vals[0], vals[1], vals[2], vals[3])
return c
end
end
Customizationnone.
CompatibilityRGSS2 only
Terms and ConditionsFree to use in all projects so long as the credit stub at the top remains.
CreditsThanks to Enterbrain for the RPGM series.