Skip to content

Commit

Permalink
Merge pull request #13 from amiantos/background-color
Browse files Browse the repository at this point in the history
Configurable Background Color
  • Loading branch information
amiantos authored Jan 28, 2022
2 parents 20fcbdf + 7b2e386 commit 12e997c
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 33 deletions.
11 changes: 11 additions & 0 deletions Shared/Database.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import SpriteKit
extension SKColor {
static let defaultHandColor = SKColor(hue: 0, saturation: 0, brightness: 0.90, alpha: 1)
static let defaultDialColor = SKColor(hue: 0, saturation: 0, brightness: 0.05, alpha: 1)
static let defaultBackgroundColor = SKColor(hue: 0, saturation: 0, brightness: 0, alpha: 1)
}

struct Database {
fileprivate enum Key {
static let handColor = "multiClockHandColor"
static let dialColor = "multiClockDialColor"
static let backgroundColor = "multiClockBackgroundColor"
static let handDesign = "multiClockHandDesign"
static let dialDesign = "multiClockDialDesign"
}
Expand All @@ -32,6 +34,7 @@ struct Database {
database.register(defaults: [
Key.handColor: archiveData(SKColor.defaultHandColor),
Key.dialColor: archiveData(SKColor.defaultDialColor),
Key.backgroundColor: archiveData(SKColor.defaultBackgroundColor),
Key.dialDesign: DialDesign.ringThin.rawValue,
Key.handDesign: HandDesign.modern.rawValue
])
Expand All @@ -52,6 +55,10 @@ extension UserDefaults {
return unarchiveColor(data(forKey: Database.Key.dialColor)!)
}

var backgroundColor: SKColor {
return unarchiveColor(data(forKey: Database.Key.backgroundColor)!)
}

var handDesign: HandDesign {
return HandDesign(rawValue: string(forKey: Database.Key.handDesign)!) ?? .modern
}
Expand All @@ -70,6 +77,10 @@ extension UserDefaults {
set(archiveData(dialColor), for: Database.Key.dialColor)
}

func set(backgroundColor: SKColor) {
set(archiveData(backgroundColor), for: Database.Key.backgroundColor)
}

func set(handDesign: HandDesign) {
set(handDesign.rawValue, for: Database.Key.handDesign)
}
Expand Down
7 changes: 7 additions & 0 deletions Shared/Manager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ final class Manager {

private(set) var handColor: SKColor
private(set) var dialColor: SKColor
private(set) var backgroundColor: SKColor
private(set) var handDesign: HandDesign
private(set) var dialDesign: DialDesign

init() {
handColor = Database.standard.handColor
dialColor = Database.standard.dialColor
backgroundColor = Database.standard.backgroundColor
handDesign = Database.standard.handDesign
dialDesign = Database.standard.dialDesign
}
Expand All @@ -41,6 +43,11 @@ final class Manager {
delegate?.updatedSettings()
}

func setBackgroundColor(_ color: SKColor) {
Database.standard.set(backgroundColor: color)
delegate?.updatedSettings()
}

func setHandDesign(_ handDesign: HandDesign) {
Database.standard.set(handDesign: handDesign)
delegate?.updatedSettings()
Expand Down
2 changes: 1 addition & 1 deletion Shared/Scene/ClockScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ClockScene: SKScene, ManagerDelegate {
private var backgroundNode: SKShapeNode?

override func sceneDidLoad() {
backgroundColor = .black
backgroundColor = Database.standard.backgroundColor

controller = ClockController(size: frame.size)
controller?.scene = self
Expand Down
8 changes: 5 additions & 3 deletions macOS Screensaver/ConfigureSheet/ClockPreviewScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import SpriteKit

class ClockPreviewScene: SKScene, ManagerDelegate {

let clockNode = ClockNode(size: CGSize(width: 150, height: 150))
let clockNode = ClockNode(size: CGSize(width: 240, height: 240))

override func sceneDidLoad() {

backgroundColor = .black
backgroundColor = Database.standard.backgroundColor

clockNode.minuteHandNode.color = Database.standard.handColor
clockNode.hourHandNode.color = Database.standard.handColor

addChild(clockNode)
clockNode.position = CGPoint(x: 75, y: 75)
clockNode.position = CGPoint(x: 120, y: 120)

let rotation: CGFloat = -360
clockNode.minuteHandNode.run(SKAction.repeatForever(
Expand All @@ -38,6 +38,8 @@ class ClockPreviewScene: SKScene, ManagerDelegate {
clockNode.hourHandNode.color = Database.standard.handColor
clockNode.clockFaceNode.color = Database.standard.dialColor

backgroundColor = Database.standard.backgroundColor

clockNode.minuteHandNode.texture = handTextures[Database.standard.handDesign]?.minuteHandTexture
clockNode.hourHandNode.texture = handTextures[Database.standard.handDesign]?.hourHandTexture

Expand Down
Loading

0 comments on commit 12e997c

Please sign in to comment.