Skip to content

Commit

Permalink
barrier also on roads, drop inheritance where not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
matkoniecz committed Nov 24, 2021
1 parent e76fbd0 commit c4b6161
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ import javax.inject.Singleton
AddBoardType(),

AddBarrierType(), // basically any more detailed rendering and routing: OSM Carto, mapy.cz, OSMand for start
AddWhatIsOnBarrierAndPathIntersection(),
AddBarrierOnPath(),
AddBarrierOnRoad(),
AddStileType(),
AddBicycleBarrierType(),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package de.westnordost.streetcomplete.quests.barrier_type

import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.data.elementfilter.toElementFilterExpression
import de.westnordost.streetcomplete.data.meta.ALL_PATHS
import de.westnordost.streetcomplete.data.osm.edits.update_tags.StringMapChangesBuilder
import de.westnordost.streetcomplete.data.osm.mapdata.Element
import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry
Expand All @@ -11,7 +12,7 @@ import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement
import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement.WHEELCHAIR
import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement.OUTDOORS

class AddWhatIsOnBarrierAndPathIntersection: OsmElementQuestType<BarrierType> {
class AddBarrierOnPath: OsmElementQuestType<BarrierType> {

private val barrierFilter by lazy {
"""
Expand All @@ -24,8 +25,7 @@ class AddWhatIsOnBarrierAndPathIntersection: OsmElementQuestType<BarrierType> {
private val pathsFilter by lazy {
"""
ways with
(highway ~ path|footway|steps|cycleway)
and area != yes
(ways with highway ~ ${ALL_PATHS.joinToString("|")} and area != yes)
and (access !~ private|no or (foot and foot !~ private|no))
""".toElementFilterExpression()
}
Expand All @@ -34,7 +34,7 @@ class AddWhatIsOnBarrierAndPathIntersection: OsmElementQuestType<BarrierType> {

override val wikiLink = "Key:barrier"

override val icon = R.drawable.ic_quest_barrier
override val icon = R.drawable.ic_quest_barrier // TODO?

override val questTypeAchievements = listOf(PEDESTRIAN, WHEELCHAIR, OUTDOORS)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package de.westnordost.streetcomplete.quests.barrier_type

import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.data.elementfilter.toElementFilterExpression
import de.westnordost.streetcomplete.data.meta.ALL_ROADS
import de.westnordost.streetcomplete.data.osm.edits.update_tags.StringMapChangesBuilder
import de.westnordost.streetcomplete.data.osm.mapdata.Element
import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry
import de.westnordost.streetcomplete.data.osm.mapdata.Node
import de.westnordost.streetcomplete.data.osm.osmquests.OsmElementQuestType
import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement.CAR

class AddBarrierOnRoad: OsmElementQuestType<BarrierType> {

private val barrierFilter by lazy {
"""
ways with
barrier ~ wall|fence|hedge|guard_rail|retaining_wall|city_wall
and area != yes
""".toElementFilterExpression()
}

private val pathsFilter by lazy {
"""
ways with
(ways with highway ~ ${ALL_ROADS.joinToString("|")} and area != yes)
and (access !~ private|no or (foot and foot !~ private|no))
""".toElementFilterExpression()
}

override val commitMessage = "Add what is on intersection of road and barrier"

override val wikiLink = "Key:barrier"

override val icon = R.drawable.ic_quest_barrier // TODO TODO TODO TODO

override val questTypeAchievements = listOf(CAR)

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

override fun getApplicableElements(mapData: MapDataWithGeometry): Iterable<Element> {
return detectWayBarrierIntersection(mapData, barrierFilter, pathsFilter)
}

override fun isApplicableTo(element: Element): Boolean? =
if (element !is Node || element.tags.isNotEmpty()) false else null

override fun createForm() = AddBarrierTypeForm()

override fun applyAnswerTo(answer: BarrierType, changes: StringMapChangesBuilder) {
changes.add("barrier", answer.osmValue)
when (answer) {
BarrierType.STILE_SQUEEZER -> {
changes.addOrModify("stile", "squeezer")
}
BarrierType.STILE_LADDER -> {
changes.addOrModify("stile", "ladder")
}
BarrierType.STILE_STEPOVER_WOODEN -> {
changes.addOrModify("stile", "stepover")
changes.addOrModify("material", "wood")
}
BarrierType.STILE_STEPOVER_STONE -> {
changes.addOrModify("stile", "stepover")
changes.addOrModify("material", "stone")
}
}
}
}
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1105,5 +1105,6 @@ If you are overwhelmed by the number of quests, you can always fine-tune which q
<string name="short_no_answer_on_button">No</string>
<string name="quest_level_title">On which level is %s located?</string>
<string name="pref_title_language_select">Select language</string>
<string name="quest_barrier_path_intersection">What is where path goes through a barrier?</string>
<string name="quest_barrier_path_intersection">How does this path go through this barrier?</string>
<string name="quest_barrier_road_intersection">How does this road go through this barrier?</string>
</resources>

0 comments on commit c4b6161

Please sign in to comment.