Class: Color

Inherits:
Object
  • Object
show all
Extended by:
RgssDb::JsonableConstructor
Includes:
RgssDb::Jsonable
Defined in:
lib/rgss_db/model/rpg_maker_data/vx/rgss/color.rb,
lib/rgss_db/model/rpg_maker_data/xp/rgss/color.rb,
lib/rgss_db/model/rpg_maker_data/vx_ace/rgss/color.rb

Overview

The RGBA color class.

Each component is handled with a floating-point value (Float).

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(red = 0, green = 0, blue = 0, alpha = 0) ⇒ Color

Creates a Color object. If alpha is omitted, it is assumed to be 255.

The default values when no arguments are specified are (0, 0, 0, 0).

Parameters:

  • red (Integer) (defaults to: 0)
  • green (Integer) (defaults to: 0)
  • blue (Integer) (defaults to: 0)
  • alpha (Integer) (defaults to: 0)


22
23
24
25
26
27
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/color.rb', line 22

def initialize(red = 0, green = 0, blue = 0, alpha = 0)
  @red = red
  @green = green
  @blue = blue
  @alpha = [red, green, blue].sum.positive? && alpha.zero? ? 255 : alpha
end

Instance Attribute Details

#alphaObject

Returns the value of attribute alpha.



71
72
73
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/color.rb', line 71

def alpha
  @alpha
end

#blueObject

Returns the value of attribute blue.



71
72
73
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/color.rb', line 71

def blue
  @blue
end

#greenObject

Returns the value of attribute green.



71
72
73
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/color.rb', line 71

def green
  @green
end

#redObject

Returns the value of attribute red.



71
72
73
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/color.rb', line 71

def red
  @red
end

Class Method Details

._load(serialized_string) ⇒ Color

Creates a new instance using the given binary data

Note: needed for Marshal module support

Parameters:

  • serialized_string (String)

Returns:



50
51
52
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/color.rb', line 50

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

.new_serialized(serialized_string) ⇒ Color

Creates a new instance from a serialized string

Note: needed for Marshal module support

Parameters:

  • serialized_string (String)

Returns:



63
64
65
66
67
68
69
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/color.rb', line 63

def self.new_serialized(serialized_string)
  # double, double, double, double (double-precision)
  red, green, blue, alpha = serialized_string.unpack("dddd")

  # Creates the instance
  Color.new(red, green, blue, alpha)
end

Instance Method Details

#_dumpString

Dumps this instance into a binary string

Note: needed for Marshal module support

Returns:

  • (String)


36
37
38
39
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/color.rb', line 36

def _dump(*)
  # double, double, double, double (double-precision)
  [@red, @green, @blue, @alpha].pack("dddd")
end