Skip to content

Commit 909f42f

Browse files
authored
Merge pull request #57 from TaskarCenterAtUW/Feature-apply-tag
Added tag with answer for Quests
2 parents 31f206c + f6bb46a commit 909f42f

23 files changed

+173
-209
lines changed

GoInfoGame/GoInfoGame/UI/CustomComponents/YesNoView.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@
66
//
77

88
import SwiftUI
9-
enum YesNoAnswer {
9+
10+
enum YesNoAnswer: String {
1011
case yes
1112
case no
1213
case other
1314
case unknown
1415
}
1516

16-
1717
struct YesNoView: View {
1818

1919
var action: ((_ answer:YesNoAnswer) -> Void)?
2020

2121
init(action: ((_ answer: YesNoAnswer) -> Void)? = nil) {
2222
self.action = action
2323
}
24+
2425
var body: some View {
2526
HStack(spacing: 0) {
2627
Spacer()
@@ -41,14 +42,12 @@ struct YesNoView: View {
4142
.frame(minWidth: 20, maxWidth: 80, minHeight: 50)
4243
Divider().background(Color.gray).frame(height: 30)
4344
Button {
44-
4545
action?(.no)
4646
} label: {
4747
Text(LocalizedStrings.questGenericHasFeatureNo.localized)
4848
.foregroundColor(.orange).font(.body)
4949
.frame(maxWidth: .infinity)
5050
}
51-
5251
}
5352
}
5453
}

GoInfoGame/GoInfoGame/quests/BusStopLit/BusStopLit.swift

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import SwiftUI
1111
import osmparser
1212

1313
class BusStopLit: QuestBase, Quest {
14+
typealias AnswerClass = YesNoAnswer
15+
var relationData: Element? = nil
16+
var _internalExpression: ElementFilterExpression?
17+
var icon: UIImage = #imageLiteral(resourceName: "stop_lit")
18+
var wikiLink: String = ""
19+
var changesetComment: String = ""
1420
var title: String = "Bus Stop Lit"
1521
var filter: String = """
1622
nodes, ways, relations with
@@ -28,24 +34,14 @@ class BusStopLit: QuestBase, Quest {
2834
or lit older today -16 years
2935
)
3036
"""
31-
var icon: UIImage = #imageLiteral(resourceName: "stop_lit")
32-
var wikiLink: String = ""
33-
var changesetComment: String = ""
34-
35-
var relationData: Element? = nil
3637
var displayUnit: DisplayUnit {
3738
DisplayUnit(title: self.title, description: "",parent: self,sheetSize:.SMALL )
3839
}
39-
typealias AnswerClass = YesNoAnswer
40-
41-
var _internalExpression: ElementFilterExpression?
42-
4340
var filterExpression: ElementFilterExpression? {
4441
if(_internalExpression != nil){
4542
return _internalExpression
4643
}
4744
else {
48-
print("<>")
4945
_internalExpression = try? filter.toElementFilterExpression()
5046
return _internalExpression
5147
}
@@ -64,7 +60,9 @@ class BusStopLit: QuestBase, Quest {
6460
}
6561

6662
func onAnswer(answer: YesNoAnswer) {
67-
63+
if let rData = self.relationData {
64+
self.updateTags(id: rData.id, tags: ["lit":answer.rawValue], type: rData.type)
65+
}
6866
}
6967

7068
func copyWithElement(element: Element) -> any Quest {

GoInfoGame/GoInfoGame/quests/BusStopLit/BusStopLitForm.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ struct BusStopLitForm: View, QuestForm {
1414
typealias AnswerClass = YesNoAnswer
1515
var body: some View {
1616
VStack{
17-
QuestionHeader(icon: Image("stop_lit"), title: LocalizedStrings.questBusStopLitTitle.localized, subtitle: "SideWalk")
17+
QuestionHeader(icon: Image("stop_lit"),
18+
title: LocalizedStrings.questBusStopLitTitle.localized,
19+
subtitle: "SideWalk")
1820
YesNoView(action: action).padding(10)
1921
.background(
2022
RoundedRectangle(cornerRadius: 10)

GoInfoGame/GoInfoGame/quests/CrossingMarking/CrossMarking.swift

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import SwiftUI
1111
import osmparser
1212

1313
class CrossMarking: QuestBase, Quest {
14+
typealias AnswerClass = CrossingAnswer
15+
var _internalExpression: ElementFilterExpression?
1416
var title: String = "Cross Marking"
1517
var filter: String = ""
1618
var icon: UIImage = #imageLiteral(resourceName: "pedestrian")
@@ -20,16 +22,11 @@ class CrossMarking: QuestBase, Quest {
2022
var displayUnit: DisplayUnit {
2123
DisplayUnit(title: self.title, description: "",parent: self,sheetSize:.MEDIUM )
2224
}
23-
typealias AnswerClass = CrossingAnswer
24-
25-
var _internalExpression: ElementFilterExpression?
26-
2725
var filterExpression: ElementFilterExpression? {
2826
if(_internalExpression != nil){
2927
return _internalExpression
3028
}
3129
else {
32-
print("<>")
3330
_internalExpression = try? filter.toElementFilterExpression()
3431
return _internalExpression
3532
}
@@ -48,7 +45,9 @@ class CrossMarking: QuestBase, Quest {
4845
}
4946

5047
func onAnswer(answer: CrossingAnswer) {
51-
48+
if let rData = self.relationData {
49+
self.updateTags(id: rData.id, tags: ["crossing":answer.rawValue], type: rData.type)
50+
}
5251
}
5352

5453
func copyWithElement(element: Element) -> any Quest {
@@ -58,18 +57,10 @@ class CrossMarking: QuestBase, Quest {
5857
}
5958
}
6059

61-
enum CrossingAnswer: String, CaseIterable {
62-
case yes
63-
case no
64-
case prohibited
65-
66-
var description: String {
67-
switch self {
68-
case .yes: return "Yes"
69-
case .no: return "No"
70-
case .prohibited: return "Prohibited"
71-
}
72-
}
60+
enum CrossingAnswer: String {
61+
case yes = "Yes"
62+
case no = "No"
63+
case prohibited = "Prohibited"
7364
}
7465

7566
struct TextItem<T> {

GoInfoGame/GoInfoGame/quests/CrossingMarking/CrossMarkingForm.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ import SwiftUI
1010

1111
struct CrossMarkingForm : View,QuestForm{
1212
var action: ((CrossingAnswer) -> Void)?
13-
13+
typealias AnswerClass = CrossingAnswer
1414
@State private var selectedAnswer: CrossingAnswer?
1515
@State private var showAlert = false
16-
17-
typealias AnswerClass = CrossingAnswer
1816
let items = [
1917
TextItem(value: CrossingAnswer.yes, titleId: LocalizedStrings.questCrossingYes.localized),
2018
TextItem(value: CrossingAnswer.no, titleId: LocalizedStrings.questCrossingNo.localized),
@@ -23,7 +21,9 @@ struct CrossMarkingForm : View,QuestForm{
2321

2422
var body: some View {
2523
VStack{
26-
QuestionHeader(icon: Image("pedestrian"), title: LocalizedStrings.questCrossingTitle.localized, subtitle: "")
24+
QuestionHeader(icon: Image("pedestrian"),
25+
title: LocalizedStrings.questCrossingTitle.localized,
26+
subtitle: "")
2727
VStack{
2828
VStack (alignment: .leading){
2929
ForEach(items, id: \.titleId) { item in

GoInfoGame/GoInfoGame/quests/Handrail/HandRail.swift

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ import osmparser
1111

1212
class HandRail: QuestBase,Quest {
1313
typealias AnswerClass = YesNoAnswer
14-
14+
var _internalExpression: ElementFilterExpression?
15+
var relationData: Element? = nil
16+
var icon: UIImage = #imageLiteral(resourceName: "steps_handrail.pdf")
17+
var wikiLink: String = "Key:handrail"
18+
var changesetComment: String = "Specify whether steps have handrails"
1519
var title: String = "HandRail"
16-
1720
var filter: String = """
1821
ways with highway = steps
1922
and (!indoor or indoor = no)
@@ -26,36 +29,23 @@ class HandRail: QuestBase,Quest {
2629
or older today -8 years
2730
)
2831
"""
29-
30-
var icon: UIImage = #imageLiteral(resourceName: "steps_handrail.pdf")
31-
32-
var wikiLink: String = "Key:handrail"
33-
34-
var changesetComment: String = "Specify whether steps have handrails"
35-
3632
var form: AnyView {
3733
get{
3834
return AnyView(self.internalForm as! HandRailForm)
3935
}
4036
}
41-
42-
var relationData: Element? = nil
43-
4437
var displayUnit: DisplayUnit {
4538
DisplayUnit(title: self.title, description: "",parent: self,sheetSize: .SMALL)
4639
}
47-
48-
var _internalExpression: ElementFilterExpression?
49-
5040
var filterExpression: ElementFilterExpression? {
5141
if(_internalExpression != nil){
5242
return _internalExpression
53-
}
54-
else {
43+
} else {
5544
_internalExpression = try? filter.toElementFilterExpression()
5645
return _internalExpression
5746
}
5847
}
48+
5949
override init() {
6050
super.init()
6151
self.internalForm = HandRailForm(action: { [self] yesNo in
@@ -64,7 +54,9 @@ class HandRail: QuestBase,Quest {
6454
}
6555

6656
func onAnswer(answer: YesNoAnswer) {
67-
57+
if let rData = self.relationData {
58+
self.updateTags(id: rData.id, tags: ["handrail":answer.rawValue], type: rData.type)
59+
}
6860
}
6961

7062
func copyWithElement(element: Element) -> any Quest {

GoInfoGame/GoInfoGame/quests/Handrail/HandRailForm.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ struct HandRailForm: View, QuestForm {
1313

1414
var body: some View {
1515
VStack{
16-
QuestionHeader(icon: Image("steps_handrail"), title: "Do these steps have handrail?", subtitle: "")
16+
QuestionHeader(icon: Image("steps_handrail"),
17+
title: "Do these steps have handrail?",
18+
subtitle: "")
1719
YesNoView(action: action)
18-
.background(
19-
RoundedRectangle(cornerRadius: 10)
20-
.fill(Color.white)
21-
.shadow(color: .gray, radius: 2, x: 0, y: 2))
20+
.background(RoundedRectangle(cornerRadius: 10)
21+
.fill(Color.white)
22+
.shadow(color: .gray, radius: 2, x: 0, y: 2))
2223
}.padding()
2324
}
2425
}

GoInfoGame/GoInfoGame/quests/QuestsRepository.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ class QuestsRepository {
4848

4949
return CLLocationCoordinate2D(latitude: randomLat, longitude: randomLon)
5050
}
51-
52-
53-
5451
}
5552
// Probably move somewhere else
5653
struct DisplayUnitWithCoordinate: Identifiable {

GoInfoGame/GoInfoGame/quests/SideWalkValidation/SideWalkValidation.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ class SideWalkValidation: QuestBase, Quest {
3434
}
3535

3636
func onAnswer(answer: SideWalkValidationAnswer) {
37-
37+
if let rData = self.relationData {
38+
self.updateTags(id: rData.id, tags: ["sidewalk":answer.description], type: rData.type)
39+
}
3840
}
3941

4042
func copyWithElement(element: Element) -> any Quest {

GoInfoGame/GoInfoGame/quests/SideWalkValidation/SideWalkValidationForm.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ struct SideWalkValidationForm: QuestForm ,View {
2929
var body: some View {
3030
ZStack{
3131
VStack (alignment: .leading){
32-
QuestionHeader(icon: Image("sidewalk"), title: LocalizedStrings.questSidewalkTitle.localized, subtitle: "Street").padding(.bottom,10)
32+
QuestionHeader(icon: Image("sidewalk"),
33+
title: LocalizedStrings.questSidewalkTitle.localized,
34+
subtitle: "Street")
35+
.padding(.bottom,10)
3336
VStack(alignment: .leading){
3437
Text(LocalizedStrings.select.localized).font(.caption).foregroundColor(.gray)
3538
ImageGridItemView(gridCount: 2, isLabelBelow: true, imageData: SideWalksImageData, isImageRotated: false, isDisplayImageOnly: false, onTap: { (type, tag) in
@@ -84,8 +87,6 @@ struct SideWalkValidationForm: QuestForm ,View {
8487
}
8588
}
8689

87-
88-
8990
#Preview {
9091
SideWalkValidationForm()
9192
}

0 commit comments

Comments
 (0)