Skip to content

Commit

Permalink
🔀️ Merge branch 'ladislas/feature/gek-add-shuffle-choices'
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Apr 8, 2024
2 parents a2761a6 + fa8ac51 commit 117316b
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,32 @@ public enum DragAndDropIntoZones {
}

public struct Payload: Codable {
// MARK: Lifecycle

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

self.dropZoneA = try container.decode(DropZone.Details.self, forKey: .dropZoneA)
self.dropZoneB = try container.decodeIfPresent(DropZone.Details.self, forKey: .dropZoneB)
self.choices = try container.decode([Choice].self, forKey: .choices)
self.shuffleChoices = try container.decodeIfPresent(Bool.self, forKey: .shuffleChoices) ?? false
}

// MARK: Public

public let dropZoneA: DropZone.Details
public let dropZoneB: DropZone.Details?
public let choices: [Choice]
public let shuffleChoices: Bool

// MARK: Internal

enum CodingKeys: String, CodingKey {
case dropZoneA
case dropZoneB
case choices
case shuffleChoices = "shuffle_choices"
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ extension DragAndDropIntoZonesView {
class ViewModel: ObservableObject {
// MARK: Lifecycle

init(choices: [DragAndDropIntoZones.Choice], shared: ExerciseSharedData? = nil) {
init(choices: [DragAndDropIntoZones.Choice], shuffle: Bool = false, shared: ExerciseSharedData? = nil) {
let gameplayChoiceModel = choices.map { GameplayDragAndDropIntoZonesChoiceModel(choice: $0) }
self.choices = gameplayChoiceModel
self.gameplay = GameplayFindTheRightAnswers(
choices: gameplayChoiceModel)
self.choices = shuffle ? gameplayChoiceModel.shuffled() : gameplayChoiceModel
self.gameplay = GameplayFindTheRightAnswers(choices: gameplayChoiceModel)
self.exercicesSharedData = shared ?? ExerciseSharedData()

self.subscribeToGameplayDragAndDropChoicesUpdates()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public struct DragAndDropIntoZonesView: View {

public init(
choices: [DragAndDropIntoZones.Choice], dropZoneA: DragAndDropIntoZones.DropZone.Details,
dropZoneB: DragAndDropIntoZones.DropZone.Details? = nil
dropZoneB: DragAndDropIntoZones.DropZone.Details? = nil, shuffle: Bool = false
) {
_viewModel = StateObject(wrappedValue: ViewModel(choices: choices))
_viewModel = StateObject(wrappedValue: ViewModel(choices: choices, shuffle: shuffle))
self.dropZoneA = dropZoneA
self.dropZoneB = dropZoneB
}
Expand All @@ -29,7 +29,7 @@ public struct DragAndDropIntoZonesView: View {
}

_viewModel = StateObject(
wrappedValue: ViewModel(choices: payload.choices, shared: data))
wrappedValue: ViewModel(choices: payload.choices, shuffle: payload.shuffleChoices, shared: data))

self.dropZoneA = payload.dropZoneA
self.dropZoneB = payload.dropZoneB
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension DragAndDropToAssociateView {
) {
let gameplayChoiceModel = choices.map { GameplayAssociateCategoriesChoiceModel(choice: $0) }
self.choices = shuffle ? gameplayChoiceModel.shuffled() : gameplayChoiceModel
self.gameplay = GameplayAssociateCategories(choices: gameplayChoiceModel, shuffle: shuffle)
self.gameplay = GameplayAssociateCategories(choices: gameplayChoiceModel)
self.exercicesSharedData = shared ?? ExerciseSharedData()

self.subscribeToGameplayAssociateCategoriesChoicesUpdates()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import SwiftUI
public struct ListenThenTouchToSelectView: View {
// MARK: Lifecycle

public init(choices: [TouchToSelect.Choice], audioRecording: AudioRecording) {
_viewModel = StateObject(wrappedValue: TouchToSelectViewViewModel(choices: choices))
public init(choices: [TouchToSelect.Choice], audioRecording: AudioRecording, shuffle: Bool = false) {
_viewModel = StateObject(wrappedValue: TouchToSelectViewViewModel(choices: choices, shuffle: shuffle))
_audioPlayer = StateObject(wrappedValue: AudioPlayer(audioRecording: audioRecording))
}

Expand All @@ -23,7 +23,7 @@ public struct ListenThenTouchToSelectView: View {
}

_viewModel = StateObject(
wrappedValue: TouchToSelectViewViewModel(choices: payload.choices, shared: data))
wrappedValue: TouchToSelectViewViewModel(choices: payload.choices, shuffle: payload.shuffleChoices, shared: data))

let audioRecording = AudioRecording(name: name, file: name)
_audioPlayer = StateObject(wrappedValue: AudioPlayer(audioRecording: audioRecording))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import SwiftUI
public struct ObserveThenTouchToSelectView: View {
// MARK: Lifecycle

public init(choices: [TouchToSelect.Choice], image: String) {
_viewModel = StateObject(wrappedValue: TouchToSelectViewViewModel(choices: choices))
public init(choices: [TouchToSelect.Choice], image: String, shuffle: Bool = false) {
_viewModel = StateObject(wrappedValue: TouchToSelectViewViewModel(choices: choices, shuffle: shuffle))
self.image = image
}

Expand All @@ -23,7 +23,7 @@ public struct ObserveThenTouchToSelectView: View {
}

_viewModel = StateObject(
wrappedValue: TouchToSelectViewViewModel(choices: payload.choices, shared: data))
wrappedValue: TouchToSelectViewViewModel(choices: payload.choices, shuffle: payload.shuffleChoices, shared: data))

self.image = name
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import SwiftUI
public struct RobotThenTouchToSelectView: View {
// MARK: Lifecycle

public init(choices: [TouchToSelect.Choice]) {
_viewModel = StateObject(wrappedValue: TouchToSelectViewViewModel(choices: choices))
public init(choices: [TouchToSelect.Choice], shuffle: Bool = false) {
_viewModel = StateObject(wrappedValue: TouchToSelectViewViewModel(choices: choices, shuffle: shuffle))

self.actionType = .color("red")
}
Expand All @@ -26,7 +26,7 @@ public struct RobotThenTouchToSelectView: View {
}

_viewModel = StateObject(
wrappedValue: TouchToSelectViewViewModel(choices: payload.choices, shared: data))
wrappedValue: TouchToSelectViewViewModel(choices: payload.choices, shuffle: payload.shuffleChoices, shared: data))

self.actionType = actionType

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct GameplayAssociateCategoriesChoiceModel: GameplayChoiceModelProtocol {
}

extension GameplayAssociateCategories where ChoiceModelType == GameplayAssociateCategoriesChoiceModel {
convenience init(choices: [GameplayAssociateCategoriesChoiceModel], shuffle _: Bool = false, allowedTrials: Int? = nil) {
convenience init(choices: [GameplayAssociateCategoriesChoiceModel], allowedTrials: Int? = nil) {
self.init()
self.choices.send(choices)
state.send(.playing)
Expand Down

0 comments on commit 117316b

Please sign in to comment.