Skip to content

Commit

Permalink
🔀 Merge branch 'REVIEW+ladislas+hugo/feature/GEK-Handle-others-interf…
Browse files Browse the repository at this point in the history
…ace-type'
  • Loading branch information
ladislas committed Oct 27, 2023
2 parents 7c250c7 + b076595 commit ce57826
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Leka - iOS Monorepo
# Copyright 2023 APF France handicap
# SPDX-License-Identifier: Apache-2.0

id: 6be7fcc5e32942d5804ec336ef127d03
name: Touch To Select - One Right Answer - Image
description: L'objectif est de trouver la bonne image ou des les rassembler par famille
image: activity_image_recognition_1
sequence:
- exercises:
- instructions: Touche les animaux
type: selection
interface: touchToSelect
gameplay: selectAllRightAnswers
payload:
choices:
- value: image-placeholder-animals
type: image
isRightAnswer: true

- instructions: Touche le portrait
type: selection
interface: touchToSelect
gameplay: selectAllRightAnswers
payload:
choices:
- value: image-placeholder-food
type: image
- value: image-placeholder-portrait
type: image
isRightAnswer: true

- instructions: Touche le paysage
type: selection
interface: touchToSelect
gameplay: selectAllRightAnswers
payload:
choices:
- value: image-placeholder-landscape
type: image
isRightAnswer: true
- value: image-placeholder-animals
type: image
- value: image-placeholder-food
type: image

- instructions: Touche la nourriture
type: selection
interface: touchToSelect
gameplay: selectAllRightAnswers
payload:
choices:
- value: image-placeholder-animals
type: image
- value: image-placeholder-portrait
type: image
- value: image-placeholder-food
type: image
isRightAnswer: true
- value: image-placeholder-landscape
type: image

- instructions: Touche les animaux
type: selection
interface: touchToSelect
gameplay: selectAllRightAnswers
payload:
choices:
- value: image-placeholder-animals
type: image
- value: image-placeholder-food
type: image
isRightAnswer: true
- value: image-placeholder-landscape
type: image
- value: image-placeholder-portrait
type: image
- value: image-placeholder-food
type: image

- instructions: Touche le portrait
type: selection
interface: touchToSelect
gameplay: selectAllRightAnswers
payload:
choices:
- value: image-placeholder-animals
type: image
- value: image-placeholder-food
type: image
- value: image-placeholder-landscape
type: image
- value: image-placeholder-food
type: image
- value: image-placeholder-portrait
type: image
isRightAnswer: true
- value: image-placeholder-animals
type: image
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

id: 9a5431d4a5084ce4abc48109f90b8504
name: Touch To Select - One Right Answer - Mixed
description: L'objectif est de trouver la bonne réponse ou des les rassembler par famille
image: activity_mixed_recognition_1
sequence:
- exercises:
- instructions: Touche l'image
type: selection
interface: touchToSelect
gameplay: selectAllRightAnswers
payload:
choices:
- value: image-placeholder-food
type: image
isRightAnswer: true
- value: blue
type: color

- instructions: Touche les images
type: selection
interface: touchToSelect
gameplay: selectAllRightAnswers
payload:
choices:
- value: blue
type: color
isRightAnswer: true
- value: image-placeholder-animals
type: image
- value: green
type: color
- value: image-placeholder-portrait
type: image
isRightAnswer: true

- instructions: Touche toutes les items
type: selection
interface: touchToSelect
gameplay: selectAllRightAnswers
payload:
choices:
- value: blue
type: color
isRightAnswer: true
- value: image-placeholder-food
type: image
isRightAnswer: true
- value: green
type: color
isRightAnswer: true
- value: image-placeholder-landscape
type: image
isRightAnswer: true
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ let kActivities: [Activity] = [
// ? dragAndDrop: activity-dragAndDrop-<number_of_zones>-<number_of_answers>-<answer_type>

ContentKit.decodeActivity("activity-touchToSelect-one_right_answer-colors"),
// ContentKit.decodeActivity("activity-touchToSelect-one_right_answer-image"),
ContentKit.decodeActivity("activity-touchToSelect-one_right_answer-image"),
ContentKit.decodeActivity("activity-touchToSelect-one_right_answer-mixed"),
// ContentKit.decodeActivity("activity-touchToSelect-multipe_right_answers-mixed"),
// ContentKit.decodeActivity("activity-touchToSelect-multipe_right_answers-colors"),
// ContentKit.decodeActivity("activity-touchToSelect-multipe_right_answers-images"),
Expand Down
117 changes: 117 additions & 0 deletions Modules/GameEngineKit/Sources/_NewSystem/Views/ChoiceImageView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Leka - iOS Monorepo
// Copyright 2023 APF France handicap
// SPDX-License-Identifier: Apache-2.0

//import Combine
import ContentKit
import RobotKit
import SwiftUI

struct ChoiceImageView: View {

private let image: String
private let size: CGFloat
private let state: GameplayChoiceState
private let kOverLayScaleFactor: CGFloat = 1.08

@State private var animationPercent: CGFloat = .zero
@State private var overlayOpacity: CGFloat = .zero

init(image: String, size: CGFloat, state: GameplayChoiceState = .idle) {
self.image = image
self.size = size
self.state = state
}

@ViewBuilder
var circle: some View {
if let uiImage = UIImage(named: image) {
Image(uiImage: uiImage)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(
width: size,
height: size
)
.clipShape(Circle())
} else {
Text("\nImage not found:\n\(image)")
.multilineTextAlignment(.center)
.frame(
width: size,
height: size
)
.overlay {
Circle()
.stroke(Color.red, lineWidth: 5)
}
}
}

var body: some View {
switch state {
case .idle:
circle
.onAppear {
withAnimation {
animationPercent = 0.0
overlayOpacity = 0.0
}
}

case .rightAnswer:
circle
.overlay {
RightAnswerFeedback(animationPercent: animationPercent)
.frame(
width: size * kOverLayScaleFactor,
height: size * kOverLayScaleFactor
)
}
.onAppear {
withAnimation {
animationPercent = 1.0
}
}

case .wrongAnswer:
circle
.overlay {
WrongAnswerFeedback(overlayOpacity: overlayOpacity)
.frame(
width: size * kOverLayScaleFactor,
height: size * kOverLayScaleFactor
)
}
.onAppear {
withAnimation {
overlayOpacity = 0.8
}
}
}
}

}

#Preview {
VStack(spacing: 30) {
HStack(spacing: 50) {
ChoiceImageView(image: "image-placeholder-animals", size: 200)
ChoiceImageView(image: "image-placeholder-missing", size: 200)
}

HStack(spacing: 50) {
ChoiceImageView(image: "image-placeholder-animals", size: 200)
ChoiceImageView(image: "image-placeholder-animals", size: 200, state: .rightAnswer)
ChoiceImageView(image: "image-placeholder-animals", size: 200, state: .wrongAnswer)
}

HStack(spacing: 0) {
ChoiceImageView(image: "image-placeholder-animals", size: 200)
ChoiceColorView(color: "blue", size: 200)

ChoiceImageView(image: "image-placeholder-animals", size: 200, state: .rightAnswer)
ChoiceColorView(color: "blue", size: 200, state: .rightAnswer)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct SelectionChoiceView: View {
}

var body: some View {
// TODO(@ladislas): Add image and text
// TODO(@ladislas): Add text
switch choice.type {
case .color:
ChoiceColorView(color: choice.value, size: size, state: state)
Expand All @@ -34,6 +34,13 @@ struct SelectionChoiceView: View {
.fill(isTappable ? .clear : .white.opacity(0.6))
)
.animation(.easeOut(duration: 0.3), value: isTappable)
case .image:
ChoiceImageView(image: choice.value, size: size, state: state)
.overlay(
Circle()
.fill(isTappable ? .clear : .white.opacity(0.6))
)
.animation(.easeOut(duration: 0.3), value: isTappable)

default:
Text("ERROR")
Expand Down

0 comments on commit ce57826

Please sign in to comment.