From 2911c715fd4418870e87d6bbc7113ebfd0b44406 Mon Sep 17 00:00:00 2001 From: Hugo Pezziardi Date: Fri, 22 Dec 2023 11:01:42 +0100 Subject: [PATCH] :sparkles: (GEK): Add reinforcer enabler --- .../Views/Activity/ActivityProgressBar.swift | 2 +- .../Views/Activity/ActivityView.swift | 22 ++++++++++++++----- .../Activity/ActivityViewViewModel.swift | 5 +++-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Modules/GameEngineKit/Sources/_NewSystem/Views/Activity/ActivityProgressBar.swift b/Modules/GameEngineKit/Sources/_NewSystem/Views/Activity/ActivityProgressBar.swift index 83847bf2e8..ad5810af3b 100644 --- a/Modules/GameEngineKit/Sources/_NewSystem/Views/Activity/ActivityProgressBar.swift +++ b/Modules/GameEngineKit/Sources/_NewSystem/Views/Activity/ActivityProgressBar.swift @@ -38,7 +38,7 @@ struct ActivityProgressBar: View { .padding(6) .onChange(of: self.viewModel.currentExerciseSharedData.state) { newValue in if newValue == .completed { - withAnimation(.snappy.delay(5)) { + withAnimation(.snappy.delay(self.viewModel.isReinforcerEnabled ? 5 : 0.5)) { self.currentColor = .green } } diff --git a/Modules/GameEngineKit/Sources/_NewSystem/Views/Activity/ActivityView.swift b/Modules/GameEngineKit/Sources/_NewSystem/Views/Activity/ActivityView.swift index 0326601081..441a8f965f 100644 --- a/Modules/GameEngineKit/Sources/_NewSystem/Views/Activity/ActivityView.swift +++ b/Modules/GameEngineKit/Sources/_NewSystem/Views/Activity/ActivityView.swift @@ -8,6 +8,8 @@ import Lottie import RobotKit import SwiftUI +// swiftlint:disable cyclomatic_complexity void_function_in_ternary + extension LottieAnimation { static var reinforcer: LottieAnimation { LottieAnimation.named("reinforcer-spin-blink", bundle: .module)! @@ -54,7 +56,7 @@ public struct ActivityView: View { } } .id(self.viewModel.currentExerciseIndexInSequence) - .blur(radius: self.viewModel.isCurrentExerciseDisplayingReinforcer ? 20 : 0) + .blur(radius: self.viewModel.isCurrentExerciseCompleted && self.viewModel.isReinforcerEnabled ? 20 : 0) .opacity(self.viewModel.isCurrentActivityCompleted ? 0 : 1) self.lottieReinforcer @@ -80,6 +82,13 @@ public struct ActivityView: View { } .disabled(self.viewModel.isFirstExercise) } + ToolbarItem(placement: .topBarTrailing) { + Button { + self.viewModel.isReinforcerEnabled.toggle() + } label: { + Image(systemName: self.viewModel.isReinforcerEnabled ? "circle" : "circle.slash") + } + } ToolbarItem(placement: .topBarTrailing) { Button("Dismiss") { self.dismiss() @@ -130,15 +139,16 @@ public struct ActivityView: View { @ViewBuilder private var lottieReinforcer: some View { - let isLottieDisplayed = self.viewModel.isCurrentExerciseDisplayingReinforcer + let isLottieDisplayed = self.viewModel.isCurrentExerciseCompleted + let isReinforcerEnabled = self.viewModel.isReinforcerEnabled - if isLottieDisplayed { + if isLottieDisplayed, isReinforcerEnabled { LottieView( animation: .reinforcer, speed: 0.25, action: { withAnimation { - self.viewModel.isCurrentExerciseDisplayingReinforcer = false + self.viewModel.isCurrentExerciseCompleted = false } } ) @@ -168,7 +178,7 @@ public struct ActivityView: View { .buttonStyle(.borderedProminent) .tint(.green) .padding() - .transition(.asymmetric(insertion: .opacity.animation(.snappy.delay(5)), removal: .identity)) + .transition(.asymmetric(insertion: .opacity.animation(.snappy.delay(self.viewModel.isReinforcerEnabled ? 5 : 0.5)), removal: .identity)) } } @@ -250,6 +260,8 @@ public struct ActivityView: View { } } +// swiftlint:enable cyclomatic_complexity void_function_in_ternary + #Preview { let activity = ContentKit.decodeActivity("activity-sample") return ActivityView(viewModel: ActivityViewViewModel(activity: activity)) diff --git a/Modules/GameEngineKit/Sources/_NewSystem/Views/Activity/ActivityViewViewModel.swift b/Modules/GameEngineKit/Sources/_NewSystem/Views/Activity/ActivityViewViewModel.swift index 9e681152ae..b77cc7155f 100644 --- a/Modules/GameEngineKit/Sources/_NewSystem/Views/Activity/ActivityViewViewModel.swift +++ b/Modules/GameEngineKit/Sources/_NewSystem/Views/Activity/ActivityViewViewModel.swift @@ -40,7 +40,8 @@ public class ActivityViewViewModel: ObservableObject { @Published var currentExercise: Exercise @Published var currentExerciseInterface: Exercise.Interface @Published var currentExerciseSharedData: ExerciseSharedData - @Published var isCurrentExerciseDisplayingReinforcer: Bool = false + @Published var isCurrentExerciseCompleted: Bool = false + @Published var isReinforcerEnabled: Bool = true @Published var isCurrentActivityCompleted: Bool = false // TODO(@ladislas/@hugo): Add method to change this boolean @@ -101,7 +102,7 @@ public class ActivityViewViewModel: ObservableObject { self.objectWillChange.send() if self.currentExerciseSharedData.state == .completed { withAnimation { - self.isCurrentExerciseDisplayingReinforcer = true + self.isCurrentExerciseCompleted = true } } }