 |
Blamite Game Engine - blam!
00285.12.18.20.1411.blamite
The core library for the Blamite Game Engine.
|
Go to the documentation of this file.
7 #include <Strings/components/utils/string/string.h>
9 #define GVARS_FILE "./globals.xml"
23 unsigned char r = 255;
24 unsigned char g = 255;
25 unsigned char b = 255;
26 unsigned char a = 255;
59 return std::string(std::to_string(
r) +
"," + std::to_string(
g) +
"," + std::to_string(
b) +
"," + std::to_string(
a));
112 int color_int = 0xFFFFFFFF;
114 char* color_int_ptr = (
char*)&color_int;
116 memcpy(color_int_ptr + 3, &
r, 1);
117 memcpy(color_int_ptr + 2, &
g, 1);
118 memcpy(color_int_ptr + 1, &
b, 1);
119 memcpy(color_int_ptr, &
a, 1);
142 std::string new_string = format;
144 new_string = BlamStrings::Utils::String::Replace(new_string,
"{r}", std::to_string(
r));
145 new_string = BlamStrings::Utils::String::Replace(new_string,
"{g}", std::to_string(
g));
146 new_string = BlamStrings::Utils::String::Replace(new_string,
"{b}", std::to_string(
b));
147 new_string = BlamStrings::Utils::String::Replace(new_string,
"{a}", std::to_string(
a));
149 double r_float = (double)
r / 255.0f;
150 double g_float = (double)
g / 255.0f;
151 double b_float = (double)
b / 255.0f;
152 double a_float = (double)
a / 255.0f;
154 new_string = BlamStrings::Utils::String::Replace(new_string,
"{r>f}", std::to_string(r_float));
155 new_string = BlamStrings::Utils::String::Replace(new_string,
"{g>f}", std::to_string(g_float));
156 new_string = BlamStrings::Utils::String::Replace(new_string,
"{b>f}", std::to_string(b_float));
157 new_string = BlamStrings::Utils::String::Replace(new_string,
"{a>f}", std::to_string(a_float));
169 return ToString(
"rgba({r},{g},{b},{a>f})");
183 std::vector<std::string> color_values = BlamStrings::Utils::String::Split(
string,
",");
185 if (color_values.size() == 3)
187 r = atoi(color_values.at(0).c_str());
188 g = atoi(color_values.at(1).c_str());
189 b = atoi(color_values.at(2).c_str());
194 else if (color_values.size() == 4)
196 r = atoi(color_values.at(0).c_str());
197 g = atoi(color_values.at(1).c_str());
198 b = atoi(color_values.at(2).c_str());
199 a = atoi(color_values.at(3).c_str());
Namespace surrounding all major engine components.
Definition: blam_api.h:18
BlamColor()
Definition: globals.h:28
BLAM void RegisterGvar(EngineGlobal var)
Registers a new engine global.
Definition: globals.cpp:65
BLAM EngineGlobal * GetGlobal(std::string name)
Retrieves a global with the specified ID.
Definition: globals.cpp:193
BLAM bool GlobalExists(std::string id)
Determines whether or not a global exists.
Definition: globals.cpp:27
float float_value
The float value of the global.
Definition: globals.h:272
std::string info
An optional description of the global.
Definition: globals.h:260
@ Int
Represents an int.
Definition: globals.h:241
BlamColor color_value
The color value of the global.
Definition: globals.h:273
int GetColorAsInt()
Gets the color's value as an integer.
Definition: globals.h:110
@ UnknownGlobal
The specified global does not exist.
Definition: globals.h:223
@ Long
Represents a long.
Definition: globals.h:238
@ GlobalIsProtected
The specified global is protected and cannot be modified during runtime.
Definition: globals.h:227
BLAM bool LoadGlobalsFromFile()
Loads any globals from GVARS_FILE.
Definition: globals.cpp:206
BLAM float * GetGlobalAsFloat(std::string name)
Retrieves a global's value as a float.
Definition: globals.cpp:400
@ InvalidArgs
The provided arguments were invalid.
Definition: globals.h:225
@ Real
Unknown. Referenced within the hs_doc from Halo 2 Sapien.
Definition: globals.h:236
BLAM GvarUpdateResult UpdateGlobalWrap(std::string name, std::string new_value)
Updates a global's raw value.
Definition: globals.cpp:428
unsigned char a
The Alpha value of the color.
Definition: globals.h:26
bool read_only
Whether or not the global is protected from modification.
Definition: globals.h:262
std::string name
The name of the global.
Definition: globals.h:259
GvarType
Enumerator for the type of global variable.
Definition: globals.h:233
short short_value
The short value of the global.
Definition: globals.h:269
BLAM BlamColor * GetGlobalAsColor(std::string name)
Retrieves a global's value as a BlamColor.
Definition: globals.cpp:412
@ String
Represents a std::string.
Definition: globals.h:240
#define BLAM
Definition: globals.h:12
Structure containing data for a game engine global.
Definition: globals.h:256
@ Float
Represents a float.
Definition: globals.h:242
long long_value
The long value of the global.
Definition: globals.h:270
GvarUpdateResult
Enumerator for the result of a global update attempt.
Definition: globals.h:220
BLAM short * GetGlobalAsShort(std::string name)
Retrieves a global's value as a short.
Definition: globals.cpp:364
BlamColor(short _r, short _g, short _b)
Definition: globals.h:36
@ InvalidType
The provided value was of an invalid type.
Definition: globals.h:222
unsigned char g
The Green value of the color.
Definition: globals.h:24
@ Object
Unknown. Referenced within the hs_doc from Halo 2 Sapien.
Definition: globals.h:239
unsigned char b
The Blue value of the color.
Definition: globals.h:25
@ Short
Represents a short.
Definition: globals.h:237
float GetBlueAsFloat()
Gets the color's red value as a float, between 0 and 1.
Definition: globals.h:87
int int_value
The int value of the global.
Definition: globals.h:271
BLAM std::map< std::string, EngineGlobal > * GetGlobalsList()
Retrieves the list of loaded globals.
Definition: globals.cpp:22
@ OutOfBounds
The provided value was too small or too large for the globals' data type.
Definition: globals.h:226
BLAM long * GetGlobalAsLong(std::string name)
Retrieves a global's value as a long.
Definition: globals.cpp:376
@ Color
Represents a BlamColor. See BlamColor for details.
Definition: globals.h:243
float GetRedAsFloat()
Gets the color's red value as a float, between 0 and 1.
Definition: globals.h:67
@ Boolean
Represents a boolean. Can be true or false.
Definition: globals.h:235
float GetGreenAsFloat()
Gets the color's red value as a float, between 0 and 1.
Definition: globals.h:77
BLAM std::string * GetGlobalAsString(std::string name)
Retrieves a global's value as a string.
Definition: globals.cpp:352
std::string ToString()
Converts the color value to a string.
Definition: globals.h:57
std::string value_raw
The raw value of the global as a string.
Definition: globals.h:261
std::string ToStringForCSS()
Converts the color to a string that can be used with CSS.
Definition: globals.h:167
bool FromString(std::string string)
Attempts to set color information from a string.
Definition: globals.h:181
std::string ToString(std::string format)
Converts the color value to a string in the specified format.
Definition: globals.h:140
BlamColor(short _r, short _g, short _b, short _a)
Definition: globals.h:44
float GetAlphaAsFloat()
Gets the color's red value as a float, between 0 and 1.
Definition: globals.h:97
Structure representing a color.
Definition: globals.h:20
GvarType type
The type of the global.
Definition: globals.h:258
unsigned char r
The Red value of the color.
Definition: globals.h:23
@ Ok
The global was updated successfully.
Definition: globals.h:224
BLAM bool * GetGlobalAsBoolean(std::string name)
Retrieves a global's value as a boolean.
Definition: globals.cpp:340
bool boolean_value
The boolean value of the global.
Definition: globals.h:268
BLAM GvarUpdateResult UpdateGlobal(std::string name, std::string new_value)
Updates the value of a String global.
Definition: globals.cpp:571
BLAM std::string GetGvarTypeLabel(GvarType type)
Retrieves a string representation of a global's type, for use in UI.
Definition: globals.cpp:40
BLAM int * GetGlobalAsInteger(std::string name)
Retrieves a global's value as an int.
Definition: globals.cpp:388