Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. //
  2. // EntityOptionSet.swift
  3. // SoundSketch
  4. //
  5. // Created by alexanderbollbach on 3/25/17.
  6. // Copyright © 2017 alexanderbollbach. All rights reserved.
  7. //
  8.  
  9. import Foundation
  10.  
  11. protocol ModeSet {
  12.  
  13. var modes: [Mode] { get set }
  14. init(with options: [Mode])
  15. }
  16.  
  17. class LayerAnimationModes: ModeSet {
  18.  
  19. var modes: [Mode]
  20.  
  21. public required init(with modes: [Mode]) {
  22. self.modes = modes
  23. }
  24.  
  25. public func state(forMode mode: String) -> Bool {
  26.  
  27. if let mode = getMode(with: mode) {
  28. return mode.active
  29. }
  30. return false
  31. }
  32.  
  33. public func update(with newMode: Mode) {
  34.  
  35. if let oldMode = getMode(with: newMode.name) {
  36.  
  37. oldMode.active = !newMode.active
  38. }
  39. }
  40.  
  41. private func getMode(with name: String) -> Mode? {
  42.  
  43. for mode in modes {
  44. if mode.name == name {
  45. return mode
  46. }
  47. }
  48. return nil
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement