Skip to content

Commit

Permalink
🔀 Merge branch 'hugo/feature/Add-ColorQuest-gameplay'
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Oct 6, 2023
2 parents 26e17c6 + 2e51183 commit bd4f5e2
Show file tree
Hide file tree
Showing 7 changed files with 226 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Leka - iOS Monorepo
// Copyright 2023 APF France handicap
// SPDX-License-Identifier: Apache-2.0

import GameEngineKit
import SwiftUI

private let choicesStep1 = [
ChoiceViewModel(item: "blue", type: .color, rightAnswer: true)
]

private let choicesStep2 = [
ChoiceViewModel(item: "green", type: .color, rightAnswer: true)
]

private let choicesStep3 = [
ChoiceViewModel(item: "pink", type: .color, rightAnswer: true)
]

private let choicesStep4 = [
ChoiceViewModel(item: "yellow", type: .color, rightAnswer: true)
]

private let choicesStep5 = [
ChoiceViewModel(item: "red", type: .color, rightAnswer: true)

]

private var steps: [StandardStepModel] = [
StandardStepModel(choices: choicesStep1, gameplay: .colorBingo, interface: .oneChoice),
StandardStepModel(choices: choicesStep2, gameplay: .colorBingo, interface: .oneChoice),
StandardStepModel(choices: choicesStep3, gameplay: .colorBingo, interface: .oneChoice),
StandardStepModel(choices: choicesStep4, gameplay: .colorBingo, interface: .oneChoice),
StandardStepModel(choices: choicesStep5, gameplay: .colorBingo, interface: .oneChoice),
]

struct ColorBingoLevelOne: View {
private var stepManager = StepManager(steps: steps)

var body: some View {
StepView(stepManager: stepManager)
}
}

struct ColorBingoLevelOne_Previews: PreviewProvider {
static var previews: some View {
ColorBingoLevelOne()
.previewInterfaceOrientation(.landscapeLeft)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Leka - iOS Monorepo
// Copyright 2023 APF France handicap
// SPDX-License-Identifier: Apache-2.0

import GameEngineKit
import SwiftUI

private let choicesStep1 = [
ChoiceViewModel(item: "red", type: .color),
ChoiceViewModel(item: "blue", type: .color, rightAnswer: true),
ChoiceViewModel(item: "yellow", type: .color),
]

private let choicesStep2 = [
ChoiceViewModel(item: "purple", type: .color),
ChoiceViewModel(item: "green", type: .color),
ChoiceViewModel(item: "blue", type: .color, rightAnswer: true),
]

private let choicesStep3 = [
ChoiceViewModel(item: "yellow", type: .color, rightAnswer: true),
ChoiceViewModel(item: "blue", type: .color),
ChoiceViewModel(item: "red", type: .color),
]

private let choicesStep4 = [
ChoiceViewModel(item: "green", type: .color),
ChoiceViewModel(item: "pink", type: .color),
ChoiceViewModel(item: "yellow", type: .color, rightAnswer: true),
]

private let choicesStep5 = [
ChoiceViewModel(item: "red", type: .color, rightAnswer: true),
ChoiceViewModel(item: "blue", type: .color),
ChoiceViewModel(item: "yellow", type: .color),
]

private var steps: [StandardStepModel] = [
StandardStepModel(choices: choicesStep1, gameplay: .colorBingo, interface: .threeChoicesInline),
StandardStepModel(choices: choicesStep2, gameplay: .colorBingo, interface: .threeChoicesInline),
StandardStepModel(choices: choicesStep3, gameplay: .colorBingo, interface: .threeChoicesInline),
StandardStepModel(choices: choicesStep4, gameplay: .colorBingo, interface: .threeChoicesInline),
StandardStepModel(choices: choicesStep5, gameplay: .colorBingo, interface: .threeChoicesInline),
]

struct ColorBingoLevelThree: View {
private var stepManager = StepManager(steps: steps)

var body: some View {
StepView(stepManager: stepManager)
}
}

struct ColorBingoLevelThree_Previews: PreviewProvider {
static var previews: some View {
ColorBingoLevelThree()
.previewInterfaceOrientation(.landscapeLeft)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Leka - iOS Monorepo
// Copyright 2023 APF France handicap
// SPDX-License-Identifier: Apache-2.0

import GameEngineKit
import SwiftUI

private let choicesStep1 = [
ChoiceViewModel(item: "red", type: .color),
ChoiceViewModel(item: "green", type: .color, rightAnswer: true),
]

private let choicesStep2 = [
ChoiceViewModel(item: "purple", type: .color),
ChoiceViewModel(item: "blue", type: .color, rightAnswer: true),
]

private let choicesStep3 = [
ChoiceViewModel(item: "yellow", type: .color, rightAnswer: true),
ChoiceViewModel(item: "red", type: .color),
]

private let choicesStep4 = [
ChoiceViewModel(item: "pink", type: .color),
ChoiceViewModel(item: "yellow", type: .color, rightAnswer: true),
]

private let choicesStep5 = [
ChoiceViewModel(item: "red", type: .color, rightAnswer: true),
ChoiceViewModel(item: "green", type: .color),
]

private var steps: [StandardStepModel] = [
StandardStepModel(choices: choicesStep1, gameplay: .colorBingo, interface: .twoChoices),
StandardStepModel(choices: choicesStep2, gameplay: .colorBingo, interface: .twoChoices),
StandardStepModel(choices: choicesStep3, gameplay: .colorBingo, interface: .twoChoices),
StandardStepModel(choices: choicesStep4, gameplay: .colorBingo, interface: .twoChoices),
StandardStepModel(choices: choicesStep5, gameplay: .colorBingo, interface: .twoChoices),
]

struct ColorBingoLevelTwo: View {
private var stepManager = StepManager(steps: steps)

var body: some View {
StepView(stepManager: stepManager)
}
}

struct ColorBingoLevelTwo_Previews: PreviewProvider {
static var previews: some View {
ColorBingoLevelTwo()
.previewInterfaceOrientation(.landscapeLeft)
}
}
15 changes: 15 additions & 0 deletions Apps/LekaActivityUIExplorer/Sources/NewUI/Data/ActivityList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,19 @@ let kListOfAvailablesActivities: [ActivityModel] = [
instructions: "Start sequence and observe the user's behavior interacting with Leka",
view: AnyView(PairingActivity())
),
ActivityModel(
title: "ColorBingo - Lvl 1",
instructions: "Touch the right color",
view: AnyView(ColorBingoLevelOne())
),
ActivityModel(
title: "ColorBingo - Lvl 2",
instructions: "Touch the right color",
view: AnyView(ColorBingoLevelTwo())
),
ActivityModel(
title: "ColorBingo - Lvl 3",
instructions: "Touch the right color",
view: AnyView(ColorBingoLevelThree())
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Leka - iOS Monorepo
// Copyright 2023 APF France handicap
// SPDX-License-Identifier: Apache-2.0

import Combine
import Foundation

public class ColorBingoGameplay: GameplayProtocol {
public var choices = CurrentValueSubject<[ChoiceViewModel], Never>([])
public var state = CurrentValueSubject<GameplayState, Never>(.idle)

public init(choices: [ChoiceViewModel]) {
self.choices.send(choices)
self.state.send(.playing)

// TODO(@ladislas): Show the right answer color on Leka's belt
let index = self.choices.value.firstIndex(where: { $0.rightAnswer })!
let color = self.choices.value[index].item
print("Leka is \(color)")
}

public func process(choice: ChoiceViewModel) {
if choice.rightAnswer {
if let index = choices.value.firstIndex(where: { $0.id == choice.id }) {
self.choices.value[index].status = .playingRightAnimation

// TO DO (@hugo) asyncAwait
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
self.choices.value[index].status = .notSelected
self.state.send(.finished)
}
// TODO(@ladislas): Run reinforcers and lottie animation
}
} else {
if let index = choices.value.firstIndex(where: { $0.id == choice.id }) {
self.choices.value[index].status = .playingWrongAnimation

// TO DO (@hugo) asyncAwait
DispatchQueue.main.asyncAfter(deadline: .now() + 0.8) {
self.choices.value[index].status = .notSelected
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public enum GameplayType {
case selectTheRightAnswer
case selectAllRightAnswers
case selectSomeRightAnswers(Int)
case colorBingo
}

public enum InterfaceType {
Expand Down
2 changes: 2 additions & 0 deletions Modules/GameEngineKit/Sources/StepViewViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class StepViewViewModel: ObservableObject {
case .selectSomeRightAnswers(let answersNumber):
return GameplaySelectSomeRightAnswers(
choices: stepModel.choices, rightAnswersToFind: answersNumber)
case .colorBingo:
return ColorBingoGameplay(choices: stepModel.choices)
}
}

Expand Down

0 comments on commit bd4f5e2

Please sign in to comment.