class PersistantQuestion{
private var isActive:Bool = false
private var mode:String = "yes" // key mode
private var dic:[String:DrawRnd]=[:]
private var outputDripper:OutPutDripper = OutPutDripper(limit: 1)
private var loggedAnswer:String = "" // only used in log() which replaces process()
// getters and setters
func getLoggedAnswer()->String{
return self.loggedAnswer
}
func setLoggedAnswer(loggedAnswer:String){
// underuse
self.loggedAnswer = loggedAnswer
}
func getMode()->String{
return mode
}
func setMode(newMode:String){
// dictionary contains key code:
if dic.keys.contains(newMode){
mode = newMode
}
}
func setPause(pause:Int){
// set pause between question to wait for answer
self.outputDripper.setLimit(limit: pause)
}
func activate(){
self.isActive = true
}
func deActivate(){
self.isActive = false
self.dic[mode]!.reset()
}
// end setters and getters
func addPath(answer:String, nags:DrawRnd){
self.dic[answer]=nags
}
func process(inp:String)->String{
// got answer?
if dic.keys.contains(inp){
mode = inp
isActive = false
dic[mode]!.reset()
return "okay"; // can extend code to reply key, rnd finalizer
}
// nag for answer
if !outputDripper.drip(){
return ""
}
let result:String = dic[mode]!.draw()
if !result.isEmpty {
return result
}
dic[mode]!.reset()
isActive = false
return "i see"
}
func log(inp:String)->String{
// got answer?
if dic.keys.contains(inp){
mode = inp
loggedAnswer = inp
isActive = false
dic[mode]!.reset()
return "okay"; // can extend code to reply key, rnd finalizer
}
if !inp.isEmpty{
loggedAnswer = inp
isActive = false
dic[mode]!.reset()
return "okay"; // can extend code to reply key, rnd finalizer
}
// nag for answer
if !outputDripper.drip(){
return ""
}
let result:String = dic[mode]!.draw()
if !result.isEmpty {
return result
}
dic[mode]!.reset()
isActive = false
return "i see"
}
}