Skip to content

Commit 392e6cd

Browse files
committed
Added answering mechanism
Added answering mechanism
1 parent 773cd54 commit 392e6cd

File tree

6 files changed

+54
-9
lines changed

6 files changed

+54
-9
lines changed

GoInfoGame/GoInfoGame/AppQuestManager.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ class AppQuestManager {
8080
let position = dbInstance.getCenterForWay(id: String(way.id)) ?? CLLocationCoordinate2D()
8181
let unit = DisplayUnitWithCoordinate(displayUnit: quest.displayUnit, coordinateInfo: position, id: way.id)
8282
displayUnits.append(unit)
83-
83+
// if(quest is SideWalkWidth){
84+
// if let q = quest as? SideWalkWidth {
85+
// q.assignAnsweringHandler()
86+
// }
87+
// }
8488
wayQuests.append(quest)
8589
break
8690
}

GoInfoGame/GoInfoGame/UI/MapViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
import UIKit
99
import SwiftUI
1010

11-
class MapViewController: UIHostingController<QuestsListUIView> {
11+
class MapViewController: UIHostingController<MapView> {
1212

1313
override func viewDidLoad() {
1414
super.viewDidLoad()
1515

1616
// Do any additional setup after loading the view.
1717
}
1818
required init?(coder aDecoder: NSCoder) {
19-
super.init(coder: aDecoder, rootView: QuestsListUIView())
19+
super.init(coder: aDecoder, rootView: MapView())
2020
}
2121
}

GoInfoGame/GoInfoGame/quests/Handrail/HandRail.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import SwiftUI
99
import Foundation
1010
import osmparser
1111

12-
class HandRail: Quest {
12+
class HandRail: QuestBase,Quest {
1313

1414
func onAnswer(answer: Bool) {
1515

@@ -38,7 +38,11 @@ class HandRail: Quest {
3838

3939
var changesetComment: String = "Specify whether steps have handrails"
4040

41-
var form: AnyView = AnyView(HandRailForm())
41+
var form: AnyView {
42+
get{
43+
return AnyView(self.internalForm as! HandRailForm)
44+
}
45+
}
4246

4347
var relationData: Any? = nil
4448

@@ -57,4 +61,10 @@ class HandRail: Quest {
5761
return _internalExpression
5862
}
5963
}
64+
override init() {
65+
super.init()
66+
self.internalForm = HandRailForm(action: { [self] yesNo in
67+
onAnswer(answer: yesNo)
68+
})
69+
}
6070
}

GoInfoGame/GoInfoGame/quests/QuestProtocols.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@ protocol Quest {
1818
var icon: UIImage {get}
1919
var wikiLink: String {get}
2020
var changesetComment: String {get}
21-
var form : AnyView {get set}
21+
var form : AnyView {get}
2222
var relationData : Any? {get set}
2323
func onAnswer(answer:AnswerClass)
2424

2525
var displayUnit: DisplayUnit { get}
2626
var filterExpression : ElementFilterExpression? { get }
2727
}
28+
29+
class QuestBase {
30+
public var internalForm: (any QuestForm)? = nil
31+
32+
}
2833
// Adds default method and implementation
2934
extension Quest {
3035

GoInfoGame/GoInfoGame/quests/SidewalkWidth/SideWalkWidth.swift

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import SwiftUI
1111
import osmparser
1212

1313

14-
class SideWalkWidth : Quest {
14+
class SideWalkWidth : QuestBase, Quest {
1515

1616
var displayUnit: DisplayUnit {
1717
DisplayUnit(title: self.title, description: "",parent: self, sheetSize: .MEDIUM)
@@ -27,14 +27,36 @@ class SideWalkWidth : Quest {
2727
var wikiLink: String = ""
2828
var changesetComment: String = ""
2929

30-
var form: AnyView = AnyView(SideWalkWidthForm())
30+
var form: AnyView {
31+
get{
32+
return AnyView(self.internalForm as! SideWalkWidthForm)
33+
}
34+
}
3135

3236
var relationData: Any? = nil
37+
38+
3339
func onAnswer(answer: WidthAnswer) {
40+
// Do whatever you need here.
3441
}
3542
typealias AnswerClass = WidthAnswer
3643

3744
var _internalExpression: ElementFilterExpression?
45+
46+
override init() {
47+
super.init()
48+
self.internalForm = SideWalkWidthForm { [self] answer in
49+
print("Wow!!")
50+
self.onAnswer(answer: answer)
51+
52+
} onConfirm: { feet, inches, isConfirmAlert in
53+
print("Whatever") // Not needed but addeed for consistency
54+
}
55+
56+
57+
58+
}
59+
3860

3961
var filterExpression: ElementFilterExpression? {
4062
if(_internalExpression != nil){

GoInfoGame/GoInfoGame/quests/SidewalkWidth/SideWalkWidthForm.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ struct SideWalkWidthForm: View, QuestForm {
2525
var onConfirm: ((_ feet: Double, _ inches: Double, _ isConfirmAlert: Bool) -> Void)?
2626

2727
func processAnswer() {
28+
print("Process this answer")
2829
// Generate the answer
2930
let answer = WidthAnswer(width: "33", units: "aa", isARMeasurement: false)
3031
applyAnswer(answer:answer)
32+
action?(answer)
3133
}
3234
var body: some View {
3335
VStack{
@@ -57,7 +59,9 @@ struct SideWalkWidthForm: View, QuestForm {
5759
message: Text(LocalizedStrings.questRoadWidthUnusualInputConfirmation.localized),
5860
primaryButton: .default(Text(LocalizedStrings.questGenericConfirmationYes.localized)) {
5961
print("OK button tapped")
60-
onConfirm?(feet, inches, isConfirmAlert)
62+
processAnswer()
63+
onConfirm?(feet, inches, isConfirmAlert) // Remove this
64+
6165
},
6266
secondaryButton: .default(Text(LocalizedStrings.questGenericConfirmationNo.localized))
6367
)

0 commit comments

Comments
 (0)