Skip to content

Commit

Permalink
ask about leaf type of natural=tree
Browse files Browse the repository at this point in the history
partial implementation of streetcomplete#83
  • Loading branch information
matkoniecz committed Feb 22, 2024
1 parent c0954cb commit b66f4e8
Show file tree
Hide file tree
Showing 6 changed files with 74 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 @@ -434,6 +435,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,34 @@
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
"""
override val changesetComment = "Specify leaf types"
override val wikiLink = "Key:leaf_type"
override val icon = R.drawable.ic_quest_leaf
override val achievements = listOf(OUTDOORS)

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">Do the tree here have needles or leaves?</string>

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

Expand Down

0 comments on commit b66f4e8

Please sign in to comment.