Skip to content

Commit

Permalink
Add quest about tree leaf type (#5496)
Browse files Browse the repository at this point in the history
* better file name

* ask about leaf type of natural=tree

partial implementation of #83

* better English

Co-authored-by: Flo Edelmann <git@flo-edelmann.de>

* exclude cases where this info is implied by other tags

* add test to common test base

* skip more tags indicating leaf_type

* fix code and tests

* more readable filter

Co-authored-by: Flo Edelmann <git@flo-edelmann.de>

* collapse line

Co-authored-by: Flo Edelmann <git@flo-edelmann.de>

* smarter filter of already tagged data

Co-authored-by: Tobias Zwick <newton@westnordost.de>

* enable deleting trees in leaf type quest

* disable tree quest by default

* remove tests as requested

---------

Co-authored-by: Flo Edelmann <git@flo-edelmann.de>
Co-authored-by: Tobias Zwick <newton@westnordost.de>
  • Loading branch information
3 people authored Mar 3, 2024
1 parent 72b958b commit 77a19d3
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ import de.westnordost.streetcomplete.quests.internet_access.AddInternetAccess
import de.westnordost.streetcomplete.quests.kerb_height.AddKerbHeight
import de.westnordost.streetcomplete.quests.lanes.AddLanes
import de.westnordost.streetcomplete.quests.leaf_detail.AddForestLeafType
import de.westnordost.streetcomplete.quests.leaf_detail.AddTreeLeafType
import de.westnordost.streetcomplete.quests.level.AddLevel
import de.westnordost.streetcomplete.quests.max_height.AddMaxHeight
import de.westnordost.streetcomplete.quests.max_height.AddMaxPhysicalHeight
Expand Down Expand Up @@ -436,6 +437,7 @@ fun questTypeRegistry(
105 to AddSummitCross(), // summit markings are not necessarily directly at the peak, need to look around
106 to AddSummitRegister(), // register is harder to find than cross

165 to AddTreeLeafType(), // may need to get close in trickier cases
107 to AddForestLeafType(), // need to walk around in the highlighted section

108 to AddOrchardProduce(), // difficult to find out if the orchard does not carry fruits right now
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package de.westnordost.streetcomplete.quests.leaf_detail

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.user.achievements.EditTypeAchievement.OUTDOORS
import de.westnordost.streetcomplete.osm.Tags

class AddTreeLeafType : OsmFilterQuestType<TreeLeafType>() {
override val elementFilter = """
nodes with
natural = tree
and !leaf_type
and !~"(taxon|genus|species).*"
"""
override val changesetComment = "Specify leaf types"
override val wikiLink = "Key:leaf_type"
override val icon = R.drawable.ic_quest_leaf
override val isDeleteElementEnabled = true
override val achievements = listOf(OUTDOORS)
override val defaultDisabledMessage = R.string.default_disabled_msg_difficult_and_time_consuming

override fun getTitle(tags: Map<String, String>) = R.string.quest_leafType_tree_title

override fun getHighlightedElements(element: Element, getMapData: () -> MapDataWithGeometry) =
getMapData().filter("nodes with natural = tree".toElementFilterExpression())

override fun createForm() = AddTreeLeafTypeForm()

override fun applyAnswerTo(answer: TreeLeafType, tags: Tags, geometry: ElementGeometry, timestampEdited: Long) {
tags["leaf_type"] = answer.osmValue
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.westnordost.streetcomplete.quests.leaf_detail

import de.westnordost.streetcomplete.quests.AImageListQuestForm

class AddTreeLeafTypeForm : AImageListQuestForm<TreeLeafType, TreeLeafType>() {

override val items = TreeLeafType.entries.map { it.asItem() }
override val itemsPerRow = 2

override fun onClickOk(selectedItems: List<TreeLeafType>) {
applyAnswer(selectedItems.single())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package de.westnordost.streetcomplete.quests.leaf_detail

enum class TreeLeafType(val osmValue: String) {
NEEDLELEAVED("needleleaved"),
BROADLEAVED("broadleaved"),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package de.westnordost.streetcomplete.quests.leaf_detail

import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.quests.leaf_detail.TreeLeafType.BROADLEAVED
import de.westnordost.streetcomplete.quests.leaf_detail.TreeLeafType.NEEDLELEAVED
import de.westnordost.streetcomplete.view.image_select.Item

fun TreeLeafType.asItem() = Item(this, iconResId, titleResId)

private val TreeLeafType.titleResId: Int get() = when (this) {
NEEDLELEAVED -> R.string.quest_leaf_type_needles
BROADLEAVED -> R.string.quest_leaf_type_broadleaved
}

private val TreeLeafType.iconResId: Int get() = when (this) {
NEEDLELEAVED -> R.drawable.leaf_type_needleleaved
BROADLEAVED -> R.drawable.leaf_type_broadleaved
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,7 @@ If any lanes are reserved for buses, please leave a note instead."</string>
<string name="quest_leaf_type_needles">Needles</string>
<string name="quest_leaf_type_broadleaved">Leaves</string>
<string name="quest_leaf_type_mixed">Both are present</string>
<string name="quest_leafType_tree_title">Does this tree have needles or leaves?</string>

<string name="quest_level_title2">On which level number is this place located?</string>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,22 @@ class AddAcceptsCardsTest {
)
assertEquals(1, questType.getApplicableElements(mapData).toList().size)
}

@Test fun `applicable to weird shop values`() {
val mapData = TestMapDataWithGeometry(
listOf(
node(1, tags = mapOf("shop" to "dgfygyug", "name" to "Foobar")),
),
)
assertEquals(1, questType.getApplicableElements(mapData).toList().size)
}

@Test fun `not applicable to vacant shop`() {
val mapData = TestMapDataWithGeometry(
listOf(
node(1, tags = mapOf("shop" to "vacant", "name" to "Foobar")),
),
)
assertEquals(0, questType.getApplicableElements(mapData).toList().size)
}
}

0 comments on commit 77a19d3

Please sign in to comment.