Skip to content

Commit

Permalink
Cube preview selection (pointfreeco#51)
Browse files Browse the repository at this point in the history
* Animate selection on cube preview.

* wip

* wip

* wip

* wip

* wip

* wip

* clean up

* wip

* wip

* clean up

* extracted out haptics core

* clean up

* wip

* wip

* wip

* clean up

* fix tests

* clean up

* fix scoring

* undo

* wip

* fix things discussed

* fix trailer

* fix tests
  • Loading branch information
mbrandonw authored Mar 29, 2021
1 parent 2601b47 commit 1195a70
Show file tree
Hide file tree
Showing 26 changed files with 787 additions and 867 deletions.
158 changes: 56 additions & 102 deletions App/Previews/CubePreviewPreview/CubePreviewPreviewApp.swift
Original file line number Diff line number Diff line change
@@ -1,117 +1,71 @@
import ClientModels
import CubeCore
import CubePreview
import PuzzleGen
import SharedModels
import Styleguide
import SwiftUI

@testable import CubePreview

@main
struct CubePreviewPreviewApp: App {
@State var wordPreviewIsPresented = false
@State var gamePreviewIsPresented = false

init() {
Styleguide.registerFonts()
}

var body: some Scene {
WindowGroup {
NavigationView {
Form {
Button("Word Preview") { self.wordPreviewIsPresented = true }
.sheet(isPresented: self.$wordPreviewIsPresented) {
CubePreviewView(
store: .init(
initialState: .init(
preview: .words(
.init(
words: [word]
)
)
CubePreviewView(
store: .init(
initialState: .init(
cubes: .mock,
isHapticsEnabled: true,
isOnLowPowerMode: false,
moveIndex: 0,
moves: [
.init(
playedAt: .mock,
playerIndex: nil,
reactions: nil,
score: 2_000,
type: .playedWord([
.init(
index: .init(x: .two, y: .two, z: .two),
side: .top
),
reducer: cubePreviewReducer,
environment: CubePreviewEnvironment()
)
)
}

Button("Game Preview") { self.gamePreviewIsPresented = true }
.sheet(isPresented: self.$gamePreviewIsPresented) {
CubePreviewView(
store: .init(
initialState: .init(
preview: .game(
.init(
cubes: .init(cubes: randomCubes(for: isowordsLetter).run()),
moves: word.moves
)
)
.init(
index: .init(x: .two, y: .two, z: .one),
side: .top
),
reducer: cubePreviewReducer,
environment: CubePreviewEnvironment()
)
.init(
index: .init(x: .two, y: .two, z: .zero),
side: .top
),
.init(
index: .init(x: .two, y: .two, z: .zero),
side: .right
),
.init(
index: .init(x: .two, y: .two, z: .one),
side: .right
),
.init(
index: .init(x: .two, y: .two, z: .two),
side: .right
),
])
)
}
}
.navigationTitle(Text("Cube Preview"))
}
],
settings: .init()
),
reducer: cubePreviewReducer,
environment: CubePreviewEnvironment(
audioPlayer: .noop,
feedbackGenerator: .live,
lowPowerMode: .live,
mainQueue: DispatchQueue.main.eraseToAnyScheduler()
)
)
)
}
}
}

let word = PreviewType.Word(
cubes: .init(cubes: randomCubes(for: isowordsLetter).run()),
moveIndex: 5,
moves: [
.init(
playedAt: Date(),
playerIndex: nil,
reactions: nil,
score: 0,
type: .removedCube(.init(x: .two, y: .two, z: .two))
),
.init(
playedAt: Date(),
playerIndex: nil,
reactions: nil,
score: 0,
type: .removedCube(.init(x: .two, y: .one, z: .two))
),
.init(
playedAt: Date(),
playerIndex: nil,
reactions: nil,
score: 0,
type: .removedCube(.init(x: .one, y: .two, z: .two))
),
.init(
playedAt: Date(),
playerIndex: nil,
reactions: nil,
score: 0,
type: .removedCube(.init(x: .two, y: .two, z: .one))
),
.init(
playedAt: Date(),
playerIndex: nil,
reactions: nil,
score: 100,
type: .playedWord([
.init(index: .init(x: .one, y: .zero, z: .two), side: .left),
.init(index: .init(x: .zero, y: .zero, z: .two), side: .left),
.init(index: .init(x: .one, y: .one, z: .two), side: .left),
.init(index: .init(x: .one, y: .two, z: .two), side: .left),
.init(index: .init(x: .zero, y: .two, z: .two), side: .left),
])
),
.init(
playedAt: Date(),
playerIndex: nil,
reactions: nil,
score: 100,
type: .playedWord([
.init(index: .init(x: .two, y: .zero, z: .two), side: .left),
.init(index: .init(x: .two, y: .zero, z: .two), side: .top),
.init(index: .init(x: .two, y: .one, z: .one), side: .left),
.init(index: .init(x: .one, y: .two, z: .one), side: .left),
.init(index: .init(x: .zero, y: .two, z: .one), side: .top),
])
),
]
)
2 changes: 2 additions & 0 deletions App/Previews/HomeFeaturePreview/HomeFeaturePreviewApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ struct HomeFeaturePreviewApp: App {
build: .noop,
database: .live(path: URL(string: ":memory:")!),
deviceId: .noop,
feedbackGenerator: .live,
fileClient: .live,
gameCenter: .noop,
lowPowerMode: .live,
mainQueue: DispatchQueue.main.eraseToAnyScheduler(),
mainRunLoop: RunLoop.main.eraseToAnyScheduler(),
remoteNotifications: .noop,
Expand Down
2 changes: 2 additions & 0 deletions App/Previews/SettingsPreview/SettingsPreviewApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ struct SettingsPreviewApp: App {
backgroundQueue: DispatchQueue(label: "background-queue").eraseToAnyScheduler(),
build: .noop,
database: .noop,
feedbackGenerator: .live,
fileClient: .live,
lowPowerMode: .live,
mainQueue: DispatchQueue.main.eraseToAnyScheduler(),
remoteNotifications: .live,
serverConfig: ServerConfigClient.live(fetch: { .init(value: .init()) }),
Expand Down
47 changes: 47 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
.library(name: "AppClipAudioLibrary", targets: ["AppClipAudioLibrary"]),
.library(name: "AppFeature", targets: ["AppFeature"]),
.library(name: "AudioPlayerClient", targets: ["AudioPlayerClient"]),
.library(name: "Bloom", targets: ["Bloom"]),
.library(name: "BottomMenu", targets: ["BottomMenu"]),
.library(name: "ClientModels", targets: ["ClientModels"]),
.library(name: "CombineHelpers", targets: ["CombineHelpers"]),
Expand All @@ -329,6 +330,7 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
.library(name: "GameCore", targets: ["GameCore"]),
.library(name: "GameFeature", targets: ["GameFeature"]),
.library(name: "GameOverFeature", targets: ["GameOverFeature"]),
.library(name: "HapticsCore", targets: ["HapticsCore"]),
.library(name: "HomeFeature", targets: ["HomeFeature"]),
.library(name: "IntegrationTestHelpers", targets: ["IntegrationTestHelpers"]),
.library(name: "LeaderboardFeature", targets: ["LeaderboardFeature"]),
Expand All @@ -339,6 +341,7 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
.library(name: "NotificationsAuthAlert", targets: ["NotificationsAuthAlert"]),
.library(name: "OnboardingFeature", targets: ["OnboardingFeature"]),
.library(name: "RemoteNotificationsClient", targets: ["RemoteNotificationsClient"]),
.library(name: "SelectionSoundsCore", targets: ["SelectionSoundsCore"]),
.library(name: "ServerConfigClient", targets: ["ServerConfigClient"]),
.library(name: "SettingsFeature", targets: ["SettingsFeature"]),
.library(name: "SharedSwiftUIEnvironment", targets: ["SharedSwiftUIEnvironment"]),
Expand Down Expand Up @@ -467,6 +470,14 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
]
),
.target(
name: "Bloom",
dependencies: [
"Styleguide",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
.product(name: "Gen", package: "swift-gen"),
]
),
.target(
name: "BottomMenu",
dependencies: [
Expand Down Expand Up @@ -540,7 +551,13 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
.target(
name: "CubePreview",
dependencies: [
"AudioPlayerClient",
"Bloom",
"CubeCore",
"FeedbackGeneratorClient",
"HapticsCore",
"LowPowerModeClient",
"SelectionSoundsCore",
"SharedModels",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
]
Expand Down Expand Up @@ -625,6 +642,7 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
.target(
name: "FeedbackGeneratorClient",
dependencies: [
"XCTestDebugSupport",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
]
Expand All @@ -645,6 +663,7 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"ActiveGamesFeature",
"ApiClient",
"AudioPlayerClient",
"Bloom",
"BottomMenu",
"Build",
"ClientModels",
Expand All @@ -656,9 +675,11 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"GameOverFeature",
"FeedbackGeneratorClient",
"FileClient",
"HapticsCore",
"LowPowerModeClient",
"PuzzleGen",
"RemoteNotificationsClient",
"SelectionSoundsCore",
"SharedSwiftUIEnvironment",
"Styleguide",
"TcaHelpers",
Expand Down Expand Up @@ -758,6 +779,14 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"SiteMiddleware",
]
),
.target(
name: "HapticsCore",
dependencies: [
"FeedbackGeneratorClient",
"TcaHelpers",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
]
),
.target(
name: "HomeFeature",
dependencies: [
Expand All @@ -776,6 +805,7 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"FileClient",
"LeaderboardFeature",
"LocalDatabaseClient",
"LowPowerModeClient",
"MultiplayerFeature",
"ServerConfigClient",
"SettingsFeature",
Expand Down Expand Up @@ -812,7 +842,9 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
name: "LeaderboardFeature",
dependencies: [
"ApiClient",
"AudioPlayerClient",
"CubePreview",
"LowPowerModeClient",
"Styleguide",
"SwiftUIHelpers",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
Expand Down Expand Up @@ -890,6 +922,15 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"OnboardingFeature"
]
),
.target(
name: "SelectionSoundsCore",
dependencies: [
"AudioPlayerClient",
"SharedModels",
"TcaHelpers",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
]
),
.target(
name: "RemoteNotificationsClient",
dependencies: [
Expand All @@ -915,6 +956,7 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"ComposableUserNotifications",
"FileClient",
"LocalDatabaseClient",
"LowPowerModeClient",
"RemoteNotificationsClient",
"ServerConfigClient",
"StatsFeature",
Expand Down Expand Up @@ -953,6 +995,7 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
.target(
name: "StatsFeature",
dependencies: [
"AudioPlayerClient",
"LocalDatabaseClient",
"Styleguide",
"VocabFeature",
Expand Down Expand Up @@ -985,6 +1028,7 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
name: "TrailerFeature",
dependencies: [
"ApiClient",
"Bloom",
"CubeCore",
"GameCore",
"DictionaryClient",
Expand Down Expand Up @@ -1034,8 +1078,11 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
.target(
name: "VocabFeature",
dependencies: [
"AudioPlayerClient",
"CubePreview",
"FeedbackGeneratorClient",
"LocalDatabaseClient",
"LowPowerModeClient",
"SharedModels",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
]
Expand Down
10 changes: 3 additions & 7 deletions Sources/AppFeature/AppView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ extension AppEnvironment {
build: self.build,
database: self.database,
deviceId: self.deviceId,
feedbackGenerator: self.feedbackGenerator,
fileClient: self.fileClient,
gameCenter: self.gameCenter,
lowPowerMode: self.lowPowerMode,
mainQueue: self.mainQueue,
mainRunLoop: self.mainRunLoop,
remoteNotifications: self.remoteNotifications,
Expand Down Expand Up @@ -245,13 +247,7 @@ let appReducerCore = Reducer<AppState, AppAction, AppEnvironment> { state, actio
environment.mainRunLoop.now.date.timeIntervalSinceReferenceDate
)
.fireAndForget()
: .none,

environment.serverConfig.refresh()
.ignoreOutput()
.ignoreFailure()
.eraseToEffect()
.fireAndForget()
: .none
)

case let .appDelegate(.userNotifications(.didReceiveResponse(response, completionHandler))):
Expand Down
Loading

0 comments on commit 1195a70

Please sign in to comment.