forked from notjosh/Aureal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
205 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import Cocoa | ||
|
||
struct CommandColor { | ||
let r: UInt8 | ||
let g: UInt8 | ||
let b: UInt8 | ||
|
||
init(r: UInt8, g: UInt8, b: UInt8) { | ||
self.r = r | ||
self.g = g | ||
self.b = b | ||
} | ||
|
||
init(color: NSColor) { | ||
let rgb = color.usingColorSpace(NSColorSpace.sRGB)! | ||
// let rgb = color | ||
|
||
let r: UInt8 = UInt8(rgb.redComponent * 255) | ||
let g: UInt8 = UInt8(rgb.greenComponent * 255) | ||
let b: UInt8 = UInt8(rgb.blueComponent * 255) | ||
|
||
self.init(r: r, g: g, b: b) | ||
} | ||
} | ||
|
||
extension CommandColor { | ||
static let red = CommandColor(r: 0xff, g: 0x00, b: 0x00) | ||
static let blue = CommandColor(r: 0x00, g: 0x00, b: 0xff) | ||
static let green = CommandColor(r: 0x00, g: 0xff, b: 0x00) | ||
static let white = CommandColor(r: 0xff, g: 0xff, b: 0xff) | ||
static let lwhite = CommandColor(r: 0x40, g: 0x40, b: 0x40) | ||
static let black = CommandColor(r: 0x00, g: 0x00, b: 0x00) | ||
|
||
static var random: CommandColor { | ||
CommandColor( | ||
r: UInt8.random(in: 0...255), | ||
g: UInt8.random(in: 0...255), | ||
b: UInt8.random(in: 0...255) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import Foundation | ||
|
||
enum EffectType { | ||
case builtInEffect | ||
case direct | ||
} | ||
|
||
enum EffectColorMode: Equatable { | ||
case none | ||
case count(Int) | ||
case dynamic | ||
|
||
var count: Int { | ||
switch self { | ||
case .none: | ||
return 0 | ||
case .count(let count): | ||
return count | ||
case .dynamic: | ||
return 3 | ||
} | ||
} | ||
} | ||
|
||
protocol Effect { | ||
var name: String { get } | ||
var type: EffectType { get } | ||
var colorMode: EffectColorMode { get } | ||
|
||
func command(for colors: [CommandColor]) -> Command | ||
} | ||
|
||
struct BuiltInEffect: Effect { | ||
let mode: AuraEffect | ||
|
||
var name: String { | ||
"Built-in: \(mode.name)" | ||
} | ||
|
||
var colorMode: EffectColorMode { | ||
mode.isColorable ? .count(1) : .none | ||
} | ||
|
||
var type: EffectType { | ||
.builtInEffect | ||
} | ||
|
||
func command(for colors: [CommandColor]) -> Command { | ||
let command = EffectCommand( | ||
mode, | ||
color: mode.isColorable ? colors.first ?? .black : .black | ||
) | ||
|
||
return command | ||
} | ||
} | ||
|
||
struct DirectEffect: Effect { | ||
let name: String | ||
let builder: (([CommandColor]) -> DirectCommand) | ||
let colorMode: EffectColorMode | ||
|
||
var type: EffectType { | ||
.direct | ||
} | ||
|
||
func command(for colors: [CommandColor]) -> Command { | ||
return builder(colors) | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Foundation | ||
|
||
// essentially "%", but also works on negative numbers | ||
// via https://stackoverflow.com/a/59461073 | ||
infix operator %% | ||
extension Int { | ||
static func %% (_ left: Int, _ right: Int) -> Int { | ||
if left >= 0 { return left % right } | ||
if left >= -right { return (left + right) } | ||
return ((left % right) + right) % right | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.