diff --git a/Common/Database/DatabaseManager.swift b/Common/Database/DatabaseManager.swift index a76febb..7696c89 100644 --- a/Common/Database/DatabaseManager.swift +++ b/Common/Database/DatabaseManager.swift @@ -138,13 +138,29 @@ extension DatabaseManager return saveStatesDirectoryURL } - class func saveStatesDirectoryURLForGame(_ game: Game) -> URL + class func saveStatesDirectoryURL(for game: Game) -> URL { let gameDirectoryURL = DatabaseManager.saveStatesDirectoryURL.appendingPathComponent(game.identifier) self.createDirectory(at: gameDirectoryURL) return gameDirectoryURL } + + class var controllerSkinsDirectoryURL: URL + { + let controllerSkinsDirectoryURL = DatabaseManager.defaultDirectoryURL().appendingPathComponent("Controller Skins") + self.createDirectory(at: controllerSkinsDirectoryURL) + + return controllerSkinsDirectoryURL + } + + class func controllerSkinsDirectoryURL(for gameType: GameType) -> URL + { + let gameTypeDirectoryURL = DatabaseManager.controllerSkinsDirectoryURL.appendingPathComponent(gameType.rawValue) + self.createDirectory(at: gameTypeDirectoryURL) + + return gameTypeDirectoryURL + } } //MARK: - Private - diff --git a/Common/Database/Model/ControllerSkin.swift b/Common/Database/Model/ControllerSkin.swift new file mode 100644 index 0000000..344cd61 --- /dev/null +++ b/Common/Database/Model/ControllerSkin.swift @@ -0,0 +1,59 @@ +// +// ControllerSkin.swift +// Delta +// +// Created by Riley Testut on 8/30/16. +// Copyright (c) 2016 Riley Testut. All rights reserved. +// + +import Foundation + +import DeltaCore + +@objc(ControllerSkin) +public class ControllerSkin: _ControllerSkin +{ + public var fileURL: URL { + let fileURL = DatabaseManager.controllerSkinsDirectoryURL(for: self.gameType).appendingPathComponent(self.filename) + return fileURL + } + + public var isDebugModeEnabled: Bool { + return self.controllerSkin?.isDebugModeEnabled ?? false + } + + fileprivate lazy var controllerSkin: DeltaCore.ControllerSkin? = DeltaCore.ControllerSkin(fileURL: self.fileURL) +} + +extension ControllerSkin: ControllerSkinProtocol +{ + public func supports(_ traits: DeltaCore.ControllerSkin.Traits) -> Bool + { + return self.controllerSkin?.supports(traits) ?? false + } + + public func image(for traits: DeltaCore.ControllerSkin.Traits, preferredSize: DeltaCore.ControllerSkin.Size) -> UIImage? + { + return self.controllerSkin?.image(for: traits, preferredSize: preferredSize) + } + + public func inputs(for traits: DeltaCore.ControllerSkin.Traits, point: CGPoint) -> [Input]? + { + return self.controllerSkin?.inputs(for: traits, point: point) + } + + public func items(for traits: DeltaCore.ControllerSkin.Traits) -> [DeltaCore.ControllerSkin.Item]? + { + return self.controllerSkin?.items(for: traits) + } + + public func isTranslucent(for traits: DeltaCore.ControllerSkin.Traits) -> Bool? + { + return self.controllerSkin?.isTranslucent(for: traits) + } + + public func gameScreenFrame(for traits: DeltaCore.ControllerSkin.Traits) -> CGRect? + { + return self.controllerSkin?.gameScreenFrame(for: traits) + } +} diff --git a/Common/Database/Model/Delta.xcdatamodeld/Model.xcdatamodel/contents b/Common/Database/Model/Delta.xcdatamodeld/Model.xcdatamodel/contents index a99d8d5..29601f8 100644 --- a/Common/Database/Model/Delta.xcdatamodeld/Model.xcdatamodel/contents +++ b/Common/Database/Model/Delta.xcdatamodeld/Model.xcdatamodel/contents @@ -19,6 +19,22 @@ + + + + + + + + + + + + + + + + @@ -82,6 +98,7 @@ + diff --git a/Common/Database/Model/SaveState.swift b/Common/Database/Model/SaveState.swift index c9a4a00..410ceee 100644 --- a/Common/Database/Model/SaveState.swift +++ b/Common/Database/Model/SaveState.swift @@ -21,13 +21,13 @@ import DeltaCore public class SaveState: _SaveState, SaveStateProtocol { public var fileURL: URL { - let fileURL = DatabaseManager.saveStatesDirectoryURLForGame(self.game!).appendingPathComponent(self.filename) + let fileURL = DatabaseManager.saveStatesDirectoryURL(for: self.game!).appendingPathComponent(self.filename) return fileURL } public var imageFileURL: URL { let imageFilename = (self.filename as NSString).deletingPathExtension + ".png" - let imageFileURL = DatabaseManager.saveStatesDirectoryURLForGame(self.game!).appendingPathComponent(imageFilename) + let imageFileURL = DatabaseManager.saveStatesDirectoryURL(for: self.game!).appendingPathComponent(imageFilename) return imageFileURL } diff --git a/Common/Database/Model/_ControllerSkin.swift b/Common/Database/Model/_ControllerSkin.swift new file mode 100644 index 0000000..be93661 --- /dev/null +++ b/Common/Database/Model/_ControllerSkin.swift @@ -0,0 +1,28 @@ +// DO NOT EDIT. This file is machine-generated and constantly overwritten. +// Make changes to ControllerSkin.swift instead. + +import Foundation +import CoreData + +import DeltaCore + +public class _ControllerSkin: NSManagedObject +{ + @nonobjc public class func fetchRequest() -> NSFetchRequest { + return NSFetchRequest(entityName: "ControllerSkin") + } + + // MARK: - Properties + + @NSManaged public var filename: String + + @NSManaged public var gameType: GameType + + @NSManaged public var identifier: String + + @NSManaged public var name: String + + // MARK: - Relationships + +} + diff --git a/Cores/DeltaCore b/Cores/DeltaCore index 040f323..6558b6e 160000 --- a/Cores/DeltaCore +++ b/Cores/DeltaCore @@ -1 +1 @@ -Subproject commit 040f323f314ab60e85d7d5e40633ec30668ff874 +Subproject commit 6558b6e5198ef9ae20e5ba9e68e4389fb210b66f diff --git a/Delta.xcodeproj/project.pbxproj b/Delta.xcodeproj/project.pbxproj index 9b70b98..be9e2e7 100644 --- a/Delta.xcodeproj/project.pbxproj +++ b/Delta.xcodeproj/project.pbxproj @@ -58,6 +58,8 @@ BFA2315C1CED10BE0011E35A /* Action.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFA2315B1CED10BE0011E35A /* Action.swift */; }; BFAA1FED1B8AA4FA00495943 /* Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFAA1FEC1B8AA4FA00495943 /* Settings.swift */; }; BFBAA86A1D5A483900A29C1B /* DatabaseManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBAA8691D5A483900A29C1B /* DatabaseManager.swift */; }; + BFC853351DB039AD00E8C372 /* _ControllerSkin.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFC853341DB039AD00E8C372 /* _ControllerSkin.swift */; }; + BFC853371DB039B500E8C372 /* ControllerSkin.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFC853361DB039B500E8C372 /* ControllerSkin.swift */; }; BFC9B7391CEFCD34008629BB /* CheatsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFC9B7381CEFCD34008629BB /* CheatsViewController.swift */; }; BFCEA67E1D56FF640061A534 /* UIViewControllerContextTransitioning+Conveniences.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFCEA67D1D56FF640061A534 /* UIViewControllerContextTransitioning+Conveniences.swift */; }; BFD097211D3A01B8005A44C2 /* SaveStatesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF3540041C5DA70400C1184C /* SaveStatesViewController.swift */; }; @@ -155,6 +157,8 @@ BFAA1FEC1B8AA4FA00495943 /* Settings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Settings.swift; sourceTree = ""; }; BFBAA8691D5A483900A29C1B /* DatabaseManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseManager.swift; sourceTree = ""; }; BFC134E01AAD82460087AD7B /* SNESDeltaCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SNESDeltaCore.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + BFC853341DB039AD00E8C372 /* _ControllerSkin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = _ControllerSkin.swift; sourceTree = ""; }; + BFC853361DB039B500E8C372 /* ControllerSkin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ControllerSkin.swift; sourceTree = ""; }; BFC9B7381CEFCD34008629BB /* CheatsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CheatsViewController.swift; path = "Pause Menu/Cheats/CheatsViewController.swift"; sourceTree = ""; }; BFCEA67D1D56FF640061A534 /* UIViewControllerContextTransitioning+Conveniences.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewControllerContextTransitioning+Conveniences.swift"; sourceTree = ""; }; BFDB28441BC9DA7B001D0C83 /* GamePickerController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GamePickerController.swift; sourceTree = ""; }; @@ -233,6 +237,7 @@ isa = PBXGroup; children = ( BF2898111DAAFC2A0023D8E9 /* Cheat.swift */, + BFC853361DB039B500E8C372 /* ControllerSkin.swift */, BF2898121DAAFC2A0023D8E9 /* Game.swift */, BF2898131DAAFC2A0023D8E9 /* GameCollection.swift */, BF2898141DAAFC2A0023D8E9 /* SaveState.swift */, @@ -244,6 +249,7 @@ isa = PBXGroup; children = ( BF2898191DAAFC330023D8E9 /* _Cheat.swift */, + BFC853341DB039AD00E8C372 /* _ControllerSkin.swift */, BF28981A1DAAFC330023D8E9 /* _Game.swift */, BF28981B1DAAFC330023D8E9 /* _GameCollection.swift */, BF28981C1DAAFC330023D8E9 /* _SaveState.swift */, @@ -689,6 +695,8 @@ BF107EC41BF413F000E0C32C /* GamesViewController.swift in Sources */, BF2898181DAAFC2A0023D8E9 /* SaveState.swift in Sources */, BF172AEB1C68986300C26774 /* NSManagedObjectContext+Conveniences.swift in Sources */, + BFC853351DB039AD00E8C372 /* _ControllerSkin.swift in Sources */, + BFC853371DB039B500E8C372 /* ControllerSkin.swift in Sources */, BF13A7561D5D29B0000BB055 /* PreviewGameViewController.swift in Sources */, BFDD04EF1D5E27DB002D450E /* NSFetchedResultsController+Conveniences.m in Sources */, BFCEA67E1D56FF640061A534 /* UIViewControllerContextTransitioning+Conveniences.swift in Sources */, diff --git a/Delta/Settings/Controller Skins/GameTypeControllerSkinsViewController.swift b/Delta/Settings/Controller Skins/GameTypeControllerSkinsViewController.swift index acbba6d..4ca3a91 100644 --- a/Delta/Settings/Controller Skins/GameTypeControllerSkinsViewController.swift +++ b/Delta/Settings/Controller Skins/GameTypeControllerSkinsViewController.swift @@ -76,12 +76,12 @@ private extension GameTypeControllerSkinsViewController { func updateControllerSkins() { - let controllerSkin = ControllerSkin.standardControllerSkin(for: self.gameType) + let controllerSkin = DeltaCore.ControllerSkin.standardControllerSkin(for: self.gameType) - let portraitTraits = ControllerSkin.Traits(deviceType: .iphone, displayMode: ControllerSkin.DisplayMode.fullScreen, orientation: .portrait) + let portraitTraits = DeltaCore.ControllerSkin.Traits(deviceType: .iphone, displayMode: DeltaCore.ControllerSkin.DisplayMode.fullScreen, orientation: .portrait) self.portraitImageView.image = controllerSkin?.image(for: portraitTraits, preferredSize: UIScreen.main.defaultControllerSkinSize) - let landscapeTraits = ControllerSkin.Traits(deviceType: .iphone, displayMode: ControllerSkin.DisplayMode.fullScreen, orientation: .landscape) + let landscapeTraits = DeltaCore.ControllerSkin.Traits(deviceType: .iphone, displayMode: DeltaCore.ControllerSkin.DisplayMode.fullScreen, orientation: .landscape) self.landscapeImageView.image = controllerSkin?.image(for: landscapeTraits, preferredSize: UIScreen.main.defaultControllerSkinSize) } }