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

Function jsonToRectI

source/core/StarJsonExtra.cpp:166–183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

164}
165
166RectI jsonToRectI(Json const& v) {
167 if (v.type() != Json::Type::Array)
168 throw JsonException("Json not an array in jsonToRectI");
169
170 if (v.size() != 4 && v.size() != 2)
171 throw JsonException("Json not an array of proper size in jsonToRectI");
172
173 if (v.size() == 4)
174 return RectI(v.getInt(0), v.getInt(1), v.getInt(2), v.getInt(3));
175
176 try {
177 auto lowerLeft = jsonToVec2I(v.get(0));
178 auto upperRight = jsonToVec2I(v.get(1));
179 return RectI(lowerLeft, upperRight);
180 } catch (JsonException const& e) {
181 throw JsonException(strf("Inner position not well formed in jsonToRectI: {}", outputException(e, true)));
182 }
183}
184
185Json jsonFromRectI(RectI const& rect) {
186 return JsonArray{rect.xMin(), rect.yMin(), rect.xMax(), rect.yMax()};

Callers 5

WorldStructureMethod · 0.85
ItemGridWidgetMethod · 0.85
commonMethod · 0.85
ItemSlotWidgetMethod · 0.85

Calls 7

jsonToVec2IFunction · 0.85
strfFunction · 0.85
getIntMethod · 0.80
outputExceptionFunction · 0.70
typeMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected