Skip to content

Commit

Permalink
🔀 Merge branch 'hugo/feature/Make-DnD-nodes-not-grabbable-on-gameplay…
Browse files Browse the repository at this point in the history
…-completed'
  • Loading branch information
ladislas committed Nov 3, 2023
2 parents 3e9e42e + 3a66de2 commit c1a412f
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Copyright 2023 APF France handicap
// SPDX-License-Identifier: Apache-2.0

import ContentKit
import Combine
import ContentKit
import SpriteKit
import SwiftUI

Expand All @@ -14,14 +14,17 @@ class DragAndDropBaseScene: SKScene {
var dropZoneB: DropZoneDetails?
var biggerSide: CGFloat = 130
var selectedNodes: [UITouch: DraggableImageAnswerNode] = [:]
var answerNodes: [DraggableImageAnswerNode] = []
var playedNode: DraggableImageAnswerNode?
var dropZoneNodes: [SKSpriteNode] = []
private var spacer: CGFloat = .zero
private var defaultPosition = CGPoint.zero
private var expectedItemsNodes: [String: [SKSpriteNode]] = [:]
private var cancellables: Set<AnyCancellable> = []

init(viewModel: DragAndDropViewViewModel, hints: Bool, dropZoneA: DropZoneDetails, dropZoneB: DropZoneDetails? = nil) {
init(
viewModel: DragAndDropViewViewModel, hints: Bool, dropZoneA: DropZoneDetails, dropZoneB: DropZoneDetails? = nil
) {
self.viewModel = viewModel
self.hints = hints
self.dropZoneA = dropZoneA
Expand All @@ -42,7 +45,6 @@ class DragAndDropBaseScene: SKScene {
self.removeAllChildren()
self.removeAllActions()


setFirstAnswerPosition()
if let dropZoneB = dropZoneB {
layoutDropZones(dropZones: dropZoneA, dropZoneB)
Expand All @@ -53,6 +55,12 @@ class DragAndDropBaseScene: SKScene {
layoutAnswers()
}

func exerciseCompletedBehavior() {
for node in answerNodes {
node.isDraggable = false
}
}

func subscribeToChoicesUpdates() {
self.viewModel.$choices
.receive(on: DispatchQueue.main)
Expand Down Expand Up @@ -82,6 +90,8 @@ class DragAndDropBaseScene: SKScene {
bindNodesToSafeArea([draggableImageAnswerNode, draggableImageShadowNode])
setNextAnswerPosition()

answerNodes.append(draggableImageAnswerNode)

addChild(draggableImageShadowNode)
addChild(draggableImageAnswerNode)
}
Expand Down Expand Up @@ -144,7 +154,7 @@ class DragAndDropBaseScene: SKScene {
onDropAction(node)
if viewModel.exercicesSharedData.state == .completed {
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) { [self] in
self.reset()
exerciseCompletedBehavior()
}
}
}
Expand All @@ -154,6 +164,7 @@ class DragAndDropBaseScene: SKScene {
.moveAnimation(.easeOut)
let group: DispatchGroup = DispatchGroup()
group.enter()
node.scaleForMax(sizeOf: biggerSide)
node.run(
moveAnimation,
completion: {
Expand Down Expand Up @@ -191,7 +202,8 @@ class DragAndDropBaseScene: SKScene {
for touch in touches {
let location = touch.location(in: self)
if let node = self.atPoint(location) as? DraggableImageAnswerNode {
for gameplayChoiceModel in viewModel.choices where node.name == gameplayChoiceModel.choice.value && node.isDraggable {
for gameplayChoiceModel in viewModel.choices
where node.name == gameplayChoiceModel.choice.value && node.isDraggable {
selectedNodes[touch] = node
onDragAnimation(node)
node.zPosition += 100
Expand Down

0 comments on commit c1a412f

Please sign in to comment.