From 80df2243373bdec47422a5251bf10f54ed23b9dc Mon Sep 17 00:00:00 2001 From: Hugo Pezziardi Date: Mon, 8 Apr 2024 16:14:50 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20(GEK):=20Add=20shuffle=20to=20{?= =?UTF-8?q?action}ThenTouchToSelect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - robot - observe - listen --- .../ListenThenTouchToSelectView.swift | 6 +++--- .../ObserveThenTouchToSelect/ObserveThenTouchToSelect.swift | 6 +++--- .../RobotThenTouchToSelect/RobotThenTouchToSelectView.swift | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Modules/GameEngineKit/Sources/Exercises/Touch/ListenThenTouchToSelect/ListenThenTouchToSelectView.swift b/Modules/GameEngineKit/Sources/Exercises/Touch/ListenThenTouchToSelect/ListenThenTouchToSelectView.swift index 171a63baf..70e9f11a7 100644 --- a/Modules/GameEngineKit/Sources/Exercises/Touch/ListenThenTouchToSelect/ListenThenTouchToSelectView.swift +++ b/Modules/GameEngineKit/Sources/Exercises/Touch/ListenThenTouchToSelect/ListenThenTouchToSelectView.swift @@ -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)) } @@ -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)) diff --git a/Modules/GameEngineKit/Sources/Exercises/Touch/ObserveThenTouchToSelect/ObserveThenTouchToSelect.swift b/Modules/GameEngineKit/Sources/Exercises/Touch/ObserveThenTouchToSelect/ObserveThenTouchToSelect.swift index 06c22ef63..04e189a42 100644 --- a/Modules/GameEngineKit/Sources/Exercises/Touch/ObserveThenTouchToSelect/ObserveThenTouchToSelect.swift +++ b/Modules/GameEngineKit/Sources/Exercises/Touch/ObserveThenTouchToSelect/ObserveThenTouchToSelect.swift @@ -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 } @@ -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 } diff --git a/Modules/GameEngineKit/Sources/Exercises/Touch/RobotThenTouchToSelect/RobotThenTouchToSelectView.swift b/Modules/GameEngineKit/Sources/Exercises/Touch/RobotThenTouchToSelect/RobotThenTouchToSelectView.swift index ad14a05d9..ce3676fa5 100644 --- a/Modules/GameEngineKit/Sources/Exercises/Touch/RobotThenTouchToSelect/RobotThenTouchToSelectView.swift +++ b/Modules/GameEngineKit/Sources/Exercises/Touch/RobotThenTouchToSelect/RobotThenTouchToSelectView.swift @@ -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") } @@ -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 From fa8ac51b0e04bd6ecbd01ebe85fca43e17dbcfed Mon Sep 17 00:00:00 2001 From: Hugo Pezziardi Date: Mon, 8 Apr 2024 16:18:22 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=A8=20(GEK):=20Add=20shuffle=20to=20D?= =?UTF-8?q?ragAndDrop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - into zones - to associate --- .../Exercise+DragAndDropIntoZones.swift | 23 +++++++++++++++++++ .../DragAndDropIntoZonesView+ViewModel.swift | 7 +++--- .../IntoZones/DragAndDropIntoZonesView.swift | 6 ++--- ...DragAndDropToAssociateView+ViewModel.swift | 2 +- ...eplayAssociateCategories+DragAndDrop.swift | 2 +- 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/Modules/ContentKit/Sources/Exercise/Exercise+DragAndDropIntoZones.swift b/Modules/ContentKit/Sources/Exercise/Exercise+DragAndDropIntoZones.swift index d75fbb651..fb66c92be 100644 --- a/Modules/ContentKit/Sources/Exercise/Exercise+DragAndDropIntoZones.swift +++ b/Modules/ContentKit/Sources/Exercise/Exercise+DragAndDropIntoZones.swift @@ -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" + } } } diff --git a/Modules/GameEngineKit/Sources/Exercises/DragAndDrop/IntoZones/DragAndDropIntoZonesView+ViewModel.swift b/Modules/GameEngineKit/Sources/Exercises/DragAndDrop/IntoZones/DragAndDropIntoZonesView+ViewModel.swift index 3aa37c127..f155f3878 100644 --- a/Modules/GameEngineKit/Sources/Exercises/DragAndDrop/IntoZones/DragAndDropIntoZonesView+ViewModel.swift +++ b/Modules/GameEngineKit/Sources/Exercises/DragAndDrop/IntoZones/DragAndDropIntoZonesView+ViewModel.swift @@ -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() diff --git a/Modules/GameEngineKit/Sources/Exercises/DragAndDrop/IntoZones/DragAndDropIntoZonesView.swift b/Modules/GameEngineKit/Sources/Exercises/DragAndDrop/IntoZones/DragAndDropIntoZonesView.swift index 23a32dbf2..c9f8f5523 100644 --- a/Modules/GameEngineKit/Sources/Exercises/DragAndDrop/IntoZones/DragAndDropIntoZonesView.swift +++ b/Modules/GameEngineKit/Sources/Exercises/DragAndDrop/IntoZones/DragAndDropIntoZonesView.swift @@ -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 } @@ -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 diff --git a/Modules/GameEngineKit/Sources/Exercises/DragAndDrop/ToAssociate/DragAndDropToAssociateView+ViewModel.swift b/Modules/GameEngineKit/Sources/Exercises/DragAndDrop/ToAssociate/DragAndDropToAssociateView+ViewModel.swift index 557a599a6..c155d84d9 100644 --- a/Modules/GameEngineKit/Sources/Exercises/DragAndDrop/ToAssociate/DragAndDropToAssociateView+ViewModel.swift +++ b/Modules/GameEngineKit/Sources/Exercises/DragAndDrop/ToAssociate/DragAndDropToAssociateView+ViewModel.swift @@ -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() diff --git a/Modules/GameEngineKit/Sources/Gameplays/AssociateCategories/GameplayAssociateCategories+DragAndDrop.swift b/Modules/GameEngineKit/Sources/Gameplays/AssociateCategories/GameplayAssociateCategories+DragAndDrop.swift index d94d8cba0..5ec14f971 100644 --- a/Modules/GameEngineKit/Sources/Gameplays/AssociateCategories/GameplayAssociateCategories+DragAndDrop.swift +++ b/Modules/GameEngineKit/Sources/Gameplays/AssociateCategories/GameplayAssociateCategories+DragAndDrop.swift @@ -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)