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

Method orientationDrawables

source/game/StarObject.cpp:1252–1304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1250}
1251
1252List<Drawable> Object::orientationDrawables(size_t orientationIndex) const {
1253 if (orientationIndex == NPos)
1254 return {};
1255
1256 auto& orientation = getOrientations().at(orientationIndex);
1257
1258 if (!m_orientationDrawablesCache || orientationIndex != m_orientationDrawablesCache->first) {
1259 m_orientationDrawablesCache = make_pair(orientationIndex, List<Drawable>());
1260 for (auto const& layer : orientation->imageLayers) {
1261 Drawable drawable = layer;
1262
1263 auto& imagePart = drawable.imagePart();
1264 imagePart.image.directives.clear();
1265 String imagePath = AssetPath::join(imagePart.image);
1266 if ((m_colorDirectives || !m_colorSuffix.empty()) && m_imageKeys.contains("color")) { // We had to leave color untouched despite separating its directives for server-side compatibility reasons, temporarily substr it in the image key
1267 String& color = m_imageKeys.find("color")->second;
1268 String backup = std::move(color);
1269 color = backup.substr(0, backup.find('?'));
1270
1271 // backwards compatibility for this is really annoying, need to append text after the <color> tag to the last directive for a rare use-case
1272 auto& image = imagePath.utf8();
1273 size_t suffix = NPos;
1274 if (!m_colorSuffix.empty() && (suffix = image.rfind("<color>")) != NPos)
1275 imagePart.image = String(image.substr(0, (suffix += 7))).replaceTags(m_imageKeys, true, "default");
1276 else
1277 imagePart.image = imagePath.replaceTags(m_imageKeys, true, "default");
1278
1279 color = std::move(backup);
1280
1281 imagePart.image.directives = layer.imagePart().image.directives;
1282 if (m_colorDirectives)
1283 imagePart.addDirectives(m_colorDirectives);
1284 if (suffix != NPos)
1285 imagePart.addDirectives(m_colorSuffix + String(image.substr(suffix)).replaceTags(m_imageKeys, true, "default"));
1286 }
1287 else {
1288 imagePart.image = imagePath.replaceTags(m_imageKeys, true, "default");
1289 imagePart.image.directives = layer.imagePart().image.directives;
1290 }
1291
1292 imagePart.addDirectives(m_directives);
1293
1294 if (orientation->flipImages)
1295 drawable.scale(Vec2F(-1, 1), drawable.boundBox(false).center() - drawable.position);
1296
1297 m_orientationDrawablesCache->second.append(std::move(drawable));
1298 }
1299 }
1300
1301 auto drawables = m_orientationDrawablesCache->second;
1302 Drawable::translateAll(drawables, orientation->imagePosition + damageShake());
1303 return drawables;
1304}
1305
1306EntityRenderLayer Object::renderLayer() const {
1307 if (auto orientation = currentOrientation())

Callers

nothing calls this directly

Calls 14

StringClass · 0.85
addDirectivesMethod · 0.80
joinFunction · 0.50
atMethod · 0.45
clearMethod · 0.45
emptyMethod · 0.45
containsMethod · 0.45
findMethod · 0.45
substrMethod · 0.45
replaceTagsMethod · 0.45
scaleMethod · 0.45
centerMethod · 0.45

Tested by

no test coverage detected