Skip to content

Instantly share code, notes, and snippets.

View vikingosegundo's full-sized avatar

Manuel Meyer vikingosegundo

  • Groningen, Netherlands
View GitHub Profile
struct Light:Codable, Equatable, Identifiable {
init(id:String, name:String) { self.init(id, name, .off, 0, 0, 0, 0, .slider, [], .unset) }
enum Mode:Codable { case unset, hsb, ct }
enum Temperature { case mirek(Int) }
let id : String
let name : String
let isOn : Turn
import Foundation
import BrighterModel
typealias Input = (Message) -> ()
typealias Output = (Message) -> ()
func createAppCore(
store : Store,
receivers : [Input],
typealias Input = (Message) -> ()
typealias Output = (Message) -> ()
func createLightingFeature(store : Store,
lightsStack: LightsStack,
output : @escaping Output) -> Input
{
let loader = LightsLoader (lightsStack:lightsStack,store:store,responder:handle(output:output))
let switcher = LightSwitcher (lightsStack:lightsStack,store:store,responder:handle(output:output))
let valueSetter = LightValueSetter(lightsStack:lightsStack,store:store,responder:handle(output:output))
// Dimmer.Request
.increase(.brightness,by:10.pt,on:light))
.decrease(.brightness,by:10.pt,on:light))
.increase(.hue, by:10.pt,on:light))
.decrease(.hue, by:10.pt,on:light))
// Dimmer.Response
.increase(.brightness,by:10.pt,on:light,.succeeded )
.increase(.colortemp, by:10.pt,on:light,.succeeded )
.decrease(.hue, by:10.pt,on:light,.succeeded )
func request(_ dimmer:Dimmer, to r:Dimmer.Request) { dimmer.request(r) }
struct Dimmer: UseCase {
enum Request { case increase(Light.Value, by:Light.Value.Increment, on:Light )
case decrease(Light.Value, by:Light.Value.Increment, on:Light ) }
enum Response { case increase(Light.Value, by:Light.Value.Increment, on:Light, Outcome)
case decrease(Light.Value, by:Light.Value.Increment, on:Light, Outcome) }
init(lightsStack: LightsStack, store: Store, responder: @escaping (Response) -> ()) {
self.lightsStack = lightsStack
self.store = store
// Requests
.lighting(.load (.lights), )
.lighting(.turn (light,.on ), )
.lighting(.turn (light,.off ), )
.lighting(.apply(.values(.ct ( 200, 0.5)),on:light))
.lighting(.apply(.values(.hsb(0.5,0.5,0.5)),on:light))
.lighting(.apply(.values(.bri( 0.5)),on:light))
.lighting(.increase(.brightness,by:10.pt, on:light))
.lighting(.change(.name("1a"), on:light))
.lighting(.change(.display(.scrubbing), on:light))
import SwiftUI
struct ContentView: View {
init(viewState: ViewState, rootHandler: @escaping (Message) -> ()) {
self.viewState = viewState
self.rootHandler = rootHandler
self.tabColor = tabColors[0]
}
var body: some View {
TabView {
import SwiftUI
@main
struct SnakeApp:App {
var body:some Scene {
WindowGroup {
ZStack {
Color.black
.edgesIgnoringSafeArea(.all)
ContentView(state:ViewState(
struct SnakeButton:View {
@StateObject var state:ViewState
let title:String
let strokeColor:Color
let backgroundColor:Color
let callback: ()->()
var game: SnakeGame.Game { state.game }
var body: some View {
struct SnakeBoard:View {
func bodyAndTarget() -> [SnakeGame.Coordinate] {
(game.target() != nil
? [ game.target()! ]
: [])
+ game.snake().body
}
@StateObject var state:ViewState
let pixelFactor:Double
var game: SnakeGame.Game { state.game }