Skip to content

Commit

Permalink
♻️ (UIExplorer): Instantiate gameplays with @StateObject
Browse files Browse the repository at this point in the history
Using @StateObject instead of @ObservedObject initiate gameplay when we start the activity instead of before
  • Loading branch information
HPezz committed Sep 22, 2023
1 parent 5da7045 commit 889f2a1
Show file tree
Hide file tree
Showing 18 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import GameEngineKit
import SwiftUI

struct DanceFreezeActivity: View {
let gameplay = DanceFreezeGameplay()
@StateObject private var gameplay = DanceFreezeGameplay()

var body: some View {
DanceFreezeView(gameplay: gameplay)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private var steps: [StandardStepModel] = [
]

struct ListenThenTouchToSelectFourChoicesActivity: View {
@ObservedObject private var stepManager = StepManager(steps: steps)
@StateObject private var stepManager = StepManager(steps: steps)

var body: some View {
stepManager.interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private var steps: [StandardStepModel] = [
]

struct ListenThenTouchToSelectOneChoiceActivity: View {
@ObservedObject private var stepManager = StepManager(steps: steps)
@StateObject private var stepManager = StepManager(steps: steps)

var body: some View {
stepManager.interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private var steps: [StandardStepModel] = [
]

struct ListenThenTouchToSelectSixChoicesActivity: View {
@ObservedObject private var stepManager = StepManager(steps: steps)
@StateObject private var stepManager = StepManager(steps: steps)

var body: some View {
stepManager.interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private var steps: [StandardStepModel] = [
]

struct ListenThenTouchToSelectThreeChoicesActivity: View {
@ObservedObject private var stepManager = StepManager(steps: steps)
@StateObject private var stepManager = StepManager(steps: steps)

var body: some View {
stepManager.interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private var steps: [StandardStepModel] = [
]

struct ListenThenTouchToSelectThreeChoicesInlineActivity: View {
@ObservedObject private var stepManager = StepManager(steps: steps)
@StateObject private var stepManager = StepManager(steps: steps)

var body: some View {
stepManager.interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private var steps: [StandardStepModel] = [
]

struct ListenThenTouchToSelectTwoChoicesActivity: View {
@ObservedObject private var stepManager = StepManager(steps: steps)
@StateObject private var stepManager = StepManager(steps: steps)

var body: some View {
stepManager.interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import GameEngineKit
import SwiftUI

struct MelodyActivity: View {
let gameplay = MelodyGameplay(song: kListOfMelodySongsAvailable[0])
@StateObject private var gameplay = MelodyGameplay(song: kListOfMelodySongsAvailable[0])

var body: some View {
MelodyView(gameplay: gameplay)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private var steps: [StandardStepModel] = [
]

struct TouchToSelectFiveChoicesActivity: View {
@ObservedObject private var stepManager = StepManager(steps: steps)
@StateObject private var stepManager = StepManager(steps: steps)

var body: some View {
stepManager.interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private var steps: [StandardStepModel] = [
]

struct TouchToSelectFourChoicesActivity: View {
@ObservedObject private var stepManager = StepManager(steps: steps)
@StateObject private var stepManager = StepManager(steps: steps)

var body: some View {
stepManager.interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private var steps: [StandardStepModel] = [
]

struct TouchToSelectFourChoicesInlineActivity: View {
@ObservedObject private var stepManager = StepManager(steps: steps)
@StateObject private var stepManager = StepManager(steps: steps)

var body: some View {
stepManager.interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private var steps: [StandardStepModel] = [
]

struct TouchToSelectOneChoiceActivity: View {
@ObservedObject private var stepManager = StepManager(steps: steps)
@StateObject private var stepManager = StepManager(steps: steps)

var body: some View {
stepManager.interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private var steps: [StandardStepModel] = [
]

struct TouchToSelectSixChoicesActivity: View {
@ObservedObject private var stepManager = StepManager(steps: steps)
@StateObject private var stepManager = StepManager(steps: steps)

var body: some View {
stepManager.interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private var steps: [StandardStepModel] = [
]

struct TouchToSelectThreeChoicesActivity: View {
@ObservedObject private var stepManager = StepManager(steps: steps)
@StateObject private var stepManager = StepManager(steps: steps)

var body: some View {
stepManager.interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private var steps: [StandardStepModel] = [
]

struct TouchToSelectThreeChoicesInlineActivity: View {
@ObservedObject private var stepManager = StepManager(steps: steps)
@StateObject private var stepManager = StepManager(steps: steps)

var body: some View {
stepManager.interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private var steps: [StandardStepModel] = [
]

struct TouchToSelectTwoChoicesActivity: View {
@ObservedObject private var stepManager = StepManager(steps: steps)
@StateObject private var stepManager = StepManager(steps: steps)

var body: some View {
stepManager.interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import Combine
import SwiftUI

public class DanceFreezeGameplay {
public class DanceFreezeGameplay : ObservableObject {
var audioPlayer: AudioPlayer
@Published public var progress: CGFloat = 0.0
@Published public var state: GameplayState = .idle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import AudioKit
import Combine
import SwiftUI

public class MelodyGameplay {
public class MelodyGameplay : ObservableObject {
@Published public var progress: CGFloat = 0.0
@Published public var state: GameplayState = .idle

Expand Down

0 comments on commit 889f2a1

Please sign in to comment.