Skip to content

Commit

Permalink
add compiler directive to allow tests to succeed when not building wi…
Browse files Browse the repository at this point in the history
…th SPM

- image path resolution for collections tilesets improved
- macOS requirement is now 11.0
- change protocol constraints from `class` to `AnyObject`
  • Loading branch information
mfessenden committed Sep 21, 2021
1 parent eb0a477 commit 69e520c
Show file tree
Hide file tree
Showing 21 changed files with 59 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Change Log

- add **Swift Package Manager** support
- add target for building binary framework
- macOS requirement is now 11.0

#### Breaking

Expand Down
4 changes: 2 additions & 2 deletions Docs/Documentation/Getting Started.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

- iOS 12
- tvOS 12
- macOS 10.12
- macOS 11
- Xcode 11/Swift 5


Expand All @@ -36,7 +36,7 @@ The **SKTiled** project contains six targets; three are demo applications for iO

### Framework Installation

To use the frameworks, build the appropriate framework target and add to your project. Make sure the **Minimum Deployment Target** is set correctly for your project (iOS11+/macOS 10.12+/tvOS12+).
To use the frameworks, build the appropriate framework target and add to your project. Make sure the **Minimum Deployment Target** is set correctly for your project (iOS11+/macOS 11+/tvOS12+).

![adding framework](images/framework.png)

Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ let package = Package(
.copy("Assets/monsters-16x16.png"),
.copy("Assets/monsters-16x16.tsx"),
.copy("Assets/portraits-8x8.png"),
.copy("Assets/portraits-8x8.tsx")
.copy("Assets/portraits-8x8.tsx"),
]
)
]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Check out the [**Official Documentation**][sktiled-12-doc-url].

- iOS 12
- tvOS 12
- macOS 10.12
- macOS 11
- Xcode 11/Swift 5

## Installation
Expand Down
6 changes: 3 additions & 3 deletions SKTiled.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ Pod::Spec.new do |s|
s.version = "1.23"
s.summary = "SKTiled is a framework for using Tiled content with Apple's SpriteKit."
s.description = <<-DESC
SKTiled is a framework for using Tiled content with Apple's SpriteKit, allowing the creation of game assets from .tmx files.
SKTiled is a framework for using Tiled content with Apple's SpriteKit, allowing the creation of game assets from Tiled .tmx files.
DESC
s.author = { "Michael Fessenden" => "[email protected]" }
s.homepage = "https://github.com/mfessenden/SKTiled"
s.license = { :type => 'MIT', :file => 'LICENSE.md' }

s.osx.deployment_target = '10.12'
s.osx.deployment_target = '11.0'
s.ios.deployment_target = '12.0'
s.tvos.deployment_target = '12.0'
s.source = { :git => "https://github.com/mfessenden/SKTiled.git", :tag => s.version }

s.source_files = 'Sources/*.swift'
s.requires_arc = true

s.swift_versions = [5, 5.2, 5.3]
s.swift_versions = [5, 5.2, 5.3, 5.4, 5.5]

end
16 changes: 3 additions & 13 deletions SKTiled.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,6 @@
4CA6A7FD21875FD9002BC924 /* TilemapTests.swift */,
4CA6A8032188C9A0002BC924 /* TilesetTests.swift */,
4C1D689021932E6200D2D042 /* QueryTests.swift */,
4CA6A8072188CD93002BC924 /* Tests+Extensions.swift */,
);
path = Tests;
sourceTree = "<group>";
Expand Down Expand Up @@ -1203,6 +1202,7 @@
4CF1D2692555E57900A6CC25 /* Supporting Files */ = {
isa = PBXGroup;
children = (
4CA6A8072188CD93002BC924 /* Tests+Extensions.swift */,
4CF1D2372555E39300A6CC25 /* TestMapDelegate.swift */,
4CF1D2382555E39300A6CC25 /* TestTilesetDelegate.swift */,
);
Expand Down Expand Up @@ -2426,7 +2426,6 @@
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 12.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down Expand Up @@ -2458,7 +2457,6 @@
SDKROOT = appletvos;
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 12.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down Expand Up @@ -2489,7 +2487,6 @@
SDKROOT = appletvos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 12.0;
};
name = Debug;
};
Expand Down Expand Up @@ -2517,7 +2514,6 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = appletvos;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 12.0;
};
name = Release;
};
Expand Down Expand Up @@ -2681,7 +2677,6 @@
DEBUG_INFORMATION_FORMAT = dwarf;
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = "Tests/Info-iOS.plist";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
Expand All @@ -2704,7 +2699,6 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = "Tests/Info-iOS.plist";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MTL_FAST_MATH = YES;
PRODUCT_NAME = SKTiledTests;
Expand All @@ -2731,7 +2725,6 @@
SDKROOT = appletvos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 12.0;
};
name = Debug;
};
Expand All @@ -2753,7 +2746,6 @@
PRODUCT_NAME = SKTiledTests;
SDKROOT = appletvos;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 12.0;
};
name = Release;
};
Expand All @@ -2771,7 +2763,6 @@
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = "Tests/Info-macOS.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_NAME = SKTiledTests;
Expand All @@ -2795,7 +2786,6 @@
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = "Tests/Info-macOS.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_FAST_MATH = YES;
PRODUCT_NAME = SKTiledTests;
SDKROOT = macosx;
Expand Down Expand Up @@ -2850,7 +2840,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MACOSX_DEPLOYMENT_TARGET = 10.12;
MACOSX_DEPLOYMENT_TARGET = 11.3;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = "-lz";
Expand Down Expand Up @@ -2904,7 +2894,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MACOSX_DEPLOYMENT_TARGET = 10.12;
MACOSX_DEPLOYMENT_TARGET = 11.3;
MTL_ENABLE_DEBUG_INFO = NO;
OTHER_LDFLAGS = "-lz";
OTHER_SWIFT_FLAGS = "-DRENDER_STATS";
Expand Down
2 changes: 1 addition & 1 deletion Sources/SKTiled+Debug.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ extension SKTiledDebugDrawNode: Loggable {}


/// :nodoc:
protocol CustomDebugReflectable: class {
protocol CustomDebugReflectable: AnyObject {
func dumpStatistics()
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/SKTiledObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import SpriteKit

[sktiledobject-url]:Protocols/SKTiledObject.html
*/
@objc public protocol SKTiledObject: class {
@objc public protocol SKTiledObject: AnyObject {
/// Unique object id (layer & object names may not be unique).
var uuid: String { get set }

Expand Down
24 changes: 12 additions & 12 deletions Sources/SKTileset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -461,28 +461,28 @@ public class SKTileset: NSObject, SKTiledObject {
log("tile data exists at id: \(tileID)", level: .error)
return nil
}

isImageCollection = true

let inputURL = URL(fileURLWithPath: source)
let filename = inputURL.deletingPathExtension().lastPathComponent
let fileExtension = inputURL.pathExtension

guard let urlPath = Bundle.main.url(forResource: filename, withExtension: fileExtension) else {
// standardize the url
let inputURL = URL(fileURLWithPath: source).standardized

// check to see if
guard let imageDataProvider = CGDataProvider(url: inputURL as CFURL) else {
log("invalid image source '\(inputURL.path)'.", level: .error)
return nil
}

// read image from file
let imageDataProvider = CGDataProvider(url: urlPath as CFURL)!


// create a data provider
let image = CGImage(pngDataProviderSource: imageDataProvider, decode: nil, shouldInterpolate: false, intent: .defaultIntent)!
let sourceTexture = SKTexture(cgImage: image)
sourceTexture.filteringMode = .nearest


// create the tile data and set the source size here (as tileset size won't be accurate)
let data = SKTilesetData(id: tileID, texture: sourceTexture, tileSet: self)
data.sourceSize = sourceTexture.size()
data.ignoreProperties = ignoreProperties

// add the image name to the source attribute
data.source = source
self.tileData.insert(data)
Expand Down
3 changes: 3 additions & 0 deletions Sources/SKTilesetData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public class SKTilesetData: SKTiledObject {

/// Source image name (collections tileset)
public var source: String! = nil

/// Source image size (collections tileset)
public var sourceSize: CGSize?

/// Tile occurance probability (parsed from Tiled, not currently used).

Expand Down
2 changes: 1 addition & 1 deletion Sources/TiledSceneCameraDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import SpriteKit
[tiled-scene-camera-delegate-image]:https://mfessenden.github.io/SKTiled/images/camera-delegate.svg

*/
@objc public protocol SKTiledSceneCameraDelegate: class {
@objc public protocol SKTiledSceneCameraDelegate: AnyObject {

/**
Allow delegate to receive updates from camera.
Expand Down
2 changes: 1 addition & 1 deletion Sources/TiledSceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import GameplayKit
[skscene-url]:https://developer.apple.com/reference/spritekit/skscene
[sktiledscenedelegate-image-url]:https://mfessenden.github.io/SKTiled/images/scene-hierarchy.svg
*/
public protocol SKTiledSceneDelegate: class {
public protocol SKTiledSceneDelegate: AnyObject {

/// Root container node. Tiled assets are parented to this node.
var worldNode: SKNode! { get set }
Expand Down
2 changes: 1 addition & 1 deletion Sources/TilemapDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import GameplayKit
}
```
*/
public protocol SKTilemapDelegate: class {
public protocol SKTilemapDelegate: AnyObject {
var zDeltaForLayers: CGFloat { get }
func didBeginParsing(_ tilemap: SKTilemap)
func didAddTileset(_ tileset: SKTileset)
Expand Down
2 changes: 1 addition & 1 deletion Sources/TilesetDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import SpriteKit
}
```
*/
public protocol SKTilesetDataSource: class {
public protocol SKTilesetDataSource: AnyObject {

/**
Provide an image name for the tileset before textures are generated.
Expand Down
5 changes: 3 additions & 2 deletions Tests/ColorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,13 @@ class ColorTests: XCTestCase {
let firstTextColorHexValue = firstTestColor.hexString()

// second value (4 characters)
let secondShortHexString = "#854"
let secondExpectedHexValue = "#885544"
let secondShortHexString = "#5ba"
let secondExpectedHexValue = "#55bbaa"
let secondTestColor = SKColor(hexString: secondShortHexString)
let secondTextColorHexValue = secondTestColor.hexString()

XCTAssertEqual(firstTextColorHexValue, firstExpectedHexValue, "❗️ incorrect hex to color conversion, `\(firstShortHexString)` does not equal `\(firstExpectedHexValue)`")
XCTAssertEqual(secondTextColorHexValue, secondExpectedHexValue, "❗️ incorrect hex to color conversion, `\(secondShortHexString)` does not equal `\(secondExpectedHexValue)`")
}
}

4 changes: 4 additions & 0 deletions Tests/CoordinateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ class CoordinateTests: XCTestCase {

if (testBundle == nil) {
TiledGlobals.default.loggingLevel = .none
#if SWIFT_PACKAGE
testBundle = Bundle.module
#else
testBundle = Bundle(for: type(of: self))
#endif
}

if (tilemap == nil) {
Expand Down
5 changes: 4 additions & 1 deletion Tests/ParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ class ParserTests: XCTestCase {
super.setUp()

if (testBundle == nil) {
#if SWIFT_PACKAGE
testBundle = Bundle.module
#else
testBundle = Bundle(for: type(of: self))
#endif
}

if (tilemap == nil) {
print("➜ loading test tilemap: \"\(tilemapName)\"...")

let mapurl = testBundle!.url(forResource: tilemapName, withExtension: "tmx")!
tilemap = SKTilemap.load(tmxFile: mapurl.path, delegate: tilemapDelegate,
tilesetDataSource: tilesetDelegate, loggingLevel: .none)
Expand Down
4 changes: 4 additions & 0 deletions Tests/PropertiesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ class PropertiesTests: XCTestCase {

if (testBundle == nil) {
TiledGlobals.default.loggingLevel = .none
#if SWIFT_PACKAGE
testBundle = Bundle.module
#else
testBundle = Bundle(for: type(of: self))
#endif
}

if (tilemap == nil) {
Expand Down
4 changes: 4 additions & 0 deletions Tests/QueryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ class QueryTests: XCTestCase {

if (testBundle == nil) {
TiledGlobals.default.loggingLevel = .none
#if SWIFT_PACKAGE
testBundle = Bundle.module
#else
testBundle = Bundle(for: type(of: self))
#endif
}

if (tilemap == nil) {
Expand Down
4 changes: 4 additions & 0 deletions Tests/TilemapTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ class TilemapTests: XCTestCase {

if (testBundle == nil) {
TiledGlobals.default.loggingLevel = .none
#if SWIFT_PACKAGE
testBundle = Bundle.module
#else
testBundle = Bundle(for: type(of: self))
#endif
}

if (tilemap == nil) {
Expand Down
4 changes: 4 additions & 0 deletions Tests/TilesetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ class TilesetTests: XCTestCase {

if (testBundle == nil) {
TiledGlobals.default.loggingLevel = .none
#if SWIFT_PACKAGE
testBundle = Bundle.module
#else
testBundle = Bundle(for: type(of: self))
#endif
}

if (tilemap == nil) {
Expand Down

0 comments on commit 69e520c

Please sign in to comment.