Created
October 21, 2016 13:36
-
-
Save mzaks/a92b1c2d922a311b528d1c03a9cdc032 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct IsItPlugedIn : Action { | |
| var counter = Counter() | |
| func execute(data: String, callback: @escaping (DataType, BehaviourResult) -> ()) { | |
| let realy = [String](repeating: " realy", count: counter.count).joined(separator: ",") | |
| print("Is it\(realy) plugged in?") | |
| counter.increase() | |
| callback(data, .succeeded) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct RepeatOnSuccess : Decorator { | |
| let node : BehaviourNode | |
| let counter = Counter() | |
| func execute(data: DataType, callback: @escaping (DataType, BehaviourResult) -> ()) { | |
| func repeatExecution(data : DataType, result : BehaviourResult) -> (){ | |
| if result == .succeeded { | |
| if counter.count < 3 { | |
| counter.increase() | |
| } else { | |
| print("Sorry can't help you mate.") | |
| callback(data, .panicked(reason: "This is pointless")) | |
| return | |
| } | |
| node.execute(data: data, callback: repeatExecution) | |
| } else { | |
| callback(data, result) | |
| } | |
| } | |
| node.execute(data: data, callback: repeatExecution) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment