| 554 | } |
| 555 | |
| 556 | List<Drawable> ObjectDatabase::cursorHintDrawables(World const* world, String const& objectName, Vec2I const& position, |
| 557 | Direction direction, Json parameters) const { |
| 558 | List<Drawable> drawables; |
| 559 | |
| 560 | auto config = getConfig(objectName); |
| 561 | parameters = jsonMerge(config->config, parameters); |
| 562 | |
| 563 | if (auto placementImage = parameters.optString("placementImage")) { |
| 564 | if (direction == Direction::Left) |
| 565 | *placementImage += "?flipx"; |
| 566 | drawables = {Drawable::makeImage(AssetPath::relativeTo(config->path, *placementImage), |
| 567 | 1.0 / TilePixels, false, Vec2F(position) + jsonToVec2F(parameters.get("placementImagePosition")) / TilePixels)}; |
| 568 | } else { |
| 569 | size_t orientationIndex = config->findValidOrientation(world, position, direction); |
| 570 | if (orientationIndex == NPos) { |
| 571 | // If we aren't in a valid orientation, still need to draw something at |
| 572 | // the cursor. Draw the first orientation whose direction affinity |
| 573 | // matches our current direction, or if that fails just the first |
| 574 | // orientation. |
| 575 | List<Drawable> result; |
| 576 | for (size_t i = 0; i < config->orientations.size(); ++i) { |
| 577 | if (config->orientations[i]->directionAffinity == direction) |
| 578 | orientationIndex = i; |
| 579 | } |
| 580 | if (orientationIndex == NPos) |
| 581 | orientationIndex = 0; |
| 582 | } |
| 583 | |
| 584 | auto orientation = config->orientations.at(orientationIndex); |
| 585 | for (auto const& layer : orientation->imageLayers) { |
| 586 | Drawable drawable = layer; |
| 587 | auto& image = drawable.imagePart().image; |
| 588 | image = AssetPath::join(image).replaceTags(StringMap<String>(), true, "default"); |
| 589 | if (orientation->flipImages) |
| 590 | drawable.scale(Vec2F(-1, 1), drawable.boundBox(false).center() - drawable.position); |
| 591 | drawables.append(std::move(drawable)); |
| 592 | } |
| 593 | Drawable::translateAll(drawables, Vec2F(position) + orientation->imagePosition); |
| 594 | } |
| 595 | |
| 596 | return drawables; |
| 597 | } |
| 598 | |
| 599 | } |
nothing calls this directly
no test coverage detected