Skip to content

Commit

Permalink
1.3.0 update
Browse files Browse the repository at this point in the history
- Refactored the "finalState" convenience initializer for the Motion class to now take an Array of PropertyStates objects. This allows you to provide both starting and ending representational value objects for easy animation properties creation. Most of the ValueAssistant objects had significant updates to support this.
- A new "buildPropertyData(fromObject: AnyObject, propertyStates: [PropertyStates])" public method has been added to the Motion class, which creates and returns an array of PropertyData objects. This method is used in conjunction with the above convenience initializer, but can be called ad hoc to generate PropertyData objects from a set of state objects you pass in.
- Bugfix: ValueAssistants now won't exclude properties from being created when the ending value is the same as the object's original value, but the specified starting value is different.
- Minor updates for Swift 4 compatibility. The Examples and Tests projects now target Swift 4.
- Updated tests, and additional test coverage for ValueAssistant classes.
  • Loading branch information
poetmountain committed Mar 19, 2018
1 parent 49745e4 commit 7e3417d
Show file tree
Hide file tree
Showing 48 changed files with 1,361 additions and 586 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#### 1.3.0
- Refactored the "finalState" convenience initializer for the Motion class to now take an Array of PropertyStates objects. This allows you to provide both starting and ending representational value objects for easy animation properties creation. Most of the ValueAssistant objects had significant updates to support this.
- A new "buildPropertyData(fromObject: AnyObject, propertyStates: [PropertyStates])" public method has been added to the Motion class, which creates and returns an array of PropertyData objects. This method is used in conjunction with the above convenience initializer, but can be called ad hoc to generate PropertyData objects from a set of state objects you pass in.
- Bugfix: ValueAssistants now won't exclude properties from being created when the ending value is the same as the object's original value, but the specified starting value is different.
- Minor updates for Swift 4 compatibility. The Examples and Tests projects now target Swift 4.
- Updated tests, and additional test coverage for ValueAssistant classes.

#### 1.2.0
Support for Swift 4.0.

Expand Down
2 changes: 1 addition & 1 deletion Classes/CATempo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MotionMachine
//
// Created by Brett Walker on 4/19/16.
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Classes/EasingTypes/EasingBack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MotionMachine
//
// Created by Brett Walker on 5/3/16.
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Classes/EasingTypes/EasingBounce.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MotionMachine
//
// Created by Brett Walker on 5/3/16.
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Classes/EasingTypes/EasingCircular.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MotionMachine
//
// Created by Brett Walker on 5/3/16.
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Classes/EasingTypes/EasingCubic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MotionMachine
//
// Created by Brett Walker on 5/3/16.
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Classes/EasingTypes/EasingElastic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MotionMachine
//
// Created by Brett Walker on 5/3/16.
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Classes/EasingTypes/EasingExpo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MotionMachine
//
// Created by Brett Walker on 5/3/16.
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Classes/EasingTypes/EasingLinear.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MotionMachine
//
// Created by Brett Walker on 4/19/16.
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Classes/EasingTypes/EasingQuadratic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MotionMachine
//
// Created by Brett Walker on 4/30/16.
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Classes/EasingTypes/EasingQuartic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MotionMachine
//
// Created by Brett Walker on 5/3/16.
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Classes/EasingTypes/EasingQuintic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MotionMachine
//
// Created by Brett Walker on 5/3/16.
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Classes/EasingTypes/EasingSine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MotionMachine
//
// Created by Brett Walker on 5/3/16.
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
116 changes: 70 additions & 46 deletions Classes/Motion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MotionMachine
//
// Created by Brett Walker on 4/19/16.
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -524,7 +524,7 @@ public class Motion: Moveable, Additive, TempoDriven, PropertyDataDelegate {
*/
public convenience init(target targetObject: NSObject, properties: [PropertyData], duration: TimeInterval, easing: EasingUpdateClosure?=EasingLinear.easeNone(), options: MotionOptions?=MotionOptions.None) {

self.init(target: targetObject, properties: properties, finalStates: nil, duration: duration, easing: easing, options: options)
self.init(target: targetObject, properties: properties, statesForProperties: nil, duration: duration, easing: easing, options: options)

}

Expand All @@ -539,26 +539,26 @@ public class Motion: Moveable, Additive, TempoDriven, PropertyDataDelegate {
*/
public convenience init(target targetObject: NSObject, duration: TimeInterval, easing: EasingUpdateClosure?=EasingLinear.easeNone(), options: MotionOptions?=MotionOptions.None) {

self.init(target: targetObject, properties: [], finalStates: nil, duration: duration, easing: easing, options: options)
self.init(target: targetObject, properties: [], statesForProperties: nil, duration: duration, easing: easing, options: options)
}

/**
* Initializer.
* Initializer. Using this convenience method, you can pass in objects of the value type you're modifying without having to manually create `PropertyData` objects for each object property you wish to modify. For instance, if you're modifying a CGRect object, you can provide CGRect objects that represent its starting and ending states and it will handle the setup for all the properties of the CGRect that have changed between the two states.
*
* - parameters:
* - target: The target object whose properties should be modified.
* - finalState: A Dictionary of template objects, with keys representing property keypaths (relative to the target object), and values that represent their final states. These final states must be of the same object type as the property located at the keypath.
* - statesForProperties: An Array of `PropertyStates` objects which represent property keypaths (relative to the target object), and values that represent their starting and ending states. By using `PropertyStates` objects, you can pass in objects of the value type you're modifying without having to manually create `PropertyData` objects for each object property you wish to modify. Please see the `PropertyStates` documentation for usage information.
* - duration: The length of the motion, in seconds.
* - easing: An optional `EasingUpdateClosure` easing equation to use when moving the values of the given properties. `EasingLinear.easeNone()` is the default equation if none is provided.
* - options: An optional set of `MotionsOptions`.
*/
public convenience init(target targetObject: NSObject, finalState templateObjects: [String:Any], duration: TimeInterval, easing: EasingUpdateClosure?=EasingLinear.easeNone(), options: MotionOptions?=MotionOptions.None) {
public convenience init(target targetObject: NSObject, statesForProperties templateObjects: [PropertyStates], duration: TimeInterval, easing: EasingUpdateClosure?=EasingLinear.easeNone(), options: MotionOptions?=MotionOptions.None) {

self.init(target: targetObject, properties: nil, finalStates: templateObjects, duration: duration, easing: easing, options: options)
self.init(target: targetObject, properties: nil, statesForProperties: templateObjects, duration: duration, easing: easing, options: options)
}


private init(target targetObject: NSObject, properties props: [PropertyData]?, finalStates: [String:Any]?, duration: TimeInterval, easing: EasingUpdateClosure?, options: MotionOptions?) {
private init(target targetObject: NSObject, properties props: [PropertyData]?, statesForProperties: [PropertyStates]?, duration: TimeInterval, easing: EasingUpdateClosure?, options: MotionOptions?) {

var properties = props ?? []

Expand Down Expand Up @@ -587,43 +587,8 @@ public class Motion: Moveable, Additive, TempoDriven, PropertyDataDelegate {

_tempo?.delegate = self

if let final_object_states = finalStates {
for (path, final_state) in final_object_states {
var tobj: AnyObject = targetObject
if (path != "" && valueAssistant.acceptsKeypath(targetObject)) {
if let tvalue = targetObject.value(forKeyPath: path) as AnyObject? {
tobj = tvalue
}
}

if let val = CGStructAssistant.valueForCGStruct(final_state) {
do {
let generated = try valueAssistant.generateProperties(fromObject: val, keyPath: path, targetObject: tobj)
properties.append(contentsOf: generated)

} catch ValueAssistantError.typeRequirement(let valueType) {
ValueAssistantError.typeRequirement(valueType).printError(fromFunction: #function)

} catch {
// any other errors
}

} else {
do {
let generated = try valueAssistant.generateProperties(fromObject: (final_state as AnyObject), keyPath: path, targetObject: tobj)
properties.append(contentsOf: generated)

} catch ValueAssistantError.typeRequirement(let valueType) {
ValueAssistantError.typeRequirement(valueType).printError(fromFunction: #function)

} catch {
// any other errors
}

}

}

if let unwrapped_states = statesForProperties {
properties = buildPropertyData(forObject: targetObject, propertyStates: unwrapped_states)
}

for property in properties {
Expand Down Expand Up @@ -710,7 +675,7 @@ public class Motion: Moveable, Additive, TempoDriven, PropertyDataDelegate {
*
* - remark: When this method is used there is no need to specify `.Reverse` in the `options` parameter of the init method.
*
* - parameter easing: The easing equation to be used while reversing. When no equation is provided, the normal `easing` closure will be used in both movement directions.
* - parameter withEasing: The easing equation to be used while reversing. When no equation is provided, the normal `easing` closure will be used in both movement directions.
* - returns: A reference to this Motion instance, for the purpose of chaining multiple calls to this method.
* - seealso: reversing, reverseEasing
*/
Expand All @@ -723,6 +688,64 @@ public class Motion: Moveable, Additive, TempoDriven, PropertyDataDelegate {
}


/**
* Builds `PropertyData` objects for the supplied PropertyStates objects.
*
* - parameter forObject: The object to be modified, and the base object for the paths of the `PropertyStates` objects.
* - parameter propertyStates: An Array of `PropertyStates` objects that define how the `PropertyData` objects are constructed.
* - remark: This method is used internally by the initializer when the `statesForProperties` convenience method is used, but you can also call it directly to build an array of `PropertyData` objects.
* - returns: An Array of `PropertyData` objects.
*/
public func buildPropertyData(forObject targetObject: AnyObject, propertyStates: [PropertyStates]) -> [PropertyData] {
var data: [PropertyData] = []

for var property_states in propertyStates {
var tobj: AnyObject = targetObject
if (property_states.path != "" && valueAssistant.acceptsKeypath(targetObject)) {
if let tvalue = targetObject.value(forKeyPath: property_states.path) as AnyObject? {
tobj = tvalue
}
}

if let end_val = CGStructAssistant.valueForCGStruct(property_states.end) {
do {
// the `generateProperties` method expects AnyObject for the states, so convert them to NSValue if we have a CGStruct
property_states.end = end_val
if let unwrapped_start = property_states.start, let start_val = CGStructAssistant.valueForCGStruct(unwrapped_start) {
property_states.start = start_val
}

let generated = try valueAssistant.generateProperties(targetObject: tobj, propertyStates: property_states)
data.append(contentsOf: generated)

} catch ValueAssistantError.typeRequirement(let valueType) {
ValueAssistantError.typeRequirement(valueType).printError(fromFunction: #function)

} catch {
// any other errors
}

} else {
do {
let generated = try valueAssistant.generateProperties(targetObject: tobj, propertyStates: property_states)
data.append(contentsOf: generated)

} catch ValueAssistantError.typeRequirement(let valueType) {
ValueAssistantError.typeRequirement(valueType).printError(fromFunction: #function)

} catch {
// any other errors
}

}

}

return data
}



// MARK: - Private methods

/**
Expand Down Expand Up @@ -935,6 +958,7 @@ public class Motion: Moveable, Additive, TempoDriven, PropertyDataDelegate {
private func updatePropertyValue(forProperty property: inout PropertyData) {

let new_value = (additive) ? property.delta : property.current

if (property.targetObject == nil) {

if let new_prop = valueAssistant.calculateValue(forProperty: property, newValue: new_value) {
Expand Down
2 changes: 1 addition & 1 deletion Classes/MotionGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MotionMachine
//
// Created by Brett Walker on 5/6/16.
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 4 additions & 2 deletions Classes/MotionMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MotionMachine
//
// Created by Brett Walker on 4/19/16.
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -237,6 +237,8 @@ public protocol MotionUpdateDelegate: class {
/// This protocol defines methods and properties that must be adopted for any value assistant.
public protocol ValueAssistant {

init()

/**
* This method returns an array of PropertyData instances based on the values of the provided object.
*
Expand All @@ -247,7 +249,7 @@ public protocol ValueAssistant {
*
* - returns: An array of PropertyData instances representing the values of the provided object.
*/
func generateProperties(fromObject object: AnyObject, keyPath path: String, targetObject target: AnyObject) throws -> [PropertyData]
func generateProperties(targetObject target: AnyObject, propertyStates: PropertyStates) throws -> [PropertyData]

/**
* This method replaces an element of an AnyObject subclass by assigning new values.
Expand Down
2 changes: 1 addition & 1 deletion Classes/MotionSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MotionMachine
//
// Created by Brett Walker on 5/11/16.
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Classes/MotionSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MotionMachine
//
// Created by Brett Walker on 4/20/16.
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Classes/PhysicsMotion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MotionMachine
//
// Created by Brett Walker on 5/16/16.
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Classes/PhysicsSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MotionMachine
//
// Created by Brett Walker on 5/16/16.
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
Loading

0 comments on commit 7e3417d

Please sign in to comment.