Skip to content

Commit

Permalink
✨ (ContentKit): Activity - Add ability to shuffle exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Nov 15, 2023
1 parent 8d4a20b commit 317df29
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Leka - iOS Monorepo
# Copyright 2023 APF France handicap
# SPDX-License-Identifier: Apache-2.0

id: 6869327315c945dea0966c7ac4673c05
name: Touch To Select - One Right Answer - Colors - Shuffle exercises
description: L'objectif est de trouver la bonne couleur ou des les rassembler par famille
image: activity_color_recognition_1
shuffle_exercises: true
sequence:
- exercises:
- instructions: Touche le rouge
interface: touchToSelect
gameplay: findTheRightAnswers
payload:
choices:
- value: red
type: color
isRightAnswer: true

- instructions: Touche le vert
interface: touchToSelect
gameplay: findTheRightAnswers
payload:
choices:
- value: green
type: color
isRightAnswer: true

- instructions: Touche le bleu
interface: touchToSelect
gameplay: findTheRightAnswers
payload:
choices:
- value: blue
type: color
isRightAnswer: true
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let kActivities: [Activity] = [

ContentKit.decodeActivity("activity-touchToSelect-one_right_answer-colors"),
ContentKit.decodeActivity("activity-touchToSelect-one_right_answer-colors-shuffle_choices"),
ContentKit.decodeActivity("activity-touchToSelect-one_right_answer-colors-shuffle_exercises"),
ContentKit.decodeActivity("activity-touchToSelect-one_right_answer-colors-shuffle_sequences"),
ContentKit.decodeActivity("activity-touchToSelect-one_right_answer-image"),
ContentKit.decodeActivity("activity-touchToSelect-one_right_answer-mixed"),
Expand Down
3 changes: 3 additions & 0 deletions Modules/ContentKit/Sources/Activity/Activity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ public struct Activity: Codable, Identifiable {
public let name: String
public let description: String
public let image: String
public let shuffleExercises: Bool
public let shuffleSequences: Bool
public var sequence: [Exercise.Sequence]

private enum CodingKeys: String, CodingKey {
case id, name, description, image, sequence
case shuffleExercises = "shuffle_exercises"
case shuffleSequences = "shuffle_sequences"
}

Expand All @@ -27,6 +29,7 @@ public struct Activity: Codable, Identifiable {
self.image = try container.decode(String.self, forKey: .image)
self.sequence = try container.decode([Exercise.Sequence].self, forKey: .sequence)

self.shuffleExercises = try container.decodeIfPresent(Bool.self, forKey: .shuffleExercises) ?? false
self.shuffleSequences = try container.decodeIfPresent(Bool.self, forKey: .shuffleSequences) ?? false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@ public class ActivitySequenceManager {

public init(activity: Activity) {
var localActivity = activity

if localActivity.shuffleExercises {
localActivity.sequence = localActivity.sequence.map { sequence in
Exercise.Sequence(exercises: sequence.exercises.shuffled())
}
}

if localActivity.shuffleSequences {
localActivity.sequence.shuffle()
}

self.activity = localActivity
}

Expand Down

0 comments on commit 317df29

Please sign in to comment.