2021-06-29 05:28:17 +02:00
|
|
|
#include "framework.h"
|
|
|
|
#include "GameScriptColor.h"
|
|
|
|
|
2021-07-20 17:48:39 +01:00
|
|
|
/***
|
2021-07-23 02:06:50 +01:00
|
|
|
An RGBA or RGB color.
|
|
|
|
Components are specified in bytes; all values are clamped to [0, 255].
|
2021-07-20 17:48:39 +01:00
|
|
|
|
2021-08-23 19:16:24 +01:00
|
|
|
@miscclass Color
|
2021-07-20 17:48:39 +01:00
|
|
|
@pragma nostrip
|
|
|
|
*/
|
|
|
|
|
|
|
|
void GameScriptColor::Register(sol::state* state)
|
|
|
|
{
|
|
|
|
state->new_usertype<GameScriptColor>("Color",
|
2021-08-07 19:03:27 +01:00
|
|
|
sol::constructors<GameScriptColor(byte, byte, byte), GameScriptColor(byte, byte, byte, byte)>(),
|
2021-07-20 17:48:39 +01:00
|
|
|
|
|
|
|
/// (int) red component
|
2021-07-23 02:06:50 +01:00
|
|
|
//@mem r
|
|
|
|
"r", sol::property(&GameScriptColor::GetR, &GameScriptColor::SetR),
|
2021-07-20 17:48:39 +01:00
|
|
|
|
|
|
|
/// (int) green component
|
2021-07-23 02:06:50 +01:00
|
|
|
//@mem g
|
|
|
|
"g", sol::property(&GameScriptColor::GetG, &GameScriptColor::SetG),
|
2021-07-20 17:48:39 +01:00
|
|
|
|
|
|
|
/// (int) blue component
|
2021-07-23 02:06:50 +01:00
|
|
|
//@mem b
|
|
|
|
"b", sol::property(&GameScriptColor::GetB, &GameScriptColor::SetB),
|
2021-07-20 17:48:39 +01:00
|
|
|
|
|
|
|
/// (int) alpha component (255 is opaque, 0 is invisible)
|
2021-07-23 02:06:50 +01:00
|
|
|
//@mem a
|
|
|
|
"a", sol::property(&GameScriptColor::GetA, &GameScriptColor::SetA)
|
2021-07-20 17:48:39 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
@int R red component
|
|
|
|
@int G green component
|
|
|
|
@int B blue component
|
|
|
|
@return A Color object.
|
|
|
|
@function Color.new
|
|
|
|
*/
|
2021-06-29 05:28:17 +02:00
|
|
|
GameScriptColor::GameScriptColor(byte r, byte g, byte b)
|
|
|
|
{
|
|
|
|
SetR(r);
|
|
|
|
SetG(g);
|
|
|
|
SetB(b);
|
|
|
|
}
|
|
|
|
|
2021-07-20 17:48:39 +01:00
|
|
|
/***
|
|
|
|
@int R red component
|
|
|
|
@int G green component
|
|
|
|
@int B blue component
|
|
|
|
@int A alpha component (255 is opaque, 0 is invisible)
|
|
|
|
@return A Color object.
|
|
|
|
@function Color.new
|
|
|
|
*/
|
2021-08-07 19:03:27 +01:00
|
|
|
GameScriptColor::GameScriptColor(byte r, byte g, byte b, byte a) : GameScriptColor(r, g, b)
|
2021-06-29 05:28:17 +02:00
|
|
|
{
|
|
|
|
SetA(a);
|
|
|
|
}
|
|
|
|
|
2021-07-21 18:18:51 +01:00
|
|
|
GameScriptColor::GameScriptColor(Vector3 const& col) : GameScriptColor{ col.x, col.y, col.z } {}
|
|
|
|
|
|
|
|
GameScriptColor::GameScriptColor(Vector4 const& col) : GameScriptColor{ col.x, col.y, col.z, col.w } {}
|
|
|
|
|
|
|
|
GameScriptColor::operator Vector3() const
|
|
|
|
{
|
|
|
|
return Vector3{ float(r), float(g), float(b) };
|
|
|
|
}
|
|
|
|
|
|
|
|
GameScriptColor::operator Vector4() const
|
|
|
|
{
|
|
|
|
return Vector4{ float(r), float(g), float(b), float(a) };
|
|
|
|
}
|
|
|
|
|
2021-07-24 12:26:48 +01:00
|
|
|
byte GameScriptColor::GetR() const
|
2021-06-29 05:28:17 +02:00
|
|
|
{
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameScriptColor::SetR(byte v)
|
|
|
|
{
|
|
|
|
r = std::clamp<byte>(v, 0, 255);
|
|
|
|
}
|
|
|
|
|
2021-07-24 12:26:48 +01:00
|
|
|
byte GameScriptColor::GetG() const
|
2021-06-29 05:28:17 +02:00
|
|
|
{
|
|
|
|
return g;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameScriptColor::SetG(byte v)
|
|
|
|
{
|
|
|
|
g = std::clamp<byte>(v, 0, 255);
|
|
|
|
}
|
|
|
|
|
2021-07-24 12:26:48 +01:00
|
|
|
byte GameScriptColor::GetB() const
|
2021-06-29 05:28:17 +02:00
|
|
|
{
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameScriptColor::SetB(byte v)
|
|
|
|
{
|
|
|
|
b = std::clamp<byte>(v, 0, 255);
|
|
|
|
}
|
|
|
|
|
2021-07-24 12:26:48 +01:00
|
|
|
byte GameScriptColor::GetA() const
|
2021-06-29 05:28:17 +02:00
|
|
|
{
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameScriptColor::SetA(byte v)
|
|
|
|
{
|
|
|
|
a = std::clamp<byte>(v, 0, 255);
|
2021-07-23 02:06:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
@tparam Color color this color
|
|
|
|
@treturn string A string showing the r, g, b, and a values of the color
|
|
|
|
@function __tostring
|
|
|
|
*/
|
|
|
|
std::string GameScriptColor::ToString() const
|
|
|
|
{
|
|
|
|
return "{" + std::to_string(r) + ", " + std::to_string(g) + ", " + std::to_string(b) + ", " + std::to_string(a) + "}";
|
|
|
|
}
|