From 548fc8ed52b78ad9bcc5fe0c0956cfd6f25a9156 Mon Sep 17 00:00:00 2001 From: qugebert <44033795+qugebert@users.noreply.github.com> Date: Thu, 24 Aug 2023 12:58:17 +0200 Subject: [PATCH] Fix element highlightning in amenity_coverage In the AddAmenityCover-Task, getHighlightedElements(..) highlighted picnic_tables when asked for bbq nodes. Mostly copy&paste from the logik used in the CheckExistence-quest --- .../streetcomplete/quests/QuestsModule.kt | 2 +- .../quests/amenity_cover/AddAmenityCover.kt | 37 +++++++++++++++---- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/QuestsModule.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/QuestsModule.kt index ad82f820b1..062ed3a592 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/QuestsModule.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/QuestsModule.kt @@ -246,7 +246,7 @@ fun questTypeRegistry( 9 to AddCarWashType(), 10 to AddBenchBackrest(), - 11 to AddAmenityCover(), + 11 to AddAmenityCover(featureDictionaryFuture), 12 to AddBridgeStructure(), diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/amenity_cover/AddAmenityCover.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/amenity_cover/AddAmenityCover.kt index 2861ed4173..f51f03f851 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/amenity_cover/AddAmenityCover.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/amenity_cover/AddAmenityCover.kt @@ -1,26 +1,30 @@ package de.westnordost.streetcomplete.quests.amenity_cover +import de.westnordost.osmfeatures.FeatureDictionary import de.westnordost.streetcomplete.R +import de.westnordost.streetcomplete.data.elementfilter.toElementFilterExpression import de.westnordost.streetcomplete.data.osm.geometry.ElementGeometry import de.westnordost.streetcomplete.data.osm.mapdata.Element import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry -import de.westnordost.streetcomplete.data.osm.mapdata.filter -import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType +import de.westnordost.streetcomplete.data.osm.osmquests.OsmElementQuestType import de.westnordost.streetcomplete.data.user.achievements.EditTypeAchievement.OUTDOORS import de.westnordost.streetcomplete.osm.Tags import de.westnordost.streetcomplete.quests.YesNoQuestForm import de.westnordost.streetcomplete.util.ktx.toYesNo +import java.util.concurrent.FutureTask -class AddAmenityCover : OsmFilterQuestType() { +class AddAmenityCover ( + private val featureDictionaryFuture: FutureTask +) : OsmElementQuestType { - override val elementFilter = """ + private val nodesFilter by lazy { """ nodes with (leisure = picnic_table or amenity = bbq) and access !~ private|no and !covered and (!seasonal or seasonal = no) - """ + """.toElementFilterExpression() } override val changesetComment = "Specify whether various amenities are covered" override val wikiLink = "Key:covered" override val icon = R.drawable.ic_quest_picnic_table_cover @@ -28,9 +32,26 @@ class AddAmenityCover : OsmFilterQuestType() { override val achievements = listOf(OUTDOORS) override fun getTitle(tags: Map) = R.string.quest_amenityCover_title + override fun getApplicableElements(mapData: MapDataWithGeometry): Iterable = + mapData.filter { isApplicableTo(it) } - override fun getHighlightedElements(element: Element, getMapData: () -> MapDataWithGeometry) = - getMapData().filter("nodes with leisure = picnic_table") + override fun isApplicableTo(element: Element) = + nodesFilter.matches(element) && hasAnyName(element.tags) + + private fun hasAnyName(tags: Map): Boolean = + featureDictionaryFuture.get().byTags(tags).isSuggestion(false).find().isNotEmpty() + + override fun getHighlightedElements(element: Element, getMapData: () -> MapDataWithGeometry): Sequence { + /* put markers for objects that are exactly the same as for which this quest is asking for + e.g. it's a ticket validator? -> display other ticket validators. Etc. */ + val feature = featureDictionaryFuture.get() + .byTags(element.tags) + .isSuggestion(false) // not brands + .find() + .firstOrNull() ?: return emptySequence() + + return getMapData().filter { it.tags.containsAll(feature.tags) }.asSequence() + } override fun createForm() = YesNoQuestForm() @@ -38,3 +59,5 @@ class AddAmenityCover : OsmFilterQuestType() { tags["covered"] = answer.toYesNo() } } + +private fun Map.containsAll(other: Map) = other.all { this[it.key] == it.value }