Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Point-Free authored and Point-Free committed Apr 23, 2024
1 parent ca796b7 commit 0d6af85
Show file tree
Hide file tree
Showing 16 changed files with 125 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@
"kind" : "remoteSourceControl",
"location" : "/~https://github.com/pointfreeco/swift-composable-architecture",
"state" : {
"revision" : "115fe5af41d333b6156d4924d7c7058bc77fd580",
"version" : "1.9.2"
"branch" : "shared-state-beta",
"revision" : "0293b055101b7283ddbe332c7945b424aca5eb72"
}
},
{
Expand Down
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var package = Package(
dependencies: [
.package(url: "/~https://github.com/apple/swift-crypto", from: "1.1.6"),
.package(url: "/~https://github.com/pointfreeco/swift-case-paths", from: "1.1.0"),
.package(url: "/~https://github.com/pointfreeco/swift-composable-architecture", from: "1.9.2"),
.package(url: "/~https://github.com/pointfreeco/swift-composable-architecture", branch: "shared-state-beta"),
.package(url: "/~https://github.com/pointfreeco/swift-custom-dump", from: "1.0.0"),
.package(url: "/~https://github.com/pointfreeco/swift-dependencies", from: "1.1.0"),
.package(url: "/~https://github.com/pointfreeco/swift-gen", from: "0.3.0"),
Expand Down Expand Up @@ -933,6 +933,7 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
name: "UserSettingsClient",
dependencies: [
"Styleguide",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
.product(name: "Dependencies", package: "swift-dependencies"),
]
),
Expand Down
2 changes: 1 addition & 1 deletion Sources/AppFeature/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public struct AppDelegateReducer {
@Dependency(\.remoteNotifications.register) var registerForRemoteNotifications
@Dependency(\.applicationClient.setUserInterfaceStyle) var setUserInterfaceStyle
@Dependency(\.userNotifications) var userNotifications
@Dependency(\.userSettings) var userSettings

public init() {}

Expand Down Expand Up @@ -65,6 +64,7 @@ public struct AppDelegateReducer {
}

group.addTask {
@Shared(.userSettings) var userSettings
await self.audioPlayer.setGlobalVolumeForSoundEffects(userSettings.soundEffectsVolume)
await self.audioPlayer.setGlobalVolumeForMusic(
self.audioPlayer.secondaryAudioShouldBeSilencedHint()
Expand Down
2 changes: 1 addition & 1 deletion Sources/AppFeature/GameCenterCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public struct GameCenterLogic {
for await event in self.gameCenter.localPlayer.listener() {
await send(.gameCenter(.listener(event)))
}
}
} catch: { _, _ in }

case .destination(
.presented(.game(.destination(.presented(.gameOver(.rematchButtonTapped)))))
Expand Down
14 changes: 13 additions & 1 deletion Sources/ComposableGameCenter/LiveKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@
localPlayer: .live,
reportAchievements: { try await GKAchievement.report($0) },
showNotificationBanner: {
await GKNotificationBanner.show(withTitle: $0.title, message: $0.message)
if #available(iOS 16.1, *) {
var content = UNMutableNotificationContent()
content.title = $0.title ?? content.title
content.body = $0.message ?? content.body
let request = UNNotificationRequest(
identifier: UUID().uuidString,
content: content,
trigger: nil
)
try? await UNUserNotificationCenter.current().add(request)
} else {
await GKNotificationBanner.show(withTitle: $0.title, message: $0.message)
}
},
turnBasedMatch: .live,
turnBasedMatchmakerViewController: .live
Expand Down
15 changes: 4 additions & 11 deletions Sources/CubePreview/CubePreviewView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ public struct CubePreview {
@ObservableState
public struct State: Equatable {
var cubes: Puzzle
var enableGyroMotion: Bool
var isAnimationReduced: Bool
var isOnLowPowerMode: Bool
var moveIndex: Int
var moves: Moves
var nub: CubeSceneView.ViewState.NubState
var selectedCubeFaces: [IndexedCubeFace]
@Shared(.userSettings) var userSettings

public init(
cubes: ArchivablePuzzle,
Expand All @@ -30,14 +29,9 @@ public struct CubePreview {
nub: CubeSceneView.ViewState.NubState = .init(),
selectedCubeFaces: [IndexedCubeFace] = []
) {
@Dependency(\.userSettings) var userSettings

var cubes = Puzzle(archivableCubes: cubes)
apply(moves: moves[0..<moveIndex], to: &cubes)
self.cubes = cubes

self.enableGyroMotion = userSettings.enableGyroMotion
self.isAnimationReduced = userSettings.enableReducedAnimation
self.isOnLowPowerMode = isOnLowPowerMode
self.moveIndex = moveIndex
self.moves = moves
Expand Down Expand Up @@ -83,7 +77,7 @@ public struct CubePreview {
}
}
},
enableGyroMotion: self.enableGyroMotion,
enableGyroMotion: self.userSettings.enableGyroMotion,
isOnLowPowerMode: self.isOnLowPowerMode,
nub: self.nub,
playedWords: [],
Expand Down Expand Up @@ -117,7 +111,6 @@ public struct CubePreview {

@Dependency(\.lowPowerMode) var lowPowerMode
@Dependency(\.mainQueue) var mainQueue
@Dependency(\.userSettings) var userSettings

public init() {}

Expand Down Expand Up @@ -210,7 +203,7 @@ public struct CubePreview {
}
}
.haptics(
isEnabled: { _ in self.userSettings.enableHaptics },
isEnabled: \.userSettings.enableHaptics,
triggerOnChangeOf: \.selectedCubeFaces
)
.selectionSounds(
Expand Down Expand Up @@ -262,7 +255,7 @@ public struct CubePreviewView: View {
.task { await store.send(.task).finish() }
}
.background {
if !store.isAnimationReduced {
if !store.userSettings.enableReducedAnimation {
BloomBackground(
size: proxy.size,
word: store.selectedWordString
Expand Down
2 changes: 1 addition & 1 deletion Sources/GameCore/CubeSceneViewState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extension CubeSceneView.ViewState {
}
}
},
enableGyroMotion: game.enableGyroMotion,
enableGyroMotion: game.userSettings.enableGyroMotion,
isOnLowPowerMode: game.isOnLowPowerMode,
nub: nub,
playedWords: game.playedWords,
Expand Down
3 changes: 1 addition & 2 deletions Sources/GameCore/Drawer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public struct ActiveGamesTray {
.lowPowerModeChanged,
.matchesLoaded(.failure),
.savedGamesLoaded(.failure),
.timerTick,
.userSettingsUpdated:
.timerTick:

return .none

Expand Down
19 changes: 1 addition & 18 deletions Sources/GameCore/GameCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public struct Game {
public var gameCurrentTime: Date
public var gameMode: GameMode
public var gameStartTime: Date
public var enableGyroMotion: Bool
public var isAnimationReduced: Bool
public var isDemo: Bool
public var isGameLoaded: Bool
public var isOnLowPowerMode: Bool
Expand All @@ -67,6 +65,7 @@ public struct Game {
public var secondsPlayed: Int
public var selectedWord: [IndexedCubeFace]
public var selectedWordIsValid: Bool
@Shared(.userSettings) public var userSettings
public var wordSubmitButton: WordSubmitButtonFeature.ButtonState

public init(
Expand All @@ -91,17 +90,14 @@ public struct Game {
selectedWordIsValid: Bool = false,
wordSubmit: WordSubmitButtonFeature.ButtonState = .init()
) {
@Dependency(\.userSettings) var userSettings
self.activeGames = activeGames
self.cubes = cubes
self.cubeStartedShakingAt = cubeStartedShakingAt
self.destination = destination
self.enableGyroMotion = userSettings.enableGyroMotion
self.gameContext = gameContext
self.gameCurrentTime = gameCurrentTime
self.gameMode = gameMode
self.gameStartTime = gameStartTime
self.isAnimationReduced = userSettings.enableReducedAnimation
self.isDemo = isDemo
self.isGameLoaded = isGameLoaded
self.isOnLowPowerMode = isOnLowPowerMode
Expand Down Expand Up @@ -158,7 +154,6 @@ public struct Game {
case tap(UIGestureRecognizer.State, IndexedCubeFace?)
case timerTick(Date)
case trayButtonTapped
case userSettingsUpdated(UserSettings)
case wordSubmitButton(WordSubmitButtonFeature.Action)
}

Expand All @@ -178,7 +173,6 @@ public struct Game {
@Dependency(\.mainRunLoop) var mainRunLoop
@Dependency(\.serverConfig.config) var serverConfig
@Dependency(\.userDefaults) var userDefaults
@Dependency(\.userSettings) var userSettings

public init() {}

Expand Down Expand Up @@ -350,12 +344,6 @@ public struct Game {
try await self.mainQueue.sleep(for: 0.5)
await send(.gameLoaded)
}

group.addTask {
for await userSettings in self.userSettings.stream() {
await send(.userSettingsUpdated(userSettings))
}
}
}
for music in AudioPlayerClient.Sound.allMusic {
await self.audioPlayer.stop(music)
Expand Down Expand Up @@ -511,11 +499,6 @@ public struct Game {
case .trayButtonTapped:
return .none

case let .userSettingsUpdated(userSettings):
state.enableGyroMotion = userSettings.enableGyroMotion
state.isAnimationReduced = userSettings.enableReducedAnimation
return .none

case .wordSubmitButton:
return .none
}
Expand Down
1 change: 0 additions & 1 deletion Sources/GameCore/TurnBased.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ extension Reducer where State == Game.State, Action == Game.Action {
.savedGamesLoaded,
.timerTick,
.trayButtonTapped,
.userSettingsUpdated,
.wordSubmitButton:
return true
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/GameCore/Views/GameFooterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public struct GameFooterView: View {
store: store
)
.transition(
store.isAnimationReduced
store.userSettings.enableReducedAnimation
? .opacity
: AnyTransition.offset(y: 50)
.combined(with: .opacity)
Expand Down
4 changes: 2 additions & 2 deletions Sources/GameCore/Views/GameView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public struct GameView<Content>: View where Content: View {
)
.ignoresSafeArea()
.transition(
store.isAnimationReduced
store.userSettings.enableReducedAnimation
? .opacity
: .asymmetric(insertion: .offset(y: 50), removal: .offset(y: 50))
.combined(with: .opacity)
Expand Down Expand Up @@ -126,7 +126,7 @@ public struct GameView<Content>: View where Content: View {
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background {
if !store.isAnimationReduced {
if !store.userSettings.enableReducedAnimation {
BloomBackground(
size: proxy.size,
word: store.selectedWordString
Expand Down
4 changes: 2 additions & 2 deletions Sources/OnboardingFeature/OnboardingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public struct Onboarding {
public var game: Game.State
public var presentationStyle: PresentationStyle
public var step: Step
@Shared(.userSettings) var userSettings

public init(
alert: AlertState<Action.Alert>? = nil,
Expand Down Expand Up @@ -182,7 +183,6 @@ public struct Onboarding {
@Dependency(\.feedbackGenerator) var feedbackGenerator
@Dependency(\.mainQueue) var mainQueue
@Dependency(\.userDefaults) var userDefaults
@Dependency(\.userSettings) var userSettings

public init() {}

Expand Down Expand Up @@ -380,7 +380,7 @@ public struct Onboarding {
Scope(state: \.game, action: \.game) {
Game()
.haptics(
isEnabled: { _ in self.userSettings.enableHaptics },
isEnabled: \.userSettings.enableHaptics,
triggerOnChangeOf: \.selectedWord
)
}
Expand Down
13 changes: 1 addition & 12 deletions Sources/SettingsFeature/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public struct Settings {
public var isRestoring: Bool
public var stats: Stats.State
public var userNotificationSettings: UserNotificationClient.Notification.Settings?
public var userSettings: UserSettings
@Shared(.userSettings) public var userSettings

public struct ProductError: Error, Equatable {}

Expand All @@ -68,7 +68,6 @@ public struct Settings {
stats: Stats.State = .init(),
userNotificationSettings: UserNotificationClient.Notification.Settings? = nil
) {
@Dependency(\.userSettings) var userSettings
self.alert = alert
self.buildNumber = buildNumber
self.developer = developer
Expand All @@ -78,7 +77,6 @@ public struct Settings {
self.isRestoring = isRestoring
self.stats = stats
self.userNotificationSettings = userNotificationSettings
self.userSettings = userSettings.get()
}

public var isFullGamePurchased: Bool {
Expand Down Expand Up @@ -117,7 +115,6 @@ public struct Settings {
@Dependency(\.serverConfig.config) var serverConfig
@Dependency(\.storeKit) var storeKit
@Dependency(\.userNotifications) var userNotifications
@Dependency(\.userSettings) var userSettings

public init() {}

Expand Down Expand Up @@ -456,14 +453,6 @@ public struct Settings {
}
}
.ifLet(\.$alert, action: \.alert)
.onChange(of: \.userSettings) { _, userSettings in
Reduce { _, _ in
enum CancelID { case saveDebounce }

return .run { _ in await self.userSettings.set(userSettings) }
.debounce(id: CancelID.saveDebounce, for: .seconds(0.5), scheduler: self.mainQueue)
}
}

Scope(state: \.stats, action: \.stats) {
Stats()
Expand Down
12 changes: 4 additions & 8 deletions Sources/SettingsFeature/SoundsSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,14 @@ struct SoundsSettingsView: View {

struct SoundsSettingsView_Previews: PreviewProvider {
static var previews: some View {
Preview {
@Shared(.userSettings) var userSettings
userSettings.musicVolume = 0.5
userSettings.soundEffectsVolume = 0.5
return Preview {
NavigationView {
SoundsSettingsView(
store: Store(initialState: Settings.State()) {
Settings()
} withDependencies: {
$0.userSettings = .mock(
initialUserSettings: UserSettings(
musicVolume: 0.5,
soundEffectsVolume: 0.5
)
)
}
)
}
Expand Down
Loading

0 comments on commit 0d6af85

Please sign in to comment.