Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hugo/feature/Split generic gameplay into several specific gameplay #317

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: .colorQuest, interface: .oneChoice),
StandardStepModel(choices: choicesStep2, gameplay: .colorQuest, interface: .oneChoice),
StandardStepModel(choices: choicesStep3, gameplay: .colorQuest, interface: .oneChoice),
StandardStepModel(choices: choicesStep4, gameplay: .colorQuest, interface: .oneChoice),
StandardStepModel(choices: choicesStep5, gameplay: .colorQuest, interface: .oneChoice),
]

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

var body: some View {
stepManager.interface
}
}

struct ColorQuest1_Previews: PreviewProvider {
static var previews: some View {
ColorQuest1()
.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: .colorQuest, interface: .twoChoices),
StandardStepModel(choices: choicesStep2, gameplay: .colorQuest, interface: .twoChoices),
StandardStepModel(choices: choicesStep3, gameplay: .colorQuest, interface: .twoChoices),
StandardStepModel(choices: choicesStep4, gameplay: .colorQuest, interface: .twoChoices),
StandardStepModel(choices: choicesStep5, gameplay: .colorQuest, interface: .twoChoices),
]

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

var body: some View {
stepManager.interface
}
}

struct ColorQuest2_Previews: PreviewProvider {
static var previews: some View {
ColorQuest2()
.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: .colorQuest, interface: .threeChoicesInline),
StandardStepModel(choices: choicesStep2, gameplay: .colorQuest, interface: .threeChoicesInline),
StandardStepModel(choices: choicesStep3, gameplay: .colorQuest, interface: .threeChoicesInline),
StandardStepModel(choices: choicesStep4, gameplay: .colorQuest, interface: .threeChoicesInline),
StandardStepModel(choices: choicesStep5, gameplay: .colorQuest, interface: .threeChoicesInline),
]

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

var body: some View {
stepManager.interface
}
}

struct ColorQuest3_Previews: PreviewProvider {
static var previews: some View {
ColorQuest3()
.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: "ColorQuest1",
instructions: "Touch the right color",
view: AnyView(ColorQuest1())
),
ActivityModel(
title: "ColorQuest2",
instructions: "Touch the right color",
view: AnyView(ColorQuest2())
),
ActivityModel(
title: "ColorQuest3",
instructions: "Touch the right color",
view: AnyView(ColorQuest3())
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Leka - iOS Monorepo
// Copyright 2023 APF France handicap
// SPDX-License-Identifier: Apache-2.0

import Combine
import Foundation

public class ColorQuestGameplay: 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)
}

public func setup() {
// 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
}
}
}
}
}
4 changes: 4 additions & 0 deletions Modules/GameEngineKit/Sources/Gameplay/GameplayError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ public class GameplayError: GameplayProtocol {
public var choices = CurrentValueSubject<[ChoiceViewModel], Never>([])
public var state = CurrentValueSubject<GameplayState, Never>(.idle)

public func setup() {
// Nothing to do
}

public func process(choice: ChoiceViewModel) {
// Nothing to do
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public protocol GameplayProtocol: ObservableObject {
var choices: CurrentValueSubject<[ChoiceViewModel], Never> { get set }
var state: CurrentValueSubject<GameplayState, Never> { get set }

func setup()
func process(choice: ChoiceViewModel)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class GameplaySelectAllRightAnswers: GameplayProtocol {
self.state.send(.playing)
}

public func setup() {
// Nothing to do
}

public func process(choice: ChoiceViewModel) {
if choice.rightAnswer {
if let index = choices.value.firstIndex(where: { $0.id == choice.id && $0.status != .playingRightAnimation }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public class GameplaySelectSomeRightAnswers: GameplayProtocol {
self.rightAnswersToFind = rightAnswersToFind
}

public func setup() {
// Nothing to do
}

public func process(choice: ChoiceViewModel) {
if choice.rightAnswer {
if let index = choices.value.firstIndex(where: { $0.id == choice.id && $0.status != .playingRightAnimation }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public class GameplaySelectTheRightAnswer: GameplayProtocol {
self.state.send(.playing)
}

public func setup() {
// Nothing to do
}

public func process(choice: ChoiceViewModel) {
if choice.rightAnswer {
if let index = choices.value.firstIndex(where: { $0.id == choice.id }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public struct ListenFourChoicesView: View {
public init(gameplay: any GameplayProtocol, audioRecording: AudioRecordingModel) {
self.viewModel = GenericViewModel(gameplay: gameplay)
self.audioPlayer = AudioPlayer(audioRecording: audioRecording)
gameplay.setup()
}

public var body: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public struct ListenOneChoiceView: View {
public init(gameplay: any GameplayProtocol, audioRecording: AudioRecordingModel) {
self.viewModel = GenericViewModel(gameplay: gameplay)
self.audioPlayer = AudioPlayer(audioRecording: audioRecording)
gameplay.setup()
}

public var body: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public struct ListenSixChoicesView: View {
public init(gameplay: any GameplayProtocol, audioRecording: AudioRecordingModel) {
self.viewModel = GenericViewModel(gameplay: gameplay)
self.audioPlayer = AudioPlayer(audioRecording: audioRecording)
gameplay.setup()
}

public var body: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public struct ListenThreeChoicesInlineView: View {
public init(gameplay: any GameplayProtocol, audioRecording: AudioRecordingModel) {
self.viewModel = GenericViewModel(gameplay: gameplay)
self.audioPlayer = AudioPlayer(audioRecording: audioRecording)
gameplay.setup()
}

public var body: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public struct ListenThreeChoicesView: View {
public init(gameplay: any GameplayProtocol, audioRecording: AudioRecordingModel) {
self.viewModel = GenericViewModel(gameplay: gameplay)
self.audioPlayer = AudioPlayer(audioRecording: audioRecording)
gameplay.setup()
}

public var body: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public struct ListenTwoChoicesView: View {
public init(gameplay: any GameplayProtocol, audioRecording: AudioRecordingModel) {
self.viewModel = GenericViewModel(gameplay: gameplay)
self.audioPlayer = AudioPlayer(audioRecording: audioRecording)
gameplay.setup()
}

public var body: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public struct FiveChoicesView: View {

public init(gameplay: any GameplayProtocol) {
self.viewModel = GenericViewModel(gameplay: gameplay)
gameplay.setup()
}

public var body: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public struct FourChoicesInlineView: View {

public init(gameplay: any GameplayProtocol) {
self.viewModel = GenericViewModel(gameplay: gameplay)
gameplay.setup()
}

public var body: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public struct FourChoicesView: View {

public init(gameplay: any GameplayProtocol) {
self.viewModel = GenericViewModel(gameplay: gameplay)
gameplay.setup()
}

public var body: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public struct OneChoiceView: View {

public init(gameplay: any GameplayProtocol) {
self.viewModel = GenericViewModel(gameplay: gameplay)
gameplay.setup()
}

public var body: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public struct SixChoicesView: View {

public init(gameplay: any GameplayProtocol) {
self.viewModel = GenericViewModel(gameplay: gameplay)
gameplay.setup()
}

public var body: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public struct ThreeChoicesInlineView: View {

public init(gameplay: any GameplayProtocol) {
self.viewModel = GenericViewModel(gameplay: gameplay)
gameplay.setup()
}

public var body: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public struct ThreeChoicesView: View {

public init(gameplay: any GameplayProtocol) {
self.viewModel = GenericViewModel(gameplay: gameplay)
gameplay.setup()
}

public var body: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public struct TwoChoicesView: View {

public init(gameplay: any GameplayProtocol) {
self.viewModel = GenericViewModel(gameplay: gameplay)
gameplay.setup()
}

public var body: some View {
Expand Down
Loading