diff --git a/Examples/Effects/Demo.xcodeproj/project.pbxproj b/Examples/Effects/Demo.xcodeproj/project.pbxproj index 0310805..65c2712 100755 --- a/Examples/Effects/Demo.xcodeproj/project.pbxproj +++ b/Examples/Effects/Demo.xcodeproj/project.pbxproj @@ -191,13 +191,13 @@ attributes = { LastSwiftMigration = 0700; LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0810; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "Razeware LLC"; TargetAttributes = { 7BAE784D182FBA95009B4DA0 = { DevelopmentTeam = KFCNEC27GU; DevelopmentTeamName = "Razeware LLC"; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; }; }; }; @@ -206,6 +206,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -288,14 +289,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -332,14 +339,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -377,7 +390,7 @@ RUN_CLANG_STATIC_ANALYZER = YES; SPRITEKIT_TEXTURE_ATLAS_OUTPUT = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; WARNING_CFLAGS = ( "-Wall", "-Wextra", @@ -403,7 +416,7 @@ RUN_CLANG_STATIC_ANALYZER = YES; SPRITEKIT_TEXTURE_ATLAS_OUTPUT = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; WARNING_CFLAGS = ( "-Wall", "-Wextra", diff --git a/Examples/Effects/Demo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Examples/Effects/Demo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Examples/Effects/Demo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Examples/Effects/Demo/Base.lproj/Main.storyboard b/Examples/Effects/Demo/Base.lproj/Main.storyboard index 9826eaf..9c5a79c 100644 --- a/Examples/Effects/Demo/Base.lproj/Main.storyboard +++ b/Examples/Effects/Demo/Base.lproj/Main.storyboard @@ -1,8 +1,11 @@ - - + + + + + - + @@ -15,7 +18,7 @@ - + @@ -27,9 +30,4 @@ - - - - - diff --git a/Examples/Effects/Demo/Images.xcassets/AppIcon.appiconset/Contents.json b/Examples/Effects/Demo/Images.xcassets/AppIcon.appiconset/Contents.json index 48af8c6..249801e 100644 --- a/Examples/Effects/Demo/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/Examples/Effects/Demo/Images.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "size" : "29x29", "idiom" : "iphone", @@ -32,6 +42,11 @@ "idiom" : "iphone", "size" : "60x60", "scale" : "3x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" } ], "info" : { diff --git a/Examples/Effects/Demo/MyScene.swift b/Examples/Effects/Demo/MyScene.swift index f5b8894..1a28816 100644 --- a/Examples/Effects/Demo/MyScene.swift +++ b/Examples/Effects/Demo/MyScene.swift @@ -164,7 +164,7 @@ class MyScene: SKScene, SKPhysicsContactDelegate { func addEffectToBorder(border: SKNode, startPosition: CGPoint, endPosition: CGPoint, delay: TimeInterval) { let moveEffect = SKTMoveEffect(node: border, duration: 0.5, startPosition: startPosition, endPosition: endPosition) moveEffect.timingFunction = SKTTimingFunctionBounceEaseOut - border.run(SKAction.afterDelay(delay, performAction: SKAction.actionWithEffect(moveEffect))) + border.run(SKAction.after(delay: delay, performAction: SKAction.actionWithEffect(moveEffect))) } /** @@ -229,7 +229,7 @@ class MyScene: SKScene, SKPhysicsContactDelegate { // Also rotate and fade in the barrier. It's OK to apply these to the // pivotNode directly. - let rotateEffect = SKTRotateEffect(node: pivotNode, duration: 1, startAngle: CGFloat.random() * π/4, endAngle:pivotNode.zRotation) + let rotateEffect = SKTRotateEffect(node: pivotNode, duration: 1, startAngle: CGFloat.random(in: 0 ..< π/4), endAngle:pivotNode.zRotation) rotateEffect.timingFunction = SKTTimingFunctionBackEaseOut pivotNode.alpha = 0 @@ -272,10 +272,11 @@ class MyScene: SKScene, SKPhysicsContactDelegate { for ball in [ball1, ball2] { addEffectToBall(ball: ball) - ball.run(SKAction.afterDelay(1, runBlock:{ + ball.run(SKAction.after(delay: 1, runBlock:{ // Assign a random angle to the ball's velocity. let ballSpeed: CGFloat = 200 - let angle = (CGFloat.random() * 360).degreesToRadians() + + let angle = CGFloat.random(in: 0 ..< 360).degreesToRadians() ball.physicsBody!.velocity = CGVector(dx: cos(angle)*ballSpeed, dy: sin(angle)*ballSpeed) })) } @@ -355,7 +356,8 @@ class MyScene: SKScene, SKPhysicsContactDelegate { override func touchesBegan(_ touches: Set, with event: UIEvent?) { worldLayer.enumerateChildNodes(withName: "ball") {(node, stop) in let speed: CGFloat = 50 - let impulse = CGVector(dx: CGFloat.random(min: -speed, max: speed), dy: CGFloat.random(min: -speed, max: speed)) + + let impulse = CGVector(dx: CGFloat.random(in: -speed ..< speed), dy: CGFloat.random(in: -speed ..< speed)) node.physicsBody!.applyImpulse(impulse) if STRETCH_BALL { @@ -456,7 +458,7 @@ class MyScene: SKScene, SKPhysicsContactDelegate { } if COLOR_GLITCH { - run(SKAction.colorGlitchWithScene(self, originalColor: sceneBackgroundColor, duration:0.1)) + run(SKAction.colorGlitch(with: self, originalColor: sceneBackgroundColor, duration:0.1)) } } @@ -582,7 +584,7 @@ class MyScene: SKScene, SKPhysicsContactDelegate { let inverseVelocity = CGPoint(x: -velocity.dx, y: -velocity.dy) let hitVector = inverseVelocity / 50 - worldLayer.run(SKAction.screenShakeWithNode(worldLayer, amount: hitVector, oscillations: 10, duration:3)) + worldLayer.run(SKAction.screenShake(with: worldLayer, amount: hitVector, oscillations: 10, duration:3)) } /** @@ -590,7 +592,7 @@ class MyScene: SKScene, SKPhysicsContactDelegate { */ func screenZoomWithVelocity(velocity: CGVector) { let amount = CGPoint(x: 1.02, y: 1.02) - worldPivot.run(SKAction.screenZoomWithNode(worldPivot, amount: amount, oscillations: 10, duration: 3)) + worldPivot.run(SKAction.screenZoom(with: worldPivot, amount: amount, oscillations: 10, duration: 3)) } /** @@ -604,7 +606,7 @@ class MyScene: SKScene, SKPhysicsContactDelegate { let distanceToCenter = (point.y - length) / length let angle = CGFloat(10).degreesToRadians() * distanceToCenter - worldPivot.run(SKAction.screenRotateWithNode(worldPivot, angle: angle, oscillations: 1, duration: 1)) + worldPivot.run(SKAction.screenRotate(with: worldPivot, angle: angle, oscillations: 1, duration: 1)) } /** diff --git a/Examples/Playground/MyPlayground.playground/timeline.xctimeline b/Examples/Playground/MyPlayground.playground/timeline.xctimeline new file mode 100644 index 0000000..bf468af --- /dev/null +++ b/Examples/Playground/MyPlayground.playground/timeline.xctimeline @@ -0,0 +1,6 @@ + + + + + diff --git a/Examples/Playground/SKTUtils.xcodeproj/project.pbxproj b/Examples/Playground/SKTUtils.xcodeproj/project.pbxproj index c2d000b..0b47fbb 100644 --- a/Examples/Playground/SKTUtils.xcodeproj/project.pbxproj +++ b/Examples/Playground/SKTUtils.xcodeproj/project.pbxproj @@ -26,7 +26,7 @@ 481EEDB819B3AF5500469716 /* SKTUtils.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SKTUtils.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 481EEDC319B3AF5500469716 /* SKTUtilsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SKTUtilsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 7B0F9F6719C43F1700538BC0 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 7B0F9F6819C43F1700538BC0 /* MyPlayground.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = MyPlayground.playground; sourceTree = ""; }; + 7B0F9F6819C43F1700538BC0 /* MyPlayground.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = MyPlayground.playground; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 7B0F9F6919C43F1700538BC0 /* SKTUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SKTUtils.h; sourceTree = ""; }; 7B0F9F6E19C43F3200538BC0 /* CGFloat+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CGFloat+Extensions.swift"; sourceTree = ""; }; 7B0F9F6F19C43F3200538BC0 /* CGPoint+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CGPoint+Extensions.swift"; sourceTree = ""; }; @@ -164,14 +164,14 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = raywenderlich; TargetAttributes = { 481EEDB719B3AF5500469716 = { CreatedOnToolsVersion = 6.0; DevelopmentTeam = KFCNEC27GU; DevelopmentTeamName = "Razeware LLC"; - LastSwiftMigration = 0800; + LastSwiftMigration = 1020; }; 481EEDC219B3AF5500469716 = { CreatedOnToolsVersion = 6.0; @@ -185,6 +185,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = 481EEDAE19B3AF5500469716; @@ -253,13 +254,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -301,13 +310,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -326,6 +343,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -337,6 +355,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -348,7 +367,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -356,6 +375,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -367,7 +387,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/Examples/Playground/SKTUtils.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Examples/Playground/SKTUtils.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Examples/Playground/SKTUtils.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Examples/Tests/SKTUtils.xcodeproj/project.pbxproj b/Examples/Tests/SKTUtils.xcodeproj/project.pbxproj index 74dd427..37fce81 100644 --- a/Examples/Tests/SKTUtils.xcodeproj/project.pbxproj +++ b/Examples/Tests/SKTUtils.xcodeproj/project.pbxproj @@ -225,16 +225,16 @@ attributes = { LastSwiftMigration = 0700; LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = Razeware; TargetAttributes = { 7B0F9FBD19C448D500538BC0 = { CreatedOnToolsVersion = 6.0; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; }; 7B0F9FD219C448D500538BC0 = { CreatedOnToolsVersion = 6.0; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; TestTargetID = 7B0F9FBD19C448D500538BC0; }; }; @@ -353,13 +353,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -398,13 +406,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -436,7 +452,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.razeware.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -450,7 +467,8 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.razeware.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -470,7 +488,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.razeware.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SKTUtils.app/SKTUtils"; }; name = Debug; @@ -488,7 +507,8 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.razeware.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SKTUtils.app/SKTUtils"; }; name = Release; diff --git a/Examples/Tests/SKTUtils/AppDelegate.swift b/Examples/Tests/SKTUtils/AppDelegate.swift index 0931516..c1a8267 100644 --- a/Examples/Tests/SKTUtils/AppDelegate.swift +++ b/Examples/Tests/SKTUtils/AppDelegate.swift @@ -3,8 +3,4 @@ import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { - return true - } } diff --git a/Examples/Tests/SKTUtils/Images.xcassets/AppIcon.appiconset/Contents.json b/Examples/Tests/SKTUtils/Images.xcassets/AppIcon.appiconset/Contents.json index eeea76c..d8db8d6 100644 --- a/Examples/Tests/SKTUtils/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/Examples/Tests/SKTUtils/Images.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "29x29", @@ -30,6 +40,16 @@ "size" : "60x60", "scale" : "3x" }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, { "idiom" : "ipad", "size" : "29x29", @@ -64,6 +84,11 @@ "idiom" : "ipad", "size" : "83.5x83.5", "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" } ], "info" : { diff --git a/Examples/Tests/SKTUtils/Images.xcassets/LaunchImage.launchimage/Contents.json b/Examples/Tests/SKTUtils/Images.xcassets/LaunchImage.launchimage/Contents.json index 5a29666..a0ad363 100644 --- a/Examples/Tests/SKTUtils/Images.xcassets/LaunchImage.launchimage/Contents.json +++ b/Examples/Tests/SKTUtils/Images.xcassets/LaunchImage.launchimage/Contents.json @@ -3,43 +3,30 @@ { "orientation" : "portrait", "idiom" : "ipad", - "minimum-system-version" : "7.0", "extent" : "full-screen", - "scale" : "2x" - }, - { - "orientation" : "landscape", - "idiom" : "ipad", "minimum-system-version" : "7.0", - "extent" : "full-screen", "scale" : "1x" }, { "orientation" : "landscape", "idiom" : "ipad", - "minimum-system-version" : "7.0", "extent" : "full-screen", - "scale" : "2x" - }, - { - "orientation" : "portrait", - "idiom" : "iphone", "minimum-system-version" : "7.0", - "scale" : "2x" + "scale" : "1x" }, { "orientation" : "portrait", - "idiom" : "iphone", + "idiom" : "ipad", + "extent" : "full-screen", "minimum-system-version" : "7.0", - "subtype" : "retina4", "scale" : "2x" }, { - "orientation" : "portrait", + "orientation" : "landscape", "idiom" : "ipad", - "minimum-system-version" : "7.0", "extent" : "full-screen", - "scale" : "1x" + "minimum-system-version" : "7.0", + "scale" : "2x" } ], "info" : { diff --git a/Examples/Tests/SKTUtilsTests/CGPointTests.swift b/Examples/Tests/SKTUtilsTests/CGPointTests.swift index 3386996..3803f45 100755 --- a/Examples/Tests/SKTUtilsTests/CGPointTests.swift +++ b/Examples/Tests/SKTUtilsTests/CGPointTests.swift @@ -116,14 +116,14 @@ class CGPointTests: XCTestCase { func testInitWith45DegreeAngle() { let a = π/4.0 let pt = CGPoint(angle: a) - XCTAssertEqualWithAccuracy(pt.x, 1.0/sqrt(2.0), accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy(pt.y, 1.0/sqrt(2.0), accuracy: CGFloat(FLT_EPSILON)) + XCTAssertEqualWithAccuracy(pt.x, 1.0/sqrt(2.0), accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy(pt.y, 1.0/sqrt(2.0), accuracy: CGFloat(Float.ulpOfOne)) } func testInitWith90DegreeAngle() { let a = π/2.0 let pt = CGPoint(angle: a) - XCTAssertEqualWithAccuracy(pt.x, CGFloat(0.0), accuracy: CGFloat(FLT_EPSILON)) + XCTAssertEqualWithAccuracy(pt.x, CGFloat(0.0), accuracy: CGFloat(Float.ulpOfOne)) XCTAssertEqual(pt.y, CGFloat(1.0)) } @@ -131,14 +131,14 @@ class CGPointTests: XCTestCase { let a = π let pt = CGPoint(angle: a) XCTAssertEqual(pt.x, -1.0) - XCTAssertEqualWithAccuracy(pt.y, CGFloat(0.0), accuracy: CGFloat(FLT_EPSILON)) + XCTAssertEqualWithAccuracy(pt.y, CGFloat(0.0), accuracy: CGFloat(Float.ulpOfOne)) } func testInitWithMinus135DegreeAngle() { let a = -3.0*π/4.0 let pt = CGPoint(angle: a) - XCTAssertEqualWithAccuracy(pt.x, -1.0/sqrt(2.0), accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy(pt.y, -1.0/sqrt(2.0), accuracy: CGFloat(FLT_EPSILON)) + XCTAssertEqualWithAccuracy(pt.x, -1.0/sqrt(2.0), accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy(pt.y, -1.0/sqrt(2.0), accuracy: CGFloat(Float.ulpOfOne)) } func testZeroDegreeAngle() { @@ -163,7 +163,7 @@ class CGPointTests: XCTestCase { func testMinus135DegreeAngle() { let pt = CGPoint(x: -1.0/sqrt(2.0), y: -1.0/sqrt(2.0)) - XCTAssertEqualWithAccuracy(pt.angle, -3.0*π/4.0, accuracy: CGFloat(FLT_EPSILON)) + XCTAssertEqualWithAccuracy(pt.angle, -3.0*π/4.0, accuracy: CGFloat(Float.ulpOfOne)) } func testLengthHorizontalUnitVector() { @@ -192,17 +192,17 @@ class CGPointTests: XCTestCase { } func testDistance() { - XCTAssertEqualWithAccuracy(pt1.distanceTo(pt2), CGFloat(100.6230589874), accuracy: CGFloat(FLT_EPSILON)) + XCTAssertEqualWithAccuracy(pt1.distanceTo(pt2), CGFloat(100.6230589874), accuracy: CGFloat(Float.ulpOfOne)) } func testThatLengthEqualsDistance() { - XCTAssertEqualWithAccuracy(pt1.distanceTo(pt2), (pt1 - pt2).length(), accuracy: CGFloat(FLT_EPSILON)) + XCTAssertEqualWithAccuracy(pt1.distanceTo(pt2), (pt1 - pt2).length(), accuracy: CGFloat(Float.ulpOfOne)) } func testNormalized() { let normalized = pt1.normalized() - XCTAssertEqualWithAccuracy(normalized.x, 2.0/sqrt(5.0), accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy(normalized.y, 1.0/sqrt(5.0), accuracy: CGFloat(FLT_EPSILON)) + XCTAssertEqualWithAccuracy(normalized.x, 2.0/sqrt(5.0), accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy(normalized.y, 1.0/sqrt(5.0), accuracy: CGFloat(Float.ulpOfOne)) } func testThatNormalizedDoesNotChangeOriginalValue() { @@ -214,8 +214,8 @@ class CGPointTests: XCTestCase { func testThatNormalizeReturnsNewValue() { pt1.normalize() - XCTAssertEqualWithAccuracy(pt1.x, 2.0/sqrt(5.0), accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy(pt1.y, 1.0/sqrt(5.0), accuracy: CGFloat(FLT_EPSILON)) + XCTAssertEqualWithAccuracy(pt1.x, 2.0/sqrt(5.0), accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy(pt1.y, 1.0/sqrt(5.0), accuracy: CGFloat(Float.ulpOfOne)) } func testThatNormalizingKeepsSameAngle() { @@ -227,7 +227,7 @@ class CGPointTests: XCTestCase { let start = CGPoint(x: -100, y: -75) let end = CGPoint(x: 100, y: 25) - let expected = [ + let expected: [CGPoint] = [ CGPoint(x: -100, y: -75), CGPoint(x: -80, y: -65), CGPoint(x: -60, y: -55), diff --git a/Examples/Tests/SKTUtilsTests/CGVectorTests.swift b/Examples/Tests/SKTUtilsTests/CGVectorTests.swift index 37611cf..9a97a11 100755 --- a/Examples/Tests/SKTUtilsTests/CGVectorTests.swift +++ b/Examples/Tests/SKTUtilsTests/CGVectorTests.swift @@ -87,14 +87,14 @@ class CGVectorTests: XCTestCase { func testInitWith45DegreeAngle() { let a = π/4.0 let v = CGVector(angle: a) - XCTAssertEqualWithAccuracy(v.dx, 1.0/sqrt(2.0), accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy(v.dy, 1.0/sqrt(2.0), accuracy: CGFloat(FLT_EPSILON)) + XCTAssertEqualWithAccuracy(v.dx, 1.0/sqrt(2.0), accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy(v.dy, 1.0/sqrt(2.0), accuracy: CGFloat(Float.ulpOfOne)) } func testInitWith90DegreeAngle() { let a = π/2.0 let v = CGVector(angle: a) - XCTAssertEqualWithAccuracy(v.dx, CGFloat(0.0), accuracy: CGFloat(FLT_EPSILON)) + XCTAssertEqualWithAccuracy(v.dx, CGFloat(0.0), accuracy: CGFloat(Float.ulpOfOne)) XCTAssertEqual(v.dy, CGFloat(1.0)) } @@ -102,14 +102,14 @@ class CGVectorTests: XCTestCase { let a = π let v = CGVector(angle: a) XCTAssertEqual(v.dx, -1.0) - XCTAssertEqualWithAccuracy(v.dy, CGFloat(0.0), accuracy: CGFloat(FLT_EPSILON)) + XCTAssertEqualWithAccuracy(v.dy, CGFloat(0.0), accuracy: CGFloat(Float.ulpOfOne)) } func testInitWithMinus135DegreeAngle() { let a = -3.0*π/4.0 let v = CGVector(angle: a) - XCTAssertEqualWithAccuracy(v.dx, -1.0/sqrt(2.0), accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy(v.dy, -1.0/sqrt(2.0), accuracy: CGFloat(FLT_EPSILON)) + XCTAssertEqualWithAccuracy(v.dx, -1.0/sqrt(2.0), accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy(v.dy, -1.0/sqrt(2.0), accuracy: CGFloat(Float.ulpOfOne)) } func testZeroDegreeAngle() { @@ -134,7 +134,7 @@ class CGVectorTests: XCTestCase { func testMinus135DegreeAngle() { let v = CGVector(dx: -1.0/sqrt(2.0), dy: -1.0/sqrt(2.0)) - XCTAssertEqualWithAccuracy(v.angle, -3.0*π/4.0, accuracy: CGFloat(FLT_EPSILON)) + XCTAssertEqualWithAccuracy(v.angle, -3.0*π/4.0, accuracy: CGFloat(Float.ulpOfOne)) } func testLengthHorizontalUnitVector() { @@ -163,17 +163,17 @@ class CGVectorTests: XCTestCase { } func testDistance() { - XCTAssertEqualWithAccuracy(v1.distanceTo(v2), CGFloat(100.6230589874), accuracy: CGFloat(FLT_EPSILON)) + XCTAssertEqualWithAccuracy(v1.distanceTo(v2), CGFloat(100.6230589874), accuracy: CGFloat(Float.ulpOfOne)) } func testThatLengthEqualsDistance() { - XCTAssertEqualWithAccuracy(v1.distanceTo(v2), (v1 - v2).length(), accuracy: CGFloat(FLT_EPSILON)) + XCTAssertEqualWithAccuracy(v1.distanceTo(v2), (v1 - v2).length(), accuracy: CGFloat(Float.ulpOfOne)) } func testNormalized() { let normalized = v1.normalized() - XCTAssertEqualWithAccuracy(normalized.dx, 2.0/sqrt(5.0), accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy(normalized.dy, 1.0/sqrt(5.0), accuracy: CGFloat(FLT_EPSILON)) + XCTAssertEqualWithAccuracy(normalized.dx, 2.0/sqrt(5.0), accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy(normalized.dy, 1.0/sqrt(5.0), accuracy: CGFloat(Float.ulpOfOne)) } func testThatNormalizedDoesNotChangeOriginalValue() { @@ -185,8 +185,8 @@ class CGVectorTests: XCTestCase { func testThatNormalizeReturnsNewValue() { v1.normalize() - XCTAssertEqualWithAccuracy(v1.dx, 2.0/sqrt(5.0), accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy(v1.dy, 1.0/sqrt(5.0), accuracy: CGFloat(FLT_EPSILON)) + XCTAssertEqualWithAccuracy(v1.dx, 2.0/sqrt(5.0), accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy(v1.dy, 1.0/sqrt(5.0), accuracy: CGFloat(Float.ulpOfOne)) } func testThatNormalizingKeepsSameAngle() { diff --git a/Examples/Tests/SKTUtilsTests/FloatTests.swift b/Examples/Tests/SKTUtilsTests/FloatTests.swift index 4f16c72..e6fea4c 100755 --- a/Examples/Tests/SKTUtilsTests/FloatTests.swift +++ b/Examples/Tests/SKTUtilsTests/FloatTests.swift @@ -70,25 +70,25 @@ class FloatTests: XCTestCase { } func testDegreesToRadians() { - XCTAssertEqualWithAccuracy(CGFloat(0).degreesToRadians(), CGFloat(0), accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy(CGFloat(45).degreesToRadians(), π/4, accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy(CGFloat(90).degreesToRadians(), π/2, accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy(CGFloat(135).degreesToRadians(), 3*π/4, accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy(CGFloat(180).degreesToRadians(), π, accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy(CGFloat(-135).degreesToRadians(), -3*π/4, accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy(CGFloat(-90).degreesToRadians(), -π/2, accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy(CGFloat(-45).degreesToRadians(), -π/4, accuracy: CGFloat(FLT_EPSILON)) + XCTAssertEqualWithAccuracy(CGFloat(0).degreesToRadians(), CGFloat(0), accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy(CGFloat(45).degreesToRadians(), π/4, accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy(CGFloat(90).degreesToRadians(), π/2, accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy(CGFloat(135).degreesToRadians(), 3*π/4, accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy(CGFloat(180).degreesToRadians(), π, accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy(CGFloat(-135).degreesToRadians(), -3*π/4, accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy(CGFloat(-90).degreesToRadians(), -π/2, accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy(CGFloat(-45).degreesToRadians(), -π/4, accuracy: CGFloat(Float.ulpOfOne)) } func testRadiansToDegrees() { - XCTAssertEqualWithAccuracy(CGFloat(0).radiansToDegrees(), CGFloat(0), accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy((π/4).radiansToDegrees(), CGFloat(45), accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy((π/2).radiansToDegrees(), CGFloat(90), accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy((3*π/4).radiansToDegrees(), CGFloat(135), accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy(π.radiansToDegrees(), CGFloat(180), accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy((-3*π/4).radiansToDegrees(), CGFloat(-135), accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy((-π/2).radiansToDegrees(), CGFloat(-90), accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy((-π/4).radiansToDegrees(), CGFloat(-45), accuracy: CGFloat(FLT_EPSILON)) + XCTAssertEqualWithAccuracy(CGFloat(0).radiansToDegrees(), CGFloat(0), accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy((π/4).radiansToDegrees(), CGFloat(45), accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy((π/2).radiansToDegrees(), CGFloat(90), accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy((3*π/4).radiansToDegrees(), CGFloat(135), accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy(π.radiansToDegrees(), CGFloat(180), accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy((-3*π/4).radiansToDegrees(), CGFloat(-135), accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy((-π/2).radiansToDegrees(), CGFloat(-90), accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy((-π/4).radiansToDegrees(), CGFloat(-45), accuracy: CGFloat(Float.ulpOfOne)) } func testAllAngles() { diff --git a/Examples/Tests/SKTUtilsTests/Vector3Tests.swift b/Examples/Tests/SKTUtilsTests/Vector3Tests.swift index 689781b..1bf5a75 100644 --- a/Examples/Tests/SKTUtilsTests/Vector3Tests.swift +++ b/Examples/Tests/SKTUtilsTests/Vector3Tests.swift @@ -106,9 +106,9 @@ class Vector3Tests: XCTestCase { func testNormalized() { let normalized = v1.normalized() - XCTAssertEqualWithAccuracy(normalized.x, 4.0/sqrt(21.0), accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy(normalized.y, 2.0/sqrt(21.0), accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy(normalized.z, 1.0/sqrt(21.0), accuracy: CGFloat(FLT_EPSILON)) + XCTAssertEqualWithAccuracy(normalized.x, 4.0/sqrt(21.0), accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy(normalized.y, 2.0/sqrt(21.0), accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy(normalized.z, 1.0/sqrt(21.0), accuracy: CGFloat(Float.ulpOfOne)) } func testThatNormalizedDoesNotChangeOriginalValue() { @@ -121,9 +121,9 @@ class Vector3Tests: XCTestCase { func testThatNormalizeReturnsNewValue() { v1.normalize() - XCTAssertEqualWithAccuracy(v1.x, 4.0/sqrt(21.0), accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy(v1.y, 2.0/sqrt(21.0), accuracy: CGFloat(FLT_EPSILON)) - XCTAssertEqualWithAccuracy(v1.z, 1.0/sqrt(21.0), accuracy: CGFloat(FLT_EPSILON)) + XCTAssertEqualWithAccuracy(v1.x, 4.0/sqrt(21.0), accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy(v1.y, 2.0/sqrt(21.0), accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqualWithAccuracy(v1.z, 1.0/sqrt(21.0), accuracy: CGFloat(Float.ulpOfOne)) } func testLerp() { diff --git a/LICENSE.txt b/LICENSE.txt index fc92ae0..ddb36c4 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2013-2014 Razeware LLC +Copyright (c) 2013-2017 Razeware LLC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/SKTUtils/CGFloat+Extensions.swift b/SKTUtils/CGFloat+Extensions.swift index 7b9104c..1a2e16f 100644 --- a/SKTUtils/CGFloat+Extensions.swift +++ b/SKTUtils/CGFloat+Extensions.swift @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Razeware LLC + * Copyright (c) 2013-2017 Razeware LLC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -23,27 +23,27 @@ import CoreGraphics /** The value of π as a CGFloat */ -let π = CGFloat(M_PI) +let π = CGFloat(Double.pi) public extension CGFloat { /** * Converts an angle in degrees to radians. */ - public func degreesToRadians() -> CGFloat { + func degreesToRadians() -> CGFloat { return π * self / 180.0 } /** * Converts an angle in radians to degrees. */ - public func radiansToDegrees() -> CGFloat { + func radiansToDegrees() -> CGFloat { return self * 180.0 / π } /** * Ensures that the float value stays between the given values, inclusive. */ - public func clamped(_ v1: CGFloat, _ v2: CGFloat) -> CGFloat { + func clamped(_ v1: CGFloat, _ v2: CGFloat) -> CGFloat { let min = v1 < v2 ? v1 : v2 let max = v1 > v2 ? v1 : v2 return self < min ? min : (self > max ? max : self) @@ -52,7 +52,8 @@ public extension CGFloat { /** * Ensures that the float value stays between the given values, inclusive. */ - public mutating func clamp(_ v1: CGFloat, _ v2: CGFloat) -> CGFloat { + @discardableResult + mutating func clamp(_ v1: CGFloat, _ v2: CGFloat) -> CGFloat { self = clamped(v1, v2) return self } @@ -60,38 +61,16 @@ public extension CGFloat { /** * Returns 1.0 if a floating point value is positive; -1.0 if it is negative. */ - public func sign() -> CGFloat { + func sign() -> CGFloat { return (self >= 0.0) ? 1.0 : -1.0 } - - /** - * Returns a random floating point number between 0.0 and 1.0, inclusive. - */ - public static func random() -> CGFloat { - return CGFloat(Float(arc4random()) / 0xFFFFFFFF) - } - - /** - * Returns a random floating point number in the range min...max, inclusive. - */ - public static func random(min: CGFloat, max: CGFloat) -> CGFloat { - assert(min < max) - return CGFloat.random() * (max - min) + min - } - - /** - * Randomly returns either 1.0 or -1.0. - */ - public static func randomSign() -> CGFloat { - return (arc4random_uniform(2) == 0) ? 1.0 : -1.0 - } } /** * Returns the shortest angle between two angles. The result is always between * -π and π. */ -public func shortestAngleBetween(_ angle1: CGFloat, angle2: CGFloat) -> CGFloat { +func shortestAngleBetween(_ angle1: CGFloat, angle2: CGFloat) -> CGFloat { let twoπ = π * 2.0 var angle = (angle2 - angle1).truncatingRemainder(dividingBy: twoπ) if (angle >= π) { diff --git a/SKTUtils/CGPoint+Extensions.swift b/SKTUtils/CGPoint+Extensions.swift index 9904f75..c21a723 100644 --- a/SKTUtils/CGPoint+Extensions.swift +++ b/SKTUtils/CGPoint+Extensions.swift @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Razeware LLC + * Copyright (c) 2013-2017 Razeware LLC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -27,22 +27,22 @@ public extension CGPoint { /** * Creates a new CGPoint given a CGVector. */ - public init(vector: CGVector) { - self.init(x: vector.dx, y: vector.dy) - } + init(vector: CGVector) { + self.init(x: vector.dx, y: vector.dy) + } /** * Given an angle in radians, creates a vector of length 1.0 and returns the * result as a new CGPoint. An angle of 0 is assumed to point to the right. */ - public init(angle: CGFloat) { + init(angle: CGFloat) { self.init(x: cos(angle), y: sin(angle)) } /** * Adds (dx, dy) to the point. */ - public mutating func offset(dx: CGFloat, dy: CGFloat) -> CGPoint { + @discardableResult mutating func offset(dx: CGFloat, dy: CGFloat) -> CGPoint { x += dx y += dy return self @@ -51,14 +51,14 @@ public extension CGPoint { /** * Returns the length (magnitude) of the vector described by the CGPoint. */ - public func length() -> CGFloat { + func length() -> CGFloat { return sqrt(x*x + y*y) } /** * Returns the squared length of the vector described by the CGPoint. */ - public func lengthSquared() -> CGFloat { + func lengthSquared() -> CGFloat { return x*x + y*y } @@ -74,7 +74,8 @@ public extension CGPoint { /** * Normalizes the vector described by the CGPoint to length 1.0. */ - public mutating func normalize() -> CGPoint { + @discardableResult + mutating func normalize() -> CGPoint { self = normalized() return self } @@ -82,7 +83,7 @@ public extension CGPoint { /** * Calculates the distance between two CGPoints. Pythagoras! */ - public func distanceTo(_ point: CGPoint) -> CGFloat { + func distance(to point: CGPoint) -> CGFloat { return (self - point).length() } @@ -90,7 +91,7 @@ public extension CGPoint { * Returns the angle in radians of the vector described by the CGPoint. * The range of the angle is -π to π; an angle of 0 points to the right. */ - public var angle: CGFloat { + var angle: CGFloat { return atan2(y, x) } } @@ -98,70 +99,70 @@ public extension CGPoint { /** * Adds two CGPoint values and returns the result as a new CGPoint. */ -public func + (left: CGPoint, right: CGPoint) -> CGPoint { +func + (left: CGPoint, right: CGPoint) -> CGPoint { return CGPoint(x: left.x + right.x, y: left.y + right.y) } /** * Increments a CGPoint with the value of another. */ -public func += (left: inout CGPoint, right: CGPoint) { +func += (left: inout CGPoint, right: CGPoint) { left = left + right } /** * Adds a CGVector to this CGPoint and returns the result as a new CGPoint. */ -public func + (left: CGPoint, right: CGVector) -> CGPoint { +func + (left: CGPoint, right: CGVector) -> CGPoint { return CGPoint(x: left.x + right.dx, y: left.y + right.dy) } /** * Increments a CGPoint with the value of a CGVector. */ -public func += (left: inout CGPoint, right: CGVector) { +func += (left: inout CGPoint, right: CGVector) { left = left + right } /** * Subtracts two CGPoint values and returns the result as a new CGPoint. */ -public func - (left: CGPoint, right: CGPoint) -> CGPoint { +func - (left: CGPoint, right: CGPoint) -> CGPoint { return CGPoint(x: left.x - right.x, y: left.y - right.y) } /** * Decrements a CGPoint with the value of another. */ -public func -= (left: inout CGPoint, right: CGPoint) { +func -= (left: inout CGPoint, right: CGPoint) { left = left - right } /** * Subtracts a CGVector from a CGPoint and returns the result as a new CGPoint. */ -public func - (left: CGPoint, right: CGVector) -> CGPoint { +func - (left: CGPoint, right: CGVector) -> CGPoint { return CGPoint(x: left.x - right.dx, y: left.y - right.dy) } /** * Decrements a CGPoint with the value of a CGVector. */ -public func -= (left: inout CGPoint, right: CGVector) { +func -= (left: inout CGPoint, right: CGVector) { left = left - right } /** * Multiplies two CGPoint values and returns the result as a new CGPoint. */ -public func * (left: CGPoint, right: CGPoint) -> CGPoint { +func * (left: CGPoint, right: CGPoint) -> CGPoint { return CGPoint(x: left.x * right.x, y: left.y * right.y) } /** * Multiplies a CGPoint with another. */ -public func *= (left: inout CGPoint, right: CGPoint) { +func *= (left: inout CGPoint, right: CGPoint) { left = left * right } @@ -169,42 +170,42 @@ public func *= (left: inout CGPoint, right: CGPoint) { * Multiplies the x and y fields of a CGPoint with the same scalar value and * returns the result as a new CGPoint. */ -public func * (point: CGPoint, scalar: CGFloat) -> CGPoint { +func * (point: CGPoint, scalar: CGFloat) -> CGPoint { return CGPoint(x: point.x * scalar, y: point.y * scalar) } /** * Multiplies the x and y fields of a CGPoint with the same scalar value. */ -public func *= (point: inout CGPoint, scalar: CGFloat) { +func *= (point: inout CGPoint, scalar: CGFloat) { point = point * scalar } /** * Multiplies a CGPoint with a CGVector and returns the result as a new CGPoint. */ -public func * (left: CGPoint, right: CGVector) -> CGPoint { +func * (left: CGPoint, right: CGVector) -> CGPoint { return CGPoint(x: left.x * right.dx, y: left.y * right.dy) } /** * Multiplies a CGPoint with a CGVector. */ -public func *= (left: inout CGPoint, right: CGVector) { +func *= (left: inout CGPoint, right: CGVector) { left = left * right } /** * Divides two CGPoint values and returns the result as a new CGPoint. */ -public func / (left: CGPoint, right: CGPoint) -> CGPoint { +func / (left: CGPoint, right: CGPoint) -> CGPoint { return CGPoint(x: left.x / right.x, y: left.y / right.y) } /** * Divides a CGPoint by another. */ -public func /= (left: inout CGPoint, right: CGPoint) { +func /= (left: inout CGPoint, right: CGPoint) { left = left / right } @@ -212,34 +213,34 @@ public func /= (left: inout CGPoint, right: CGPoint) { * Divides the x and y fields of a CGPoint by the same scalar value and returns * the result as a new CGPoint. */ -public func / (point: CGPoint, scalar: CGFloat) -> CGPoint { +func / (point: CGPoint, scalar: CGFloat) -> CGPoint { return CGPoint(x: point.x / scalar, y: point.y / scalar) } /** * Divides the x and y fields of a CGPoint by the same scalar value. */ -public func /= (point: inout CGPoint, scalar: CGFloat) { +func /= (point: inout CGPoint, scalar: CGFloat) { point = point / scalar } /** * Divides a CGPoint by a CGVector and returns the result as a new CGPoint. */ -public func / (left: CGPoint, right: CGVector) -> CGPoint { +func / (left: CGPoint, right: CGVector) -> CGPoint { return CGPoint(x: left.x / right.dx, y: left.y / right.dy) } /** * Divides a CGPoint by a CGVector. */ -public func /= (left: inout CGPoint, right: CGVector) { +func /= (left: inout CGPoint, right: CGVector) { left = left / right } /** * Performs a linear interpolation between two CGPoint values. */ -public func lerp(start: CGPoint, end: CGPoint, t: CGFloat) -> CGPoint { +func lerp(start: CGPoint, end: CGPoint, t: CGFloat) -> CGPoint { return start + (end - start) * t } diff --git a/SKTUtils/CGVector+Extensions.swift b/SKTUtils/CGVector+Extensions.swift index 5474490..b362c7c 100644 --- a/SKTUtils/CGVector+Extensions.swift +++ b/SKTUtils/CGVector+Extensions.swift @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Razeware LLC + * Copyright (c) 2013-2017 Razeware LLC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -27,7 +27,7 @@ public extension CGVector { /** * Creates a new CGVector given a CGPoint. */ - public init(point: CGPoint) { + init(point: CGPoint) { self.init(dx: point.x, dy: point.y) } @@ -35,14 +35,15 @@ public extension CGVector { * Given an angle in radians, creates a vector of length 1.0 and returns the * result as a new CGVector. An angle of 0 is assumed to point to the right. */ - public init(angle: CGFloat) { + init(angle: CGFloat) { self.init(dx: cos(angle), dy: sin(angle)) } /** * Adds (dx, dy) to the vector. */ - public mutating func offset(dx: CGFloat, dy: CGFloat) -> CGVector { + @discardableResult + mutating func offset(dx: CGFloat, dy: CGFloat) -> CGVector { self.dx += dx self.dy += dy return self @@ -51,14 +52,14 @@ public extension CGVector { /** * Returns the length (magnitude) of the vector described by the CGVector. */ - public func length() -> CGFloat { + func length() -> CGFloat { return sqrt(dx*dx + dy*dy) } /** * Returns the squared length of the vector described by the CGVector. */ - public func lengthSquared() -> CGFloat { + func lengthSquared() -> CGFloat { return dx*dx + dy*dy } @@ -74,7 +75,8 @@ public extension CGVector { /** * Normalizes the vector described by the CGVector to length 1.0. */ - public mutating func normalize() -> CGVector { + @discardableResult + mutating func normalize() -> CGVector { self = normalized() return self } @@ -82,7 +84,7 @@ public extension CGVector { /** * Calculates the distance between two CGVectors. Pythagoras! */ - public func distanceTo(_ vector: CGVector) -> CGFloat { + func distance(to vector: CGVector) -> CGFloat { return (self - vector).length() } @@ -90,7 +92,7 @@ public extension CGVector { * Returns the angle in radians of the vector described by the CGVector. * The range of the angle is -π to π; an angle of 0 points to the right. */ - public var angle: CGFloat { + var angle: CGFloat { return atan2(dy, dx) } } @@ -98,42 +100,42 @@ public extension CGVector { /** * Adds two CGVector values and returns the result as a new CGVector. */ -public func + (left: CGVector, right: CGVector) -> CGVector { +func + (left: CGVector, right: CGVector) -> CGVector { return CGVector(dx: left.dx + right.dx, dy: left.dy + right.dy) } /** * Increments a CGVector with the value of another. */ -public func += (left: inout CGVector, right: CGVector) { +func += (left: inout CGVector, right: CGVector) { left = left + right } /** * Subtracts two CGVector values and returns the result as a new CGVector. */ -public func - (left: CGVector, right: CGVector) -> CGVector { +func - (left: CGVector, right: CGVector) -> CGVector { return CGVector(dx: left.dx - right.dx, dy: left.dy - right.dy) } /** * Decrements a CGVector with the value of another. */ -public func -= (left: inout CGVector, right: CGVector) { +func -= (left: inout CGVector, right: CGVector) { left = left - right } /** * Multiplies two CGVector values and returns the result as a new CGVector. */ -public func * (left: CGVector, right: CGVector) -> CGVector { +func * (left: CGVector, right: CGVector) -> CGVector { return CGVector(dx: left.dx * right.dx, dy: left.dy * right.dy) } /** * Multiplies a CGVector with another. */ -public func *= (left: inout CGVector, right: CGVector) { +func *= (left: inout CGVector, right: CGVector) { left = left * right } @@ -141,28 +143,28 @@ public func *= (left: inout CGVector, right: CGVector) { * Multiplies the x and y fields of a CGVector with the same scalar value and * returns the result as a new CGVector. */ -public func * (vector: CGVector, scalar: CGFloat) -> CGVector { +func * (vector: CGVector, scalar: CGFloat) -> CGVector { return CGVector(dx: vector.dx * scalar, dy: vector.dy * scalar) } /** * Multiplies the x and y fields of a CGVector with the same scalar value. */ -public func *= (vector: inout CGVector, scalar: CGFloat) { +func *= (vector: inout CGVector, scalar: CGFloat) { vector = vector * scalar } /** * Divides two CGVector values and returns the result as a new CGVector. */ -public func / (left: CGVector, right: CGVector) -> CGVector { +func / (left: CGVector, right: CGVector) -> CGVector { return CGVector(dx: left.dx / right.dx, dy: left.dy / right.dy) } /** * Divides a CGVector by another. */ -public func /= (left: inout CGVector, right: CGVector) { +func /= (left: inout CGVector, right: CGVector) { left = left / right } @@ -170,20 +172,20 @@ public func /= (left: inout CGVector, right: CGVector) { * Divides the dx and dy fields of a CGVector by the same scalar value and * returns the result as a new CGVector. */ -public func / (vector: CGVector, scalar: CGFloat) -> CGVector { +func / (vector: CGVector, scalar: CGFloat) -> CGVector { return CGVector(dx: vector.dx / scalar, dy: vector.dy / scalar) } /** * Divides the dx and dy fields of a CGVector by the same scalar value. */ -public func /= (vector: inout CGVector, scalar: CGFloat) { +func /= (vector: inout CGVector, scalar: CGFloat) { vector = vector / scalar } /** * Performs a linear interpolation between two CGVector values. */ -public func lerp(start: CGVector, end: CGVector, t: CGFloat) -> CGVector { +func lerp(start: CGVector, end: CGVector, t: CGFloat) -> CGVector { return start + (end - start) * t } diff --git a/SKTUtils/Int+Extensions.swift b/SKTUtils/Int+Extensions.swift index 0d6f134..ea21863 100644 --- a/SKTUtils/Int+Extensions.swift +++ b/SKTUtils/Int+Extensions.swift @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Razeware LLC + * Copyright (c) 2013-2017 Razeware LLC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,23 +26,25 @@ public extension Int { /** * Ensures that the integer value stays with the specified range. */ - public func clamped(_ range: Range) -> Int { + func clamped(_ range: Range) -> Int { return (self < range.lowerBound) ? range.lowerBound : ((self >= range.upperBound) ? range.upperBound - 1: self) } - public func clamped(_ range: ClosedRange) -> Int { + func clamped(_ range: ClosedRange) -> Int { return (self < range.lowerBound) ? range.lowerBound : ((self > range.upperBound) ? range.upperBound: self) } /** * Ensures that the integer value stays with the specified range. */ - public mutating func clamp(_ range: Range) -> Int { + @discardableResult + mutating func clamp(_ range: Range) -> Int { self = clamped(range) return self } - public mutating func clamp(_ range: ClosedRange) -> Int { + @discardableResult + mutating func clamp(_ range: ClosedRange) -> Int { self = clamped(range) return self } @@ -50,7 +52,7 @@ public extension Int { /** * Ensures that the integer value stays between the given values, inclusive. */ - public func clamped(_ v1: Int, _ v2: Int) -> Int { + func clamped(_ v1: Int, _ v2: Int) -> Int { let min = v1 < v2 ? v1 : v2 let max = v1 > v2 ? v1 : v2 return self < min ? min : (self > max ? max : self) @@ -59,34 +61,9 @@ public extension Int { /** * Ensures that the integer value stays between the given values, inclusive. */ - public mutating func clamp(_ v1: Int, _ v2: Int) -> Int { + @discardableResult + mutating func clamp(_ v1: Int, _ v2: Int) -> Int { self = clamped(v1, v2) return self } - - /** - * Returns a random integer in the specified range. - */ - public static func random(_ range: Range) -> Int { - return Int(arc4random_uniform(UInt32(range.upperBound - range.lowerBound - 1))) + range.lowerBound - } - - public static func random(_ range: ClosedRange) -> Int { - return Int(arc4random_uniform(UInt32(range.upperBound - range.lowerBound))) + range.lowerBound - } - - /** - * Returns a random integer between 0 and n-1. - */ - public static func random(_ n: Int) -> Int { - return Int(arc4random_uniform(UInt32(n))) - } - - /** - * Returns a random integer in the range min...max, inclusive. - */ - public static func random(min: Int, max: Int) -> Int { - assert(min < max) - return Int(arc4random_uniform(UInt32(max - min + 1))) + min - } } diff --git a/SKTUtils/SKAction+Extensions.swift b/SKTUtils/SKAction+Extensions.swift index 2f28876..a491245 100644 --- a/SKTUtils/SKAction+Extensions.swift +++ b/SKTUtils/SKAction+Extensions.swift @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Razeware LLC + * Copyright (c) 2013-2017 Razeware LLC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,32 +26,32 @@ public extension SKAction { /** * Performs an action after the specified delay. */ - public class func afterDelay(_ delay: TimeInterval, performAction action: SKAction) -> SKAction { - return SKAction.sequence([SKAction.wait(forDuration: delay), action]) - } + class func after(delay: TimeInterval, performAction action: SKAction) -> SKAction { + return SKAction.sequence([SKAction.wait(forDuration: delay), action]) + } /** * Performs a block after the specified delay. */ - public class func afterDelay(_ delay: TimeInterval, runBlock block: @escaping () -> Void) -> SKAction { - return SKAction.afterDelay(delay, performAction: SKAction.run(block)) - } + class func after(delay: TimeInterval, runBlock block: @escaping () -> Void) -> SKAction { + return SKAction.after(delay: delay, performAction: SKAction.run(block)) + } /** * Removes the node from its parent after the specified delay. */ - public class func removeFromParentAfterDelay(_ delay: TimeInterval) -> SKAction { - return SKAction.afterDelay(delay, performAction: SKAction.removeFromParent()) - } + class func removeFromParent(with delay: TimeInterval) -> SKAction { + return SKAction.after(delay: delay, performAction: SKAction.removeFromParent()) + } /** * Creates an action to perform a parabolic jump. */ - public class func jumpToHeight(_ height: CGFloat, duration: TimeInterval, originalPosition: CGPoint) -> SKAction { - return SKAction.customAction(withDuration: duration) {(node, elapsedTime) in - let fraction = elapsedTime / CGFloat(duration) - let yOffset = height * 4 * fraction * (1 - fraction) - node.position = CGPoint(x: originalPosition.x, y: originalPosition.y + yOffset) + class func jump(to height: CGFloat, duration: TimeInterval, originalPosition: CGPoint) -> SKAction { + return SKAction.customAction(withDuration: duration) {(node, elapsedTime) in + let fraction = elapsedTime / CGFloat(duration) + let yOffset = height * 4 * fraction * (1 - fraction) + node.position = CGPoint(x: originalPosition.x, y: originalPosition.y + yOffset) + } } - } } diff --git a/SKTUtils/SKAction+SpecialEffects.swift b/SKTUtils/SKAction+SpecialEffects.swift index b81f36d..2ea8e7a 100644 --- a/SKTUtils/SKAction+SpecialEffects.swift +++ b/SKTUtils/SKAction+SpecialEffects.swift @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Razeware LLC + * Copyright (c) 2013-2017 Razeware LLC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -31,7 +31,7 @@ public extension SKAction { * @param oscillations The number of oscillations; 10 is a good value. * @param duration How long the effect lasts. Shorter is better. */ - public class func screenShakeWithNode(_ node: SKNode, amount: CGPoint, oscillations: Int, duration: TimeInterval) -> SKAction { + class func screenShake(with node: SKNode, amount: CGPoint, oscillations: Int, duration: TimeInterval) -> SKAction { let oldPosition = node.position let newPosition = oldPosition + amount @@ -50,7 +50,7 @@ public extension SKAction { * @param oscillations The number of oscillations; 10 is a good value. * @param duration How long the effect lasts. Shorter is better. */ - public class func screenRotateWithNode(_ node: SKNode, angle: CGFloat, oscillations: Int, duration: TimeInterval) -> SKAction { + class func screenRotate(with node: SKNode, angle: CGFloat, oscillations: Int, duration: TimeInterval) -> SKAction { let oldAngle = node.zRotation let newAngle = oldAngle + angle @@ -69,26 +69,27 @@ public extension SKAction { * @param oscillations The number of oscillations; 10 is a good value. * @param duration How long the effect lasts. Shorter is better. */ - public class func screenZoomWithNode(_ node: SKNode, amount: CGPoint, oscillations: Int, duration: TimeInterval) -> SKAction { - let oldScale = CGPoint(x: node.xScale, y: node.yScale) - let newScale = oldScale * amount - - let effect = SKTScaleEffect(node: node, duration: duration, startScale: newScale, endScale: oldScale) - effect.timingFunction = SKTCreateShakeFunction(oscillations) + class func screenZoom(with node: SKNode, amount: CGPoint, oscillations: Int, duration: TimeInterval) -> SKAction { + let oldScale = CGPoint(x: node.xScale, y: node.yScale) + let newScale = oldScale * amount - return SKAction.actionWithEffect(effect) - } + let effect = SKTScaleEffect(node: node, duration: duration, startScale: newScale, endScale: oldScale) + effect.timingFunction = SKTCreateShakeFunction(oscillations) + + return SKAction.actionWithEffect(effect) + } /** * Causes the scene background to flash for duration seconds. */ - public class func colorGlitchWithScene(_ scene: SKScene, originalColor: SKColor, duration: TimeInterval) -> SKAction { - return SKAction.customAction(withDuration: duration) {(node, elapsedTime) in - if elapsedTime < CGFloat(duration) { - scene.backgroundColor = SKColorWithRGB(Int.random(0...255), g: Int.random(0...255), b: Int.random(0...255)) - } else { - scene.backgroundColor = originalColor - } + class func colorGlitch(with scene: SKScene, originalColor: SKColor, duration: TimeInterval) -> SKAction { + return SKAction.customAction(withDuration: duration) {(node, elapsedTime) in + if elapsedTime < CGFloat(duration) { + + scene.backgroundColor = SKColorWithRGB(Int.random(in: 0...255), g: Int.random(in: 0...255), b: Int.random(in: 0...255)) + } else { + scene.backgroundColor = originalColor + } + } } - } } diff --git a/SKTUtils/SKColor+Extensions.swift b/SKTUtils/SKColor+Extensions.swift index 1eed3d2..a3c6b88 100644 --- a/SKTUtils/SKColor+Extensions.swift +++ b/SKTUtils/SKColor+Extensions.swift @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Razeware LLC + * Copyright (c) 2013-2017 Razeware LLC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -22,10 +22,10 @@ import SpriteKit -public func SKColorWithRGB(_ r: Int, g: Int, b: Int) -> SKColor { +func SKColorWithRGB(_ r: Int, g: Int, b: Int) -> SKColor { return SKColor(red: CGFloat(r)/255.0, green: CGFloat(g)/255.0, blue: CGFloat(b)/255.0, alpha: 1.0) } -public func SKColorWithRGBA(_ r: Int, g: Int, b: Int, a: Int) -> SKColor { +func SKColorWithRGBA(_ r: Int, g: Int, b: Int, a: Int) -> SKColor { return SKColor(red: CGFloat(r)/255.0, green: CGFloat(g)/255.0, blue: CGFloat(b)/255.0, alpha: CGFloat(a)/255.0) } diff --git a/SKTUtils/SKNode+Extensions.swift b/SKTUtils/SKNode+Extensions.swift index ee76ed9..d3ecdb3 100644 --- a/SKTUtils/SKNode+Extensions.swift +++ b/SKTUtils/SKNode+Extensions.swift @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Razeware LLC + * Copyright (c) 2013-2017 Razeware LLC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,7 +25,7 @@ import SpriteKit public extension SKNode { /** Lets you treat the node's scale as a CGPoint value. */ - public var scaleAsPoint: CGPoint { + var scaleAsPoint: CGPoint { get { return CGPoint(x: xScale, y: yScale) } @@ -39,14 +39,14 @@ public extension SKNode { * Runs an action on the node that performs a closure or function after * a given time. */ - public func afterDelay(_ delay: TimeInterval, runBlock block: @escaping () -> Void) { + func afterDelay(_ delay: TimeInterval, runBlock block: @escaping () -> Void) { run(SKAction.sequence([SKAction.wait(forDuration: delay), SKAction.run(block)])) } /** * Makes this node the frontmost node in its parent. */ - public func bringToFront() { + func bringToFront() { if let parent = self.parent{ removeFromParent() parent.addChild(self) @@ -62,7 +62,7 @@ public extension SKNode { * @param rate How fast the node rotates. Must have a value between 0.0 and * 1.0, where smaller means slower; 1.0 is instantaneous. */ - public func rotateToVelocity(_ velocity: CGVector, rate: CGFloat) { + func rotateToVelocity(_ velocity: CGVector, rate: CGFloat) { // Determine what the rotation angle of the node ought to be based on the // current velocity of its physics body. This assumes that at 0 degrees the // node is pointed up, not to the right, so to compensate we subtract π/4 diff --git a/SKTUtils/SKTAudio.swift b/SKTUtils/SKTAudio.swift index 84396bd..f260db9 100644 --- a/SKTUtils/SKTAudio.swift +++ b/SKTUtils/SKTAudio.swift @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Razeware LLC + * Copyright (c) 2013-2017 Razeware LLC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -34,7 +34,7 @@ public class SKTAudio { return SKTAudioInstance } - public func playBackgroundMusic(_ filename: String) { + func playBackgroundMusic(_ filename: String) { let url = Bundle.main.url(forResource: filename, withExtension: nil) if (url == nil) { print("Could not find file: \(filename)") @@ -57,7 +57,7 @@ public class SKTAudio { } } - public func pauseBackgroundMusic() { + func pauseBackgroundMusic() { if let player = backgroundMusicPlayer { if player.isPlaying { player.pause() @@ -65,7 +65,7 @@ public class SKTAudio { } } - public func resumeBackgroundMusic() { + func resumeBackgroundMusic() { if let player = backgroundMusicPlayer { if !player.isPlaying { player.play() @@ -73,7 +73,7 @@ public class SKTAudio { } } - public func playSoundEffect(_ filename: String) { + func playSoundEffect(_ filename: String) { let url = Bundle.main.url(forResource: filename, withExtension: nil) if (url == nil) { print("Could not find file: \(filename)") diff --git a/SKTUtils/SKTEffects.swift b/SKTUtils/SKTEffects.swift index a902ea8..b671658 100644 --- a/SKTUtils/SKTEffects.swift +++ b/SKTUtils/SKTEffects.swift @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Razeware LLC + * Copyright (c) 2013-2017 Razeware LLC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -39,7 +39,7 @@ public class SKTEffect { timingFunction = SKTTimingFunctionLinear } - public func update(_ t: CGFloat) { + func update(_ t: CGFloat) { // subclasses implement this } } @@ -120,7 +120,7 @@ public class SKTRotateEffect: SKTEffect { * Wrapper that allows you to use SKTEffect objects as regular SKActions. */ public extension SKAction { - public class func actionWithEffect(_ effect: SKTEffect) -> SKAction { + class func actionWithEffect(_ effect: SKTEffect) -> SKAction { return SKAction.customAction(withDuration: effect.duration) { node, elapsedTime in var t = elapsedTime / CGFloat(effect.duration) diff --git a/SKTUtils/SKTTimingFunctions.swift b/SKTUtils/SKTTimingFunctions.swift index f8238ea..e8792a8 100644 --- a/SKTUtils/SKTTimingFunctions.swift +++ b/SKTUtils/SKTTimingFunctions.swift @@ -2,7 +2,7 @@ * Timing functions for SKTEffects. Based on Robert Penner's easing equations * http://robertpenner.com/easing/ and https://github.com/warrenm/AHEasing * - * Copyright (c) 2013-2014 Razeware LLC + * Copyright (c) 2013-2017 Razeware LLC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,19 +26,19 @@ import Foundation import CoreGraphics -public func SKTTimingFunctionLinear(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionLinear(_ t: CGFloat) -> CGFloat { return t } -public func SKTTimingFunctionQuadraticEaseIn(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionQuadraticEaseIn(_ t: CGFloat) -> CGFloat { return t * t } -public func SKTTimingFunctionQuadraticEaseOut(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionQuadraticEaseOut(_ t: CGFloat) -> CGFloat { return t * (2.0 - t) } -public func SKTTimingFunctionQuadraticEaseInOut(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionQuadraticEaseInOut(_ t: CGFloat) -> CGFloat { if t < 0.5 { return 2.0 * t * t } else { @@ -56,7 +56,7 @@ func SKTTimingFunctionCubicEaseOut(_ t: CGFloat) -> CGFloat { return 1.0 + f * f * f } -public func SKTTimingFunctionCubicEaseInOut(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionCubicEaseInOut(_ t: CGFloat) -> CGFloat { if t < 0.5 { return 4.0 * t * t * t } else { @@ -65,16 +65,16 @@ public func SKTTimingFunctionCubicEaseInOut(_ t: CGFloat) -> CGFloat { } } -public func SKTTimingFunctionQuarticEaseIn(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionQuarticEaseIn(_ t: CGFloat) -> CGFloat { return t * t * t * t } -public func SKTTimingFunctionQuarticEaseOut(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionQuarticEaseOut(_ t: CGFloat) -> CGFloat { let f = t - 1.0 return 1.0 - f * f * f * f } -public func SKTTimingFunctionQuarticEaseInOut(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionQuarticEaseInOut(_ t: CGFloat) -> CGFloat { if t < 0.5 { return 8.0 * t * t * t * t } else { @@ -83,11 +83,11 @@ public func SKTTimingFunctionQuarticEaseInOut(_ t: CGFloat) -> CGFloat { } } -public func SKTTimingFunctionQuinticEaseIn(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionQuinticEaseIn(_ t: CGFloat) -> CGFloat { return t * t * t * t * t } -public func SKTTimingFunctionQuinticEaseOut(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionQuinticEaseOut(_ t: CGFloat) -> CGFloat { let f = t - 1.0 return 1.0 + f * f * f * f * f } @@ -101,27 +101,27 @@ func SKTTimingFunctionQuinticEaseInOut(_ t: CGFloat) -> CGFloat { } } -public func SKTTimingFunctionSineEaseIn(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionSineEaseIn(_ t: CGFloat) -> CGFloat { return sin((t - 1.0) * π/2) + 1.0 } -public func SKTTimingFunctionSineEaseOut(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionSineEaseOut(_ t: CGFloat) -> CGFloat { return sin(t * π/2) } -public func SKTTimingFunctionSineEaseInOut(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionSineEaseInOut(_ t: CGFloat) -> CGFloat { return 0.5 * (1.0 - cos(t * π)) } -public func SKTTimingFunctionCircularEaseIn(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionCircularEaseIn(_ t: CGFloat) -> CGFloat { return 1.0 - sqrt(1.0 - t * t) } -public func SKTTimingFunctionCircularEaseOut(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionCircularEaseOut(_ t: CGFloat) -> CGFloat { return sqrt((2.0 - t) * t) } -public func SKTTimingFunctionCircularEaseInOut(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionCircularEaseInOut(_ t: CGFloat) -> CGFloat { if t < 0.5 { return 0.5 * (1.0 - sqrt(1.0 - 4.0 * t * t)) } else { @@ -129,15 +129,15 @@ public func SKTTimingFunctionCircularEaseInOut(_ t: CGFloat) -> CGFloat { } } -public func SKTTimingFunctionExponentialEaseIn(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionExponentialEaseIn(_ t: CGFloat) -> CGFloat { return (t == 0.0) ? t : pow(2.0, 10.0 * (t - 1.0)) } -public func SKTTimingFunctionExponentialEaseOut(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionExponentialEaseOut(_ t: CGFloat) -> CGFloat { return (t == 1.0) ? t : 1.0 - pow(2.0, -10.0 * t) } -public func SKTTimingFunctionExponentialEaseInOut(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionExponentialEaseInOut(_ t: CGFloat) -> CGFloat { if t == 0.0 || t == 1.0 { return t } else if t < 0.5 { @@ -147,15 +147,15 @@ public func SKTTimingFunctionExponentialEaseInOut(_ t: CGFloat) -> CGFloat { } } -public func SKTTimingFunctionElasticEaseIn(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionElasticEaseIn(_ t: CGFloat) -> CGFloat { return sin(13.0 * π/2 * t) * pow(2.0, 10.0 * (t - 1.0)) } -public func SKTTimingFunctionElasticEaseOut(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionElasticEaseOut(_ t: CGFloat) -> CGFloat { return sin(-13.0 * π/2 * (t + 1.0)) * pow(2.0, -10.0 * t) + 1.0 } -public func SKTTimingFunctionElasticEaseInOut(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionElasticEaseInOut(_ t: CGFloat) -> CGFloat { if t < 0.5 { return 0.5 * sin(13.0 * π * t) * pow(2.0, 20.0 * t - 10.0) } else { @@ -163,18 +163,18 @@ public func SKTTimingFunctionElasticEaseInOut(_ t: CGFloat) -> CGFloat { } } -public func SKTTimingFunctionBackEaseIn(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionBackEaseIn(_ t: CGFloat) -> CGFloat { let s: CGFloat = 1.70158 return ((s + 1.0) * t - s) * t * t } -public func SKTTimingFunctionBackEaseOut(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionBackEaseOut(_ t: CGFloat) -> CGFloat { let s: CGFloat = 1.70158 let f = 1.0 - t return 1.0 - ((s + 1.0) * f - s) * f * f } -public func SKTTimingFunctionBackEaseInOut(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionBackEaseInOut(_ t: CGFloat) -> CGFloat { let s: CGFloat = 1.70158 if t < 0.5 { let f = 2.0 * t @@ -185,16 +185,16 @@ public func SKTTimingFunctionBackEaseInOut(_ t: CGFloat) -> CGFloat { } } -public func SKTTimingFunctionExtremeBackEaseIn(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionExtremeBackEaseIn(_ t: CGFloat) -> CGFloat { return (t * t - sin(t * π)) * t } -public func SKTTimingFunctionExtremeBackEaseOut(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionExtremeBackEaseOut(_ t: CGFloat) -> CGFloat { let f = 1.0 - t return 1.0 - (f * f - sin(f * π)) * f } -public func SKTTimingFunctionExtremeBackEaseInOut(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionExtremeBackEaseInOut(_ t: CGFloat) -> CGFloat { if t < 0.5 { let f = 2.0 * t return 0.5 * (f * f - sin(f * π)) * f @@ -204,11 +204,11 @@ public func SKTTimingFunctionExtremeBackEaseInOut(_ t: CGFloat) -> CGFloat { } } -public func SKTTimingFunctionBounceEaseIn(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionBounceEaseIn(_ t: CGFloat) -> CGFloat { return 1.0 - SKTTimingFunctionBounceEaseOut(1.0 - t) } -public func SKTTimingFunctionBounceEaseOut(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionBounceEaseOut(_ t: CGFloat) -> CGFloat { if t < 1.0 / 2.75 { return 7.5625 * t * t } else if t < 2.0 / 2.75 { @@ -223,7 +223,7 @@ public func SKTTimingFunctionBounceEaseOut(_ t: CGFloat) -> CGFloat { } } -public func SKTTimingFunctionBounceEaseInOut(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionBounceEaseInOut(_ t: CGFloat) -> CGFloat { if t < 0.5 { return 0.5 * SKTTimingFunctionBounceEaseIn(t * 2.0) } else { @@ -231,10 +231,10 @@ public func SKTTimingFunctionBounceEaseInOut(_ t: CGFloat) -> CGFloat { } } -public func SKTTimingFunctionSmoothstep(_ t: CGFloat) -> CGFloat { +func SKTTimingFunctionSmoothstep(_ t: CGFloat) -> CGFloat { return t * t * (3 - 2 * t) } -public func SKTCreateShakeFunction(_ oscillations: Int) -> (CGFloat) -> CGFloat { +func SKTCreateShakeFunction(_ oscillations: Int) -> (CGFloat) -> CGFloat { return {t in -pow(2.0, -10.0 * t) * sin(t * π * CGFloat(oscillations) * 2.0) + 1.0} } diff --git a/SKTUtils/Vector3.swift b/SKTUtils/Vector3.swift index d13d6dc..9bfd444 100644 --- a/SKTUtils/Vector3.swift +++ b/SKTUtils/Vector3.swift @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Razeware LLC + * Copyright (c) 2013-2017 Razeware LLC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -61,21 +61,21 @@ extension Vector3 { * * DEPRECATED: Use the == operator instead. */ - public func equalToScalar(_ value: CGFloat) -> Bool { + func equalToScalar(_ value: CGFloat) -> Bool { return x == value && y == value && z == value } /** * Returns the magnitude of the vector. */ - public func length() -> CGFloat { + func length() -> CGFloat { return sqrt(x*x + y*y + z*z) } /** * Normalizes the vector and returns the result as a new vector. */ - public func normalized() -> Vector3 { + func normalized() -> Vector3 { let scale = 1.0/length() return Vector3(x: x * scale, y: y * scale, z: z * scale) } @@ -83,7 +83,7 @@ extension Vector3 { /** * Normalizes the vector described by this Vector3 object. */ - public mutating func normalize() { + mutating func normalize() { let scale = 1.0/length() x *= scale y *= scale @@ -93,14 +93,14 @@ extension Vector3 { /** * Calculates the dot product with another Vector3. */ - public func dot(_ vector: Vector3) -> CGFloat { + func dot(_ vector: Vector3) -> CGFloat { return Vector3.dotProduct(self, right: vector) } /** * Calculates the cross product with another Vector3. */ - public func cross(_ vector: Vector3) -> Vector3 { + func cross(_ vector: Vector3) -> Vector3 { return Vector3.crossProduct(self, right: vector) } @@ -109,7 +109,7 @@ extension Vector3 { * * DEPRECATED: Use dot() instead. */ - public static func dotProduct(_ left: Vector3, right: Vector3) -> CGFloat { + static func dotProduct(_ left: Vector3, right: Vector3) -> CGFloat { return left.x * right.x + left.y * right.y + left.z * right.z } @@ -118,7 +118,7 @@ extension Vector3 { * * DEPRECATED: Use cross() instead. */ - public static func crossProduct(_ left: Vector3, right: Vector3) -> Vector3 { + static func crossProduct(_ left: Vector3, right: Vector3) -> Vector3 { let crossProduct = Vector3(x: left.y * right.z - left.z * right.y, y: left.z * right.x - left.x * right.z, z: left.x * right.y - left.y * right.x) @@ -129,42 +129,42 @@ extension Vector3 { /** * Adds two Vector3 values and returns the result as a new Vector3. */ -public func + (left: Vector3, right: Vector3) -> Vector3 { +func + (left: Vector3, right: Vector3) -> Vector3 { return Vector3(x: left.x + right.x, y: left.y + right.y, z: left.z + right.z) } /** * Increments a Vector3 with the value of another. */ -public func += (left: inout Vector3, right: Vector3) { +func += (left: inout Vector3, right: Vector3) { left = left + right } /** * Subtracts two Vector3 values and returns the result as a new Vector3. */ -public func - (left: Vector3, right: Vector3) -> Vector3 { +func - (left: Vector3, right: Vector3) -> Vector3 { return Vector3(x: left.x - right.x, y: left.y - right.y, z: left.z - right.z) } /** * Decrements a Vector3 with the value of another. */ -public func -= (left: inout Vector3, right: Vector3) { +func -= (left: inout Vector3, right: Vector3) { left = left - right } /** * Multiplies two Vector3 values and returns the result as a new Vector3. */ -public func * (left: Vector3, right: Vector3) -> Vector3 { +func * (left: Vector3, right: Vector3) -> Vector3 { return Vector3(x: left.x * right.x, y: left.y * right.y, z: left.z * right.z) } /** * Multiplies a Vector3 with another. */ -public func *= (left: inout Vector3, right: Vector3) { +func *= (left: inout Vector3, right: Vector3) { left = left * right } @@ -172,28 +172,28 @@ public func *= (left: inout Vector3, right: Vector3) { * Multiplies the x,y,z fields of a Vector3 with the same scalar value and * returns the result as a new Vector3. */ -public func * (vector: Vector3, scalar: CGFloat) -> Vector3 { +func * (vector: Vector3, scalar: CGFloat) -> Vector3 { return Vector3(x: vector.x * scalar, y: vector.y * scalar, z: vector.z * scalar) } /** * Multiplies the x,y,z fields of a Vector3 with the same scalar value. */ -public func *= (vector: inout Vector3, scalar: CGFloat) { +func *= (vector: inout Vector3, scalar: CGFloat) { vector = vector * scalar } /** * Divides two Vector3 values and returns the result as a new Vector3. */ -public func / (left: Vector3, right: Vector3) -> Vector3 { +func / (left: Vector3, right: Vector3) -> Vector3 { return Vector3(x: left.x / right.x, y: left.y / right.y, z: left.z / right.z) } /** * Divides a Vector3 by another. */ -public func /= (left: inout Vector3, right: Vector3) { +func /= (left: inout Vector3, right: Vector3) { left = left / right } @@ -201,20 +201,20 @@ public func /= (left: inout Vector3, right: Vector3) { * Divides the x,y,z fields of a Vector3 by the same scalar value and * returns the result as a new Vector3. */ -public func / (vector: Vector3, scalar: CGFloat) -> Vector3 { +func / (vector: Vector3, scalar: CGFloat) -> Vector3 { return Vector3(x: vector.x / scalar, y: vector.y / scalar, z: vector.z / scalar) } /** * Divides the x,y,z fields of a Vector3 by the same scalar value. */ -public func /= (vector: inout Vector3, scalar: CGFloat) { +func /= (vector: inout Vector3, scalar: CGFloat) { vector = vector / scalar } /** * Performs a linear interpolation between two Vector3 values. */ -public func lerp(start: Vector3, end: Vector3, t: CGFloat) -> Vector3 { +func lerp(start: Vector3, end: Vector3, t: CGFloat) -> Vector3 { return start + (end - start) * t }