<commit_before>//
//  AnimationChain.swift
//  Slaminate
//
//  Created by <NAME> on 11/02/16.
//  Copyright © 2016 Trenskow.io. All rights reserved.
//

import Foundation

public class AnimationChain: Animation {
    
    var animations: [Animation]
    private var commited: Bool = false
    
    init(animations: [Animation]) {
        self.animations = animations
        super.init()
        self.animations.forEach { (animation) -> () in
            animation.owner = self
        }
    }
        
    @objc override public var duration: NSTimeInterval {
        get {
            return self.animations.reduce(0.0, combine: { (c, animation) -> NSTimeInterval in
                return c + animation.delay + animation.duration
            })
        }
        set {
            let duration = self.duration
            let delta = newValue - duration
            animations.forEach { (animation) -> () in
                let animationPart = (animation.delay + animation.duration) / duration
                animation.delay += (delta * animationPart) * (animation.delay / (animation.delay + animation.duration))
                animation.duration += (delta * animationPart) * (animation.duration / (animation.delay + animation.duration))
            }
        }
    }
        
    override func setPosition(position: NSTimeInterval, apply: Bool) {
        defer { super.setPosition(position, apply: apply) }
        guard apply else { return }
        _ = animations.reduce(delay) { (total, animation) -> NSTimeInterval in
            let full = animation.delay + animation.duration
            animation.setPosition(max(0.0, min(full, position - total)), apply: apply)
            return total + full
        }
    }
    
    override func commit() {
        commited = true
        animateNext()
    }
    
    override public func then(animations animations: [Animation]) -> Animation {
        animations.forEach { animation in
            animation.owner = self
            self.animations.append(animation)
        }
        return self
    }<commit_msg>AnimationChain is now internal.<commit_after>//
//  AnimationChain.swift
//  Slaminate
//
//  Created by <NAME> on 11/02/16.
//  Copyright © 2016 Trenskow.io. All rights reserved.
//

import Foundation

class AnimationChain: Animation {
    
    var animations: [Animation]
    private var commited: Bool = false
    
    init(animations: [Animation]) {
        self.animations = animations
        super.init()
        self.animations.forEach { (animation) -> () in
            animation.owner = self
        }
    }
        
    @objc override var duration: NSTimeInterval {
        get {
            return self.animations.reduce(0.0, combine: { (c, animation) -> NSTimeInterval in
                return c + animation.delay + animation.duration
            })
        }
        set {
            let duration = self.duration
            let delta = newValue - duration
            animations.forEach { (animation) -> () in
                let animationPart = (animation.delay + animation.duration) / duration
                animation.delay += (delta * animationPart) * (animation.delay / (animation.delay + animation.duration))
                animation.duration += (delta * animationPart) * (animation.duration / (animation.delay + animation.duration))
            }
        }
    }
        
    override func setPosition(position: NSTimeInterval, apply: Bool) {
        defer { super.setPosition(position, apply: apply) }
        guard apply else { return }
        _ = animations.reduce(delay) { (total, animation) -> NSTimeInterval in
            let full = animation.delay + animation.duration
            animation.setPosition(max(0.0, min(full, position - total)), apply: apply)
            return total + full
        }
    }
    
    override func commit() {
        commited = true
        animateNext()
    }
    
    override func then(animations animations: [Animation]) -> Animation {
        animations.forEach { animation in
            animation.owner = self
            self.animations.append(animation)
        }
        return self
    }
{'fraction_non_alphanumeric': 0.10007269202810759, 'fraction_numerical': 0.006784589290041192, 'mean_word_length': 1.9152542372881356, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1758220', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1044, 'n_words': 276}