Adds ControllerSkin model object

This commit is contained in:
Riley Testut 2016-10-14 15:14:49 -07:00
parent 578cf5eda2
commit a94fac95de
8 changed files with 135 additions and 7 deletions

View File

@ -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 -

View File

@ -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)
}
}

View File

@ -19,6 +19,22 @@
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="ControllerSkin" representedClassName="ControllerSkin" syncable="YES">
<attribute name="filename" attributeType="String" syncable="YES"/>
<attribute name="gameType" attributeType="Transformable" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="GameType"/>
</userInfo>
</attribute>
<attribute name="identifier" attributeType="String" syncable="YES"/>
<attribute name="name" attributeType="String" syncable="YES"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="identifier"/>
<constraint value="gameType"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="Game" representedClassName="Game" syncable="YES">
<attribute name="artworkURL" optional="YES" attributeType="Transformable" syncable="YES">
<userInfo>
@ -82,6 +98,7 @@
</entity>
<elements>
<element name="Cheat" positionX="-198" positionY="-63" width="128" height="165"/>
<element name="ControllerSkin" positionX="-387" positionY="90" width="128" height="105"/>
<element name="Game" positionX="-378" positionY="-54" width="128" height="180"/>
<element name="GameCollection" positionX="-585" positionY="-27" width="128" height="90"/>
<element name="SaveState" positionX="-198" positionY="113" width="128" height="165"/>

View File

@ -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
}

View File

@ -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<ControllerSkin> {
return NSFetchRequest<ControllerSkin>(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
}

@ -1 +1 @@
Subproject commit 040f323f314ab60e85d7d5e40633ec30668ff874
Subproject commit 6558b6e5198ef9ae20e5ba9e68e4389fb210b66f

View File

@ -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 = "<group>"; };
BFBAA8691D5A483900A29C1B /* DatabaseManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseManager.swift; sourceTree = "<group>"; };
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 = "<group>"; };
BFC853361DB039B500E8C372 /* ControllerSkin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ControllerSkin.swift; sourceTree = "<group>"; };
BFC9B7381CEFCD34008629BB /* CheatsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CheatsViewController.swift; path = "Pause Menu/Cheats/CheatsViewController.swift"; sourceTree = "<group>"; };
BFCEA67D1D56FF640061A534 /* UIViewControllerContextTransitioning+Conveniences.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewControllerContextTransitioning+Conveniences.swift"; sourceTree = "<group>"; };
BFDB28441BC9DA7B001D0C83 /* GamePickerController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GamePickerController.swift; sourceTree = "<group>"; };
@ -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 */,

View File

@ -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)
}
}