-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔀 Merge branch 'hugo/feature/Add-SuperSimon-activity-to-GameEngineKit'
- Loading branch information
Showing
7 changed files
with
257 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
Apps/LekaActivityUIExplorer/Sources/NewUI/Activities/SuperSimon/SuperSimonLevelOne.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// 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), | ||
] | ||
|
||
private let choicesStep2 = [ | ||
ChoiceViewModel(item: "red", type: .color), | ||
ChoiceViewModel(item: "green", type: .color), | ||
] | ||
|
||
private var steps: [StandardStepModel] = [ | ||
StandardStepModel(choices: choicesStep1, gameplay: .superSimon([1]), interface: .twoChoices), | ||
StandardStepModel(choices: choicesStep2, gameplay: .superSimon([1, 0]), interface: .twoChoices), | ||
] | ||
|
||
struct SuperSimonLevelOne: View { | ||
private var stepManager = StepManager(steps: steps) | ||
|
||
var body: some View { | ||
StepView(stepManager: stepManager) | ||
} | ||
} | ||
|
||
struct SuperSimonLevelOne_Previews: PreviewProvider { | ||
static var previews: some View { | ||
SuperSimonLevelOne() | ||
.previewInterfaceOrientation(.landscapeLeft) | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
Apps/LekaActivityUIExplorer/Sources/NewUI/Activities/SuperSimon/SuperSimonLevelThree.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Leka - iOS Monorepo | ||
// Copyright 2023 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import Combine | ||
import GameEngineKit | ||
import SwiftUI | ||
|
||
private let choicesStep1 = [ | ||
ChoiceViewModel(item: "pink", type: .color), | ||
ChoiceViewModel(item: "blue", type: .color), | ||
ChoiceViewModel(item: "purple", type: .color), | ||
ChoiceViewModel(item: "yellow", type: .color), | ||
ChoiceViewModel(item: "green", type: .color), | ||
ChoiceViewModel(item: "red", type: .color), | ||
] | ||
|
||
private let choicesStep2 = [ | ||
ChoiceViewModel(item: "pink", type: .color), | ||
ChoiceViewModel(item: "blue", type: .color), | ||
ChoiceViewModel(item: "purple", type: .color), | ||
ChoiceViewModel(item: "yellow", type: .color), | ||
ChoiceViewModel(item: "green", type: .color), | ||
ChoiceViewModel(item: "red", type: .color), | ||
] | ||
|
||
private let choicesStep3 = [ | ||
ChoiceViewModel(item: "pink", type: .color), | ||
ChoiceViewModel(item: "blue", type: .color), | ||
ChoiceViewModel(item: "purple", type: .color), | ||
ChoiceViewModel(item: "yellow", type: .color), | ||
ChoiceViewModel(item: "green", type: .color), | ||
ChoiceViewModel(item: "red", type: .color), | ||
] | ||
|
||
private let choicesStep4 = [ | ||
ChoiceViewModel(item: "pink", type: .color), | ||
ChoiceViewModel(item: "blue", type: .color), | ||
ChoiceViewModel(item: "purple", type: .color), | ||
ChoiceViewModel(item: "yellow", type: .color), | ||
ChoiceViewModel(item: "green", type: .color), | ||
ChoiceViewModel(item: "red", type: .color), | ||
] | ||
|
||
private let choicesStep5 = [ | ||
ChoiceViewModel(item: "pink", type: .color), | ||
ChoiceViewModel(item: "blue", type: .color), | ||
ChoiceViewModel(item: "purple", type: .color), | ||
ChoiceViewModel(item: "yellow", type: .color), | ||
ChoiceViewModel(item: "green", type: .color), | ||
ChoiceViewModel(item: "red", type: .color), | ||
] | ||
|
||
private let choicesStep6 = [ | ||
ChoiceViewModel(item: "pink", type: .color), | ||
ChoiceViewModel(item: "blue", type: .color), | ||
ChoiceViewModel(item: "purple", type: .color), | ||
ChoiceViewModel(item: "yellow", type: .color), | ||
ChoiceViewModel(item: "green", type: .color), | ||
ChoiceViewModel(item: "red", type: .color), | ||
] | ||
|
||
private var steps: [StandardStepModel] = [ | ||
StandardStepModel(choices: choicesStep1, gameplay: .superSimon([5]), interface: .sixChoices), | ||
StandardStepModel(choices: choicesStep2, gameplay: .superSimon([5, 2]), interface: .sixChoices), | ||
StandardStepModel(choices: choicesStep3, gameplay: .superSimon([5, 2, 4]), interface: .sixChoices), | ||
StandardStepModel(choices: choicesStep4, gameplay: .superSimon([5, 2, 4, 1]), interface: .sixChoices), | ||
StandardStepModel(choices: choicesStep4, gameplay: .superSimon([5, 2, 4, 1, 3]), interface: .sixChoices), | ||
StandardStepModel(choices: choicesStep4, gameplay: .superSimon([5, 2, 4, 1, 3, 0]), interface: .sixChoices), | ||
] | ||
|
||
struct SuperSimonLevelThree: View { | ||
private var stepManager = StepManager(steps: steps) | ||
|
||
var body: some View { | ||
StepView(stepManager: stepManager) | ||
} | ||
} | ||
|
||
struct SuperSimonLevelThree_Previews: PreviewProvider { | ||
static var previews: some View { | ||
SuperSimonLevelThree() | ||
.previewInterfaceOrientation(.landscapeLeft) | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
Apps/LekaActivityUIExplorer/Sources/NewUI/Activities/SuperSimon/SuperSimonLevelTwo.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Leka - iOS Monorepo | ||
// Copyright 2023 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import Combine | ||
import GameEngineKit | ||
import SwiftUI | ||
|
||
private let choicesStep1 = [ | ||
ChoiceViewModel(item: "red", type: .color), | ||
ChoiceViewModel(item: "green", type: .color), | ||
ChoiceViewModel(item: "blue", type: .color), | ||
ChoiceViewModel(item: "yellow", type: .color), | ||
] | ||
|
||
private let choicesStep2 = [ | ||
ChoiceViewModel(item: "red", type: .color), | ||
ChoiceViewModel(item: "green", type: .color), | ||
ChoiceViewModel(item: "blue", type: .color), | ||
ChoiceViewModel(item: "yellow", type: .color), | ||
] | ||
|
||
private let choicesStep3 = [ | ||
ChoiceViewModel(item: "red", type: .color), | ||
ChoiceViewModel(item: "green", type: .color), | ||
ChoiceViewModel(item: "blue", type: .color), | ||
ChoiceViewModel(item: "yellow", type: .color), | ||
] | ||
|
||
private let choicesStep4 = [ | ||
ChoiceViewModel(item: "red", type: .color), | ||
ChoiceViewModel(item: "green", type: .color), | ||
ChoiceViewModel(item: "blue", type: .color), | ||
ChoiceViewModel(item: "yellow", type: .color), | ||
] | ||
|
||
private var steps: [StandardStepModel] = [ | ||
StandardStepModel(choices: choicesStep1, gameplay: .superSimon([0]), interface: .fourChoices), | ||
StandardStepModel(choices: choicesStep2, gameplay: .superSimon([0, 3]), interface: .fourChoices), | ||
StandardStepModel(choices: choicesStep3, gameplay: .superSimon([0, 3, 1]), interface: .fourChoices), | ||
StandardStepModel(choices: choicesStep4, gameplay: .superSimon([0, 3, 1, 2]), interface: .fourChoices), | ||
] | ||
|
||
struct SuperSimonLevelTwo: View { | ||
private var stepManager = StepManager(steps: steps) | ||
|
||
var body: some View { | ||
StepView(stepManager: stepManager) | ||
} | ||
} | ||
|
||
struct SuperSimonLevelTwo_Previews: PreviewProvider { | ||
static var previews: some View { | ||
SuperSimonLevelTwo() | ||
.previewInterfaceOrientation(.landscapeLeft) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
Modules/GameEngineKit/Sources/Gameplay/Specific/SuperSimonGameplay.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Leka - iOS Monorepo | ||
// Copyright 2023 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import Combine | ||
import Foundation | ||
|
||
public class SuperSimonGameplay: GameplayProtocol { | ||
public var choices = CurrentValueSubject<[ChoiceViewModel], Never>([]) | ||
public var state = CurrentValueSubject<GameplayState, Never>(.idle) | ||
|
||
private var rightAnswersGiven: [ChoiceViewModel] = [] | ||
private var answerIndexOrder: [Int] | ||
|
||
public init(choices: [ChoiceViewModel], answerIndexOrder: [Int]) { | ||
self.choices.send(choices) | ||
self.state.send(.playing) | ||
self.answerIndexOrder = answerIndexOrder | ||
|
||
// TODO(@ladislas): Show the right color and song sequence on Leka's belt | ||
for index in 0..<answerIndexOrder.count { | ||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5 * Double(index)) { | ||
let choiceIndex = self.answerIndexOrder[index] | ||
let color = self.choices.value[choiceIndex].item | ||
print("Leka is \(color)") | ||
} | ||
} | ||
} | ||
|
||
public func process(choice: ChoiceViewModel) { | ||
if rightAnswersGiven.count == answerIndexOrder.count { | ||
return | ||
} | ||
if let index = choices.value.firstIndex(where: { $0.id == choice.id && $0.status != .playingRightAnimation } | ||
) { | ||
if index == answerIndexOrder[rightAnswersGiven.count] { | ||
self.choices.value[index].status = .playingRightAnimation | ||
|
||
rightAnswersGiven.append(self.choices.value[index]) | ||
} else { | ||
self.choices.value[index].status = .playingWrongAnimation | ||
|
||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.8) { | ||
self.choices.value[index].status = .notSelected | ||
} | ||
} | ||
} | ||
|
||
if rightAnswersGiven.count == answerIndexOrder.count { | ||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { | ||
for choice in self.choices.value.filter({ $0.status == .playingRightAnimation }) { | ||
guard let index = self.choices.value.firstIndex(where: { $0.id == choice.id }) else { return } | ||
self.choices.value[index].status = .notSelected | ||
} | ||
self.rightAnswersGiven.removeAll() | ||
self.state.send(.finished) | ||
} | ||
// TODO(@ladislas): Run reinforcers and lottie animation | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters