From dc9cb367de94c904a2ae807761ac0df7ad3d464b Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Mon, 7 Nov 2016 14:29:18 -0800 Subject: [PATCH] Adds supportConfigurations property to ControllerSkin model Allows database querying of controller skins based on configurations they support --- Common/Database/DatabaseManager.swift | 13 +--- Common/Database/Model/ControllerSkin.swift | 39 ++++++++++ .../Model.xcdatamodel/contents | 9 ++- .../Model/Misc/ControllerSkinConfigurations.h | 21 +++++ Common/Database/Model/_ControllerSkin.swift | 2 + Delta.xcodeproj/project.pbxproj | 14 ++++ .../ControllerSkin+Configuring.swift | 76 +++++++++++++++++++ .../Supporting Files/Delta-Bridging-Header.h | 1 + 8 files changed, 164 insertions(+), 11 deletions(-) create mode 100644 Common/Database/Model/Misc/ControllerSkinConfigurations.h create mode 100644 Delta/Extensions/ControllerSkin+Configuring.swift diff --git a/Common/Database/DatabaseManager.swift b/Common/Database/DatabaseManager.swift index 7c06484..f4e6bf4 100644 --- a/Common/Database/DatabaseManager.swift +++ b/Common/Database/DatabaseManager.swift @@ -65,9 +65,8 @@ private extension DatabaseManager let controllerSkin = ControllerSkin(context: context) controllerSkin.isStandard = true controllerSkin.filename = deltaControllerSkin.fileURL.lastPathComponent - controllerSkin.name = deltaControllerSkin.name - controllerSkin.identifier = deltaControllerSkin.identifier - controllerSkin.gameType = deltaControllerSkin.gameType + + controllerSkin.configure(with: deltaControllerSkin) } do @@ -100,14 +99,10 @@ extension DatabaseManager guard let deltaControllerSkin = DeltaCore.ControllerSkin(fileURL: url) else { continue } let controllerSkin = ControllerSkin(context: context) - - // Manually copy values to be stored in database. - // Remaining ControllerSkinProtocol requirements will be provided by the ControllerSkin's private DeltaCore.ControllerSkin instance. controllerSkin.filename = deltaControllerSkin.identifier + ".deltaskin" - controllerSkin.name = deltaControllerSkin.name - controllerSkin.identifier = deltaControllerSkin.identifier - controllerSkin.gameType = deltaControllerSkin.gameType + controllerSkin.configure(with: deltaControllerSkin) + do { if FileManager.default.fileExists(atPath: controllerSkin.fileURL.path) diff --git a/Common/Database/Model/ControllerSkin.swift b/Common/Database/Model/ControllerSkin.swift index 2314d23..f90a773 100644 --- a/Common/Database/Model/ControllerSkin.swift +++ b/Common/Database/Model/ControllerSkin.swift @@ -10,6 +10,45 @@ import Foundation import DeltaCore +extension ControllerSkinConfigurations +{ + init(traits: DeltaCore.ControllerSkin.Traits) + { + switch traits.deviceType + { + case .iphone: + + switch traits.orientation + { + case .portrait: self = .fullScreenPortrait + case .landscape: self = .fullScreenLandscape + } + + case .ipad: + + switch traits.displayMode + { + case .fullScreen: + + switch traits.orientation + { + case .portrait: self = .fullScreenPortrait + case .landscape: self = .fullScreenLandscape + } + + case .splitView: + + switch traits.orientation + { + case .portrait: self = .splitViewPortrait + case .landscape: self = .splitViewLandscape + } + } + + } + } +} + @objc(ControllerSkin) public class ControllerSkin: _ControllerSkin { diff --git a/Common/Database/Model/Delta.xcdatamodeld/Model.xcdatamodel/contents b/Common/Database/Model/Delta.xcdatamodeld/Model.xcdatamodel/contents index 66f6b6a..62b6475 100644 --- a/Common/Database/Model/Delta.xcdatamodeld/Model.xcdatamodel/contents +++ b/Common/Database/Model/Delta.xcdatamodeld/Model.xcdatamodel/contents @@ -1,5 +1,5 @@ - + @@ -29,6 +29,11 @@ + + + + + @@ -99,7 +104,7 @@ - + diff --git a/Common/Database/Model/Misc/ControllerSkinConfigurations.h b/Common/Database/Model/Misc/ControllerSkinConfigurations.h new file mode 100644 index 0000000..b9fed34 --- /dev/null +++ b/Common/Database/Model/Misc/ControllerSkinConfigurations.h @@ -0,0 +1,21 @@ +// +// ControllerSkinConfigurations.h +// Delta +// +// Created by Riley Testut on 11/1/16. +// Copyright © 2016 Riley Testut. All rights reserved. +// + +#ifndef ControllerSkinConfigurations_h +#define ControllerSkinConfigurations_h + +typedef NS_OPTIONS(int16_t, ControllerSkinConfigurations) +{ + ControllerSkinConfigurationFullScreenPortrait = 1 << 0, + ControllerSkinConfigurationFullScreenLandscape = 1 << 1, + + ControllerSkinConfigurationSplitViewPortrait = 1 << 2, + ControllerSkinConfigurationSplitViewLandscape = 1 << 3, +}; + +#endif /* ControllerSkinConfigurations_h */ diff --git a/Common/Database/Model/_ControllerSkin.swift b/Common/Database/Model/_ControllerSkin.swift index 19db822..bff971e 100644 --- a/Common/Database/Model/_ControllerSkin.swift +++ b/Common/Database/Model/_ControllerSkin.swift @@ -24,6 +24,8 @@ public class _ControllerSkin: NSManagedObject @NSManaged public var name: String + @NSManaged public var supportedConfigurations: ControllerSkinConfigurations + // MARK: - Relationships } diff --git a/Delta.xcodeproj/project.pbxproj b/Delta.xcodeproj/project.pbxproj index ec6055d..6d72891 100644 --- a/Delta.xcodeproj/project.pbxproj +++ b/Delta.xcodeproj/project.pbxproj @@ -41,6 +41,7 @@ BF3540081C5DAFAD00C1184C /* PauseTransitionCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF3540071C5DAFAD00C1184C /* PauseTransitionCoordinator.swift */; }; BF5E7F441B9A650B00AE44F8 /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF5E7F431B9A650B00AE44F8 /* SettingsViewController.swift */; }; BF5E7F461B9A652600AE44F8 /* Settings.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BF5E7F451B9A652600AE44F8 /* Settings.storyboard */; }; + BF6866171DCAC8B900BF2D06 /* ControllerSkin+Configuring.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF6866161DCAC8B900BF2D06 /* ControllerSkin+Configuring.swift */; }; BF696B801D9B2B02009639E0 /* Theme.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF696B7F1D9B2B02009639E0 /* Theme.swift */; }; BF70798C1B6B464B0019077C /* ZipZap.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BF70798B1B6B464B0019077C /* ZipZap.framework */; }; BF70798D1B6B464B0019077C /* ZipZap.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BF70798B1B6B464B0019077C /* ZipZap.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -108,6 +109,7 @@ BF090CF11B490D8300DCAB45 /* Delta-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Delta-Bridging-Header.h"; sourceTree = ""; }; BF090CF21B490D8300DCAB45 /* UIDevice+Vibration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice+Vibration.h"; sourceTree = ""; }; BF090CF31B490D8300DCAB45 /* UIDevice+Vibration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice+Vibration.m"; sourceTree = ""; }; + BF0A81C41DC915C800443EF0 /* ControllerSkinConfigurations.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ControllerSkinConfigurations.h; path = Misc/ControllerSkinConfigurations.h; sourceTree = ""; }; BF0CDDAC1C8155D200640168 /* LoadImageOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LoadImageOperation.swift; path = Components/LoadImageOperation.swift; sourceTree = ""; }; BF107EC31BF413F000E0C32C /* GamesViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GamesViewController.swift; sourceTree = ""; }; BF11734C1DA32A5200047DF8 /* GameType+Localization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "GameType+Localization.swift"; sourceTree = ""; }; @@ -143,6 +145,7 @@ BF5E7F431B9A650B00AE44F8 /* SettingsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = ""; }; BF5E7F451B9A652600AE44F8 /* Settings.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Settings.storyboard; sourceTree = ""; }; BF63BDE91D389EEB00FCB040 /* GameViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GameViewController.swift; sourceTree = ""; }; + BF6866161DCAC8B900BF2D06 /* ControllerSkin+Configuring.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ControllerSkin+Configuring.swift"; sourceTree = ""; }; BF696B7F1D9B2B02009639E0 /* Theme.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Theme.swift; path = Theming/Theme.swift; sourceTree = ""; }; BF6BB2451BB73FE800CCF94A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; BF70798B1B6B464B0019077C /* ZipZap.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = ZipZap.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -213,10 +216,19 @@ BFCEA67D1D56FF640061A534 /* UIViewControllerContextTransitioning+Conveniences.swift */, BF13A7571D5D2FD9000BB055 /* EmulatorCore+Cheats.swift */, BF11734C1DA32A5200047DF8 /* GameType+Localization.swift */, + BF6866161DCAC8B900BF2D06 /* ControllerSkin+Configuring.swift */, ); path = Extensions; sourceTree = ""; }; + BF0A81C31DC915A100443EF0 /* Misc */ = { + isa = PBXGroup; + children = ( + BF0A81C41DC915C800443EF0 /* ControllerSkinConfigurations.h */, + ); + name = Misc; + sourceTree = ""; + }; BF11734E1DA32CEC00047DF8 /* Controllers */ = { isa = PBXGroup; children = ( @@ -302,6 +314,7 @@ BF28980B1DAAFB640023D8E9 /* Delta.xcdatamodeld */, BF28980F1DAAFC0E0023D8E9 /* Human */, BF2898101DAAFC120023D8E9 /* Machine */, + BF0A81C31DC915A100443EF0 /* Misc */, ); path = Model; sourceTree = ""; @@ -698,6 +711,7 @@ BFC853351DB039AD00E8C372 /* _ControllerSkin.swift in Sources */, BFC853371DB039B500E8C372 /* ControllerSkin.swift in Sources */, BF13A7561D5D29B0000BB055 /* PreviewGameViewController.swift in Sources */, + BF6866171DCAC8B900BF2D06 /* ControllerSkin+Configuring.swift in Sources */, BFDD04EF1D5E27DB002D450E /* NSFetchedResultsController+Conveniences.m in Sources */, BFCEA67E1D56FF640061A534 /* UIViewControllerContextTransitioning+Conveniences.swift in Sources */, BF2898161DAAFC2A0023D8E9 /* Game.swift in Sources */, diff --git a/Delta/Extensions/ControllerSkin+Configuring.swift b/Delta/Extensions/ControllerSkin+Configuring.swift new file mode 100644 index 0000000..19aa337 --- /dev/null +++ b/Delta/Extensions/ControllerSkin+Configuring.swift @@ -0,0 +1,76 @@ +// +// ControllerSkin+Configuring.swift +// Delta +// +// Created by Riley Testut on 11/2/16. +// Copyright © 2016 Riley Testut. All rights reserved. +// + +import DeltaCore + +extension ControllerSkin +{ + func configure(with skin: DeltaCore.ControllerSkin) + { + // Manually copy values to be stored in database. + // Remaining ControllerSkinProtocol requirements will be provided by the ControllerSkin's private DeltaCore.ControllerSkin instance. + self.name = skin.name + self.identifier = skin.identifier + self.gameType = skin.gameType + + var configurations = ControllerSkinConfigurations() + + if UIDevice.current.userInterfaceIdiom == .pad + { + var portraitTraits = DeltaCore.ControllerSkin.Traits(deviceType: .ipad, displayMode: .fullScreen, orientation: .portrait) + + var landscapeTraits = portraitTraits + landscapeTraits.orientation = .landscape + + + if skin.supports(portraitTraits) + { + configurations.formUnion(.fullScreenPortrait) + } + + if skin.supports(landscapeTraits) + { + configurations.formUnion(.fullScreenLandscape) + } + + + portraitTraits.displayMode = .splitView + landscapeTraits.displayMode = .splitView + + + if skin.supports(portraitTraits) + { + configurations.formUnion(.splitViewPortrait) + } + + if skin.supports(landscapeTraits) + { + configurations.formUnion(.splitViewLandscape) + } + } + else + { + let portraitTraits = DeltaCore.ControllerSkin.Traits(deviceType: .iphone, displayMode: .fullScreen, orientation: .portrait) + + var landscapeTraits = portraitTraits + landscapeTraits.orientation = .landscape + + if skin.supports(portraitTraits) + { + configurations.formUnion(.fullScreenPortrait) + } + + if skin.supports(landscapeTraits) + { + configurations.formUnion(.fullScreenLandscape) + } + } + + self.supportedConfigurations = configurations + } +} diff --git a/Delta/Supporting Files/Delta-Bridging-Header.h b/Delta/Supporting Files/Delta-Bridging-Header.h index d25ca0a..fc19b9d 100644 --- a/Delta/Supporting Files/Delta-Bridging-Header.h +++ b/Delta/Supporting Files/Delta-Bridging-Header.h @@ -4,3 +4,4 @@ #import "UIDevice+Vibration.h" #import "NSFetchedResultsController+Conveniences.h" +#import "ControllerSkinConfigurations.h"