Skip to content

Commit

Permalink
🔀 Merge branch 'hugo/feature/Convert-old-DnD-activity-to-new-architec…
Browse files Browse the repository at this point in the history
…ture'
  • Loading branch information
ladislas committed Nov 2, 2023
2 parents 029f877 + cdf2832 commit 5cd983b
Show file tree
Hide file tree
Showing 30 changed files with 700 additions and 35 deletions.
17 changes: 9 additions & 8 deletions Modules/ContentKit/Sources/Activity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public struct Exercise: Codable {
case touchToSelect
case listenThenTouchToSelect
case observeThenTouchToSelect
case dragAndDrop
}
}

Expand All @@ -66,13 +67,13 @@ public enum ExercisePayload: Codable {
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CustomKeys.self)

// ? Drag and drop
// TODO(@ladislas): not working, implement real logic
if container.allKeys.contains(.dropZoneA) {
if let payload = try? container.decode(DragAndDropPayload.self, forKey: .dropZoneA) {
self = .dragAndDrop(payload)
return
}
let dropZoneA = try container.decode(DropZoneDetails.self, forKey: .dropZoneA)
let dropZoneB = try container.decodeIfPresent(DropZoneDetails.self, forKey: .dropZoneB)
let choices = try container.decode([DragAndDropChoice].self, forKey: .choices)

self = .dragAndDrop(DragAndDropPayload(dropZoneA: dropZoneA, dropZoneB: dropZoneB, choices: choices))
return
}

// ? Selection
Expand Down Expand Up @@ -102,7 +103,7 @@ public enum ExercisePayload: Codable {
}

private enum CustomKeys: String, CodingKey {
case choices, dropZoneA, payload, media
case choices, dropZoneA, dropZoneB, payload, media
case shuffleChoices = "shuffle_choices"
}
}
Expand Down Expand Up @@ -156,7 +157,7 @@ public struct DropZoneDetails: Codable {
public struct DragAndDropChoice: Codable {
public let value: String
public let type: UIElementType
public let dropZone: ChoiceDropZone
public let dropZone: ChoiceDropZone?

public enum ChoiceDropZone: String, Codable {
case zoneA
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Leka - iOS Monorepo
# Copyright 2023 APF France handicap
# SPDX-License-Identifier: Apache-2.0

id: 1c8816781e4d4fb5a9edd911c1ca92de
name: Drag And Drop - One Zone - One Right Answer - Image
description: L'objectif est de placer la bonne image dans la zone
image: activity_image_recognition_1
sequence:
- exercises:
- instructions: Place le bon instrument dans le panier
type: dragAndDrop
interface: dragAndDrop
gameplay: selectAllRightAnswers
payload:
dropZoneA:
value: basket
type: image
choices:
- value: image-instrument-drums-no_background
type: image
dropZone: zoneA
- value: image-instrument-guitar-no_background
type: image

- instructions: Place le bon instrument dans le panier
type: dragAndDrop
interface: dragAndDrop
gameplay: selectAllRightAnswers
payload:
dropZoneA:
value: basket
type: image
choices:
- value: image-instrument-drums-no_background
type: image
- value: image-instrument-piano-no_background
type: image
- value: image-instrument-saxophone-no_background
type: image
dropZone: zoneA

- instructions: Place le bon instrument dans le panier
type: dragAndDrop
interface: dragAndDrop
gameplay: selectAllRightAnswers
payload:
dropZoneA:
value: basket
type: image
choices:
- value: image-instrument-harmonica-no_background
type: image
- value: image-instrument-flute-no_background
type: image
dropZone: zoneA
- value: image-instrument-violin-no_background
type: image
- value: image-instrument-piano-no_background
type: image
- value: image-instrument-guitar-no_background
type: image



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

id: 51344a2077d14d6b9e9e1e40f525eada
name: Drag And Drop - Two Zone - Multiple Right Answers - Image
description: L'objectif est de placer les images dans la bonne zone
image: activity_image_recognition_1
sequence:
- exercises:
- instructions: Place les instruments dans les bonnes familles d'instruments
type: dragAndDrop
interface: dragAndDrop
gameplay: selectAllRightAnswers
payload:
dropZoneA:
value: image-placeholder-instruments_wind
type: image
dropZoneB:
value: image-placeholder-instruments_string
type: image
choices:
- value: image-instrument-violin-no_background
type: image
dropZone: zoneB
- value: image-instrument-guitar-no_background
type: image
dropZone: zoneB
- value: image-instrument-flute-no_background
type: image
dropZone: zoneA


- instructions: Place les instruments dans les bonnes familles d'instruments
type: dragAndDrop
interface: dragAndDrop
gameplay: selectAllRightAnswers
payload:
dropZoneA:
value: image-placeholder-instruments_wind
type: image
dropZoneB:
value: image-placeholder-instruments_string
type: image
choices:
- value: image-instrument-harmonica-no_background
type: image
dropZone: zoneA
- value: image-instrument-piano-no_background
type: image
dropZone: zoneB
- value: image-instrument-saxophone-no_background
type: image
dropZone: zoneA

- instructions: Place les instruments dans les bonnes familles d'instruments
type: dragAndDrop
interface: dragAndDrop
gameplay: selectAllRightAnswers
payload:
dropZoneA:
value: image-placeholder-instruments_wind
type: image
dropZoneB:
value: image-placeholder-instruments_string
type: image
choices:
- value: image-instrument-harmonica-no_background
type: image
dropZone: zoneA
- value: image-instrument-flute-no_background
type: image
dropZone: zoneA
- value: image-instrument-violin-no_background
type: image
dropZone: zoneB
- value: image-instrument-piano-no_background
type: image
dropZone: zoneB
- value: image-instrument-guitar-no_background
type: image
dropZone: zoneB



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.
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.
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 @@ -24,7 +24,7 @@ let kActivities: [Activity] = [
ContentKit.decodeActivity("activity-listenThenTouchToSelect-mixed-images"),
ContentKit.decodeActivity("activity-observeThenTouchToSelect-mixed-colors"),

// ContentKit.decodeActivity("activity-dragAndDrop-one_zone-one_right_answer-image"),
ContentKit.decodeActivity("activity-dragAndDrop-one_zone-one_right_answer-image"),
// ContentKit.decodeActivity("activity-dragAndDrop-one_zone-one_right_answer-colors"),
// ContentKit.decodeActivity("activity-dragAndDrop-one_zone-one_right_answer-mixed"),
// ContentKit.decodeActivity("activity-dragAndDrop-one_zone-multiple_right_answer-images"),
Expand All @@ -34,7 +34,7 @@ let kActivities: [Activity] = [
// ContentKit.decodeActivity("activity-dragAndDrop-two_zones-one_right_answer-image"),
// ContentKit.decodeActivity("activity-dragAndDrop-two_zones-one_right_answer-colors"),
// ContentKit.decodeActivity("activity-dragAndDrop-two_zones-one_right_answer-mixed"),
// ContentKit.decodeActivity("activity-dragAndDrop-two_zones-multiple_right_answer-images"),
ContentKit.decodeActivity("activity-dragAndDrop-two_zones-multiple_right_answers-images"),
// ContentKit.decodeActivity("activity-dragAndDrop-two_zones-multiple_right_answer-colors"),
// ContentKit.decodeActivity("activity-dragAndDrop-two_zones-multiple_right_answer-mixed"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import Combine
import SpriteKit
import SwiftUI

class DragAndDropBaseScene: SKScene {
class DragAndDropBaseSceneDeprecated: SKScene {
var viewModel: DragAndDropZoneViewModel
var hints: Bool
var biggerSide: CGFloat = 130
var selectedNodes: [UITouch: DraggableImageAnswerNode] = [:]
var playedNode: DraggableImageAnswerNode?
var selectedNodes: [UITouch: DraggableImageAnswerNodeDeprecated] = [:]
var playedNode: DraggableImageAnswerNodeDeprecated?
var dropZonesNode: [SKSpriteNode] = []
private var spacer: CGFloat = .zero
private var defaultPosition = CGPoint.zero
Expand Down Expand Up @@ -62,11 +62,11 @@ class DragAndDropBaseScene: SKScene {

@MainActor func layoutAnswers() {
for choice in viewModel.choices {
let draggableImageAnswerNode = DraggableImageAnswerNode(
let draggableImageAnswerNode = DraggableImageAnswerNodeDeprecated(
choice: choice,
position: self.defaultPosition
)
let draggableImageShadowNode = DraggableImageShadowNode(
let draggableImageShadowNode = DraggableImageShadowNodeDeprecated(
draggableImageAnswerNode: draggableImageAnswerNode
)

Expand Down Expand Up @@ -131,7 +131,7 @@ class DragAndDropBaseScene: SKScene {
}
}

func goodAnswerBehavior(_ node: DraggableImageAnswerNode) {
func goodAnswerBehavior(_ node: DraggableImageAnswerNodeDeprecated) {
node.scaleForMax(sizeOf: biggerSide * 0.8)
node.zPosition = 10
node.isDraggable = false
Expand All @@ -143,7 +143,7 @@ class DragAndDropBaseScene: SKScene {
}
}

func wrongAnswerBehavior(_ node: DraggableImageAnswerNode) {
func wrongAnswerBehavior(_ node: DraggableImageAnswerNodeDeprecated) {
let moveAnimation: SKAction = SKAction.move(to: node.defaultPosition!, duration: 0.25)
.moveAnimation(.easeOut)
let group: DispatchGroup = DispatchGroup()
Expand Down Expand Up @@ -184,7 +184,7 @@ class DragAndDropBaseScene: SKScene {
override func touchesBegan(_ touches: Set<UITouch>, with: UIEvent?) {
for touch in touches {
let location = touch.location(in: self)
if let node = self.atPoint(location) as? DraggableImageAnswerNode {
if let node = self.atPoint(location) as? DraggableImageAnswerNodeDeprecated {
for choice in viewModel.choices where node.name == choice.value && node.isDraggable {
selectedNodes[touch] = node
onDragAnimation(node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Combine
import SpriteKit
import SwiftUI

final class DragAndDropOneZoneOneOrMoreChoicesScene: DragAndDropBaseScene {
final class DragAndDropOneZoneOneOrMoreChoicesSceneDeprecated: DragAndDropBaseSceneDeprecated {
override func layoutDropZones(dropZones: [DragAndDropZoneModel]) {
let dropZoneNode = SKSpriteNode()
let dropZoneSize = CGSize(width: 380, height: 280)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import SpriteKit
import SwiftUI

public struct DragAndDropOneZoneOneOrMoreChoicesView: View {
public struct DragAndDropOneZoneOneOrMoreChoicesViewDeprecated: View {
@StateObject private var viewModel: DragAndDropZoneViewModel
@State private var scene: SKScene = SKScene()
let hints: Bool
Expand All @@ -23,14 +23,14 @@ public struct DragAndDropOneZoneOneOrMoreChoicesView: View {
)
.frame(width: proxy.size.width, height: proxy.size.height)
.onAppear {
scene = DragAndDropOneZoneOneOrMoreChoicesScene(viewModel: viewModel, hints: hints)
scene = DragAndDropOneZoneOneOrMoreChoicesSceneDeprecated(viewModel: viewModel, hints: hints)
}
}
.edgesIgnoringSafeArea(.horizontal)
}

private func makeScene(size: CGSize) -> SKScene {
guard let finalScene = scene as? DragAndDropBaseScene else {
guard let finalScene = scene as? DragAndDropBaseSceneDeprecated else {
return SKScene()
}
finalScene.size = CGSize(width: size.width, height: size.height)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Combine
import SpriteKit
import SwiftUI

final class DragAndDropTwoZonesOneOrMoreChoicesScene: DragAndDropBaseScene {
final class DragAndDropTwoZonesOneOrMoreChoicesSceneDeprecated: DragAndDropBaseSceneDeprecated {
override func layoutDropZones(dropZones: [DragAndDropZoneModel]) {
let dropAreaSpacer = size.width / 4
var dropAreaPosition = dropAreaSpacer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import SpriteKit
import SwiftUI

public struct DragAndDropTwoZonesOneOrMoreChoicesView: View {
public struct DragAndDropTwoZonesOneOrMoreChoicesViewDeprecated: View {
@StateObject private var viewModel: DragAndDropZoneViewModel
@State private var scene: SKScene = SKScene()
let hints: Bool
Expand All @@ -23,14 +23,14 @@ public struct DragAndDropTwoZonesOneOrMoreChoicesView: View {
)
.frame(width: proxy.size.width, height: proxy.size.height)
.onAppear {
scene = DragAndDropTwoZonesOneOrMoreChoicesScene(viewModel: viewModel, hints: hints)
scene = DragAndDropTwoZonesOneOrMoreChoicesSceneDeprecated(viewModel: viewModel, hints: hints)
}
}
.edgesIgnoringSafeArea(.horizontal)
}

private func makeScene(size: CGSize) -> SKScene {
guard let finalScene = scene as? DragAndDropBaseScene else {
guard let finalScene = scene as? DragAndDropBaseSceneDeprecated else {
return SKScene()
}
finalScene.size = CGSize(width: size.width, height: size.height)
Expand Down
4 changes: 2 additions & 2 deletions Modules/GameEngineKit/Sources/StepViewViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ public class StepViewViewModel: ObservableObject {
ListenSixChoicesView(
gameplay: currentGameplay as! SelectionGameplayProtocol, audioRecording: audioRecording)
case .dragAndDropOneZoneOneOrMoreChoices(let hints):
DragAndDropOneZoneOneOrMoreChoicesView(
DragAndDropOneZoneOneOrMoreChoicesViewDeprecated(
gameplay: currentGameplay as! DragAndDropGameplayProtocol, hints: hints)
case .dragAndDropTwoZonesOneOrMoreChoices(let hints):
DragAndDropTwoZonesOneOrMoreChoicesView(
DragAndDropTwoZonesOneOrMoreChoicesViewDeprecated(
gameplay: currentGameplay as! DragAndDropGameplayProtocol, hints: hints)
}
}
Expand Down
Loading

0 comments on commit 5cd983b

Please sign in to comment.