MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / jsonToColor

Function jsonToColor

source/core/StarJsonExtra.cpp:212–230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

210}
211
212Color jsonToColor(Json const& v) {
213 if (v.type() == Json::Type::Array) {
214 if (v.type() != Json::Type::Array || (v.size() != 3 && v.size() != 4))
215 throw JsonException("Json not an array of size 3 or 4 in jsonToColor");
216 Color c = Color::rgba(0, 0, 0, 255);
217 c.setRed(v.getInt(0));
218 c.setGreen(v.getInt(1));
219 c.setBlue(v.getInt(2));
220
221 if (v.size() == 4)
222 c.setAlpha(v.getInt(3));
223
224 return c;
225 } else if (v.type() == Json::Type::String) {
226 return Color(v.toString());
227 } else {
228 throw JsonException(strf("Json of type {} cannot be converted to color", v.typeName()));
229 }
230}
231
232Json jsonFromColor(Color const& color) {
233 JsonArray result;

Callers 15

HumanoidIdentityMethod · 0.85
biomeSkyColoringMethod · 0.85
processActionMethod · 0.85
WorldStructureMethod · 0.85
ParticleMethod · 0.85
TileDrawerMethod · 0.85
MaterialDatabaseMethod · 0.85
SkyColoringMethod · 0.85

Calls 11

ColorClass · 0.85
strfFunction · 0.85
setRedMethod · 0.80
getIntMethod · 0.80
setGreenMethod · 0.80
setBlueMethod · 0.80
setAlphaMethod · 0.80
typeMethod · 0.45
sizeMethod · 0.45
toStringMethod · 0.45
typeNameMethod · 0.45

Tested by 1

InspectionToolMethod · 0.68