From 3d8190b0243c47aebf31868fe8f270c8333c012f Mon Sep 17 00:00:00 2001 From: Hugo Pezziardi Date: Fri, 13 Dec 2024 13:45:07 +0100 Subject: [PATCH 1/8] =?UTF-8?q?=E2=9C=A8=20(NewGEK):=20Add=20DnDGridUIMode?= =?UTF-8?q?l?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/DnD/Grid/DnDGridUIModel.swift | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/DnDGridUIModel.swift diff --git a/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/DnDGridUIModel.swift b/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/DnDGridUIModel.swift new file mode 100644 index 000000000..a6b168e27 --- /dev/null +++ b/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/DnDGridUIModel.swift @@ -0,0 +1,91 @@ +// Leka - iOS Monorepo +// Copyright APF France handicap +// SPDX-License-Identifier: Apache-2.0 + +import ContentKit +import SpriteKit +import SwiftUI + +// MARK: - DnDGridViewUIChoicesWrapper + +public struct DnDGridUIModel { + // MARK: Internal + + static let zero = DnDGridUIModel(action: nil, choices: []) + + var action: Exercise.Action? + var choices: [DnDAnswerNode] + + func choiceSize(for choiceNumber: Int) -> CGSize { + DnDGridSize(choiceNumber).choiceSize(for: self.action) + } + + // MARK: Private + + // swiftlint:disable identifier_name cyclomatic_complexity + + private enum DnDGridSize: Int { + case one = 1 + case two + case three + case four + case five + case six + case none + + // MARK: Lifecycle + + init(_ rawValue: Int) { + self = DnDGridSize(rawValue: rawValue) ?? .none + } + + // MARK: Internal + + func choiceSize(for action: Exercise.Action?) -> CGSize { + switch action { + case .ipad(type: .image), + .ipad(type: .sfsymbol): + switch self { + case .one, + .two, + .three, + .four: + CGSize(width: 180, height: 180) + case .five, + .six, + .none: + CGSize(width: 150, height: 150) + } + case .none: + switch self { + case .one, + .two: + CGSize(width: 300, height: 300) + case .three, + .four: + CGSize(width: 240, height: 240) + case .five, + .six, + .none: + CGSize(width: 200, height: 200) + } + default: + switch self { + case .one, + .two: + CGSize(width: 220, height: 220) + case .three, + .four: + CGSize(width: 200, height: 200) + case .five: + CGSize(width: 160, height: 160) + case .six, + .none: + CGSize(width: 150, height: 150) + } + } + } + } + + // swiftlint:enable identifier_name cyclomatic_complexity +} From 39539b0321bc4be2120cc54c7f9b9724ad19ab04 Mon Sep 17 00:00:00 2001 From: Hugo Pezziardi Date: Fri, 13 Dec 2024 13:48:21 +0100 Subject: [PATCH 2/8] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20(NewGEK?= =?UTF-8?q?):=20Add=20new=20image=20choices=20set?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Gameplays/NewGameplayAssociateCategories.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Modules/GameEngineKit/Sources/_NewSystem/Gameplays/NewGameplayAssociateCategories.swift b/Modules/GameEngineKit/Sources/_NewSystem/Gameplays/NewGameplayAssociateCategories.swift index bfb94e5b6..72a50a232 100644 --- a/Modules/GameEngineKit/Sources/_NewSystem/Gameplays/NewGameplayAssociateCategories.swift +++ b/Modules/GameEngineKit/Sources/_NewSystem/Gameplays/NewGameplayAssociateCategories.swift @@ -104,6 +104,15 @@ public extension NewGameplayAssociateCategories { NewGameplayAssociateCategoriesChoice(value: "Maison", category: nil, type: .text), ] + static let kDefaultImageChoices: [NewGameplayAssociateCategoriesChoice] = [ + NewGameplayAssociateCategoriesChoice(value: "pictograms-weather-sun_yellow-0106", category: .categoryA, type: .image), + NewGameplayAssociateCategoriesChoice(value: "pictograms-animals-arctic-penguin_yellow-0088", category: .categoryB, type: .image), + NewGameplayAssociateCategoriesChoice(value: "pictograms-weather-sun_yellow-0106", category: .categoryA, type: .image), + NewGameplayAssociateCategoriesChoice(value: "pictograms-animals-arctic-penguin_yellow-0088", category: .categoryB, type: .image), + NewGameplayAssociateCategoriesChoice(value: "pictograms-weather-sun_yellow-0106", category: .categoryA, type: .image), + NewGameplayAssociateCategoriesChoice(value: "Maison", category: nil, type: .text), + ] + static let kDefaultChoicesWithZones: [NewGameplayAssociateCategoriesChoice] = [ NewGameplayAssociateCategoriesChoice(value: "sun", category: .categoryA, type: .text), NewGameplayAssociateCategoriesChoice(value: "car", category: .categoryB, type: .text), From 5aee3f64abd2463407b2962dc8aab59f97e883d9 Mon Sep 17 00:00:00 2001 From: Hugo Pezziardi Date: Fri, 13 Dec 2024 13:53:48 +0100 Subject: [PATCH 3/8] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20(NewGEK):=20GridCoordi?= =?UTF-8?q?nator=20use=20GridUIModel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DnDGridCoordinator+AssociateCategories.swift | 12 +++++++----- .../DnDGridGameplayCoordinatorProtocol.swift | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/Coordinators/DnDGridCoordinator+AssociateCategories.swift b/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/Coordinators/DnDGridCoordinator+AssociateCategories.swift index fdbbe9cd3..a32c2c0e6 100644 --- a/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/Coordinators/DnDGridCoordinator+AssociateCategories.swift +++ b/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/Coordinators/DnDGridCoordinator+AssociateCategories.swift @@ -3,6 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 import Combine +import ContentKit import SpriteKit import SwiftUI import UtilsKit @@ -12,17 +13,18 @@ import UtilsKit public class DnDGridCoordinatorAssociateCategories: DnDGridGameplayCoordinatorProtocol { // MARK: Lifecycle - public init(gameplay: NewGameplayAssociateCategories) { + public init(gameplay: NewGameplayAssociateCategories, action: Exercise.Action? = nil) { self.gameplay = gameplay - self.uiChoices.value.choices = gameplay.choices.map { choice in - DnDAnswerNode(id: choice.id, value: choice.value, type: choice.type, size: self.uiChoices.value.choiceSize(for: gameplay.choices.count)) + self.uiModel.value.action = action + self.uiModel.value.choices = gameplay.choices.map { choice in + DnDAnswerNode(id: choice.id, value: choice.value, type: choice.type, size: self.uiModel.value.choiceSize(for: gameplay.choices.count)) } } // MARK: Public - public private(set) var uiChoices = CurrentValueSubject(.zero) + public private(set) var uiModel = CurrentValueSubject(.zero) public func onTouch(_ event: DnDTouchEvent, choice: DnDAnswerNode, destination: DnDAnswerNode? = nil) { switch event { @@ -76,7 +78,7 @@ public class DnDGridCoordinatorAssociateCategories: DnDGridGameplayCoordinatorPr private func updateChoiceState(for choice: NewGameplayAssociateCategoriesChoice, to state: State) { guard let index = self.gameplay.choices.firstIndex(where: { $0.id == choice.id }) else { return } - self.updateUINodeState(node: self.uiChoices.value.choices[index], state: state) + self.updateUINodeState(node: self.uiModel.value.choices[index], state: state) } private func choiceAlreadySelected(choice: NewGameplayAssociateCategoriesChoice) -> Bool { diff --git a/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/Coordinators/DnDGridGameplayCoordinatorProtocol.swift b/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/Coordinators/DnDGridGameplayCoordinatorProtocol.swift index b9b9290d5..68bc81ca3 100644 --- a/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/Coordinators/DnDGridGameplayCoordinatorProtocol.swift +++ b/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/Coordinators/DnDGridGameplayCoordinatorProtocol.swift @@ -6,6 +6,6 @@ import Combine import Foundation public protocol DnDGridGameplayCoordinatorProtocol { - var uiChoices: CurrentValueSubject { get } + var uiModel: CurrentValueSubject { get } func onTouch(_ event: DnDTouchEvent, choice: DnDAnswerNode, destination: DnDAnswerNode?) } From 29408d74c3f22e67d02bec8d3efd7d1729117715 Mon Sep 17 00:00:00 2001 From: Hugo Pezziardi Date: Fri, 13 Dec 2024 14:02:08 +0100 Subject: [PATCH 4/8] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20(NewGEK):=20GridVM=20u?= =?UTF-8?q?se=20coordinator's=20uiModel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/DnD/Grid/DnDGridViewModel.swift | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/DnDGridViewModel.swift b/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/DnDGridViewModel.swift index f83120008..a3f21e700 100644 --- a/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/DnDGridViewModel.swift +++ b/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/DnDGridViewModel.swift @@ -3,6 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 import Combine +import ContentKit import SwiftUI // MARK: - DnDGridViewModel @@ -11,12 +12,13 @@ public class DnDGridViewModel: ObservableObject { // MARK: Lifecycle public init(coordinator: DnDGridGameplayCoordinatorProtocol) { - self.choices = coordinator.uiChoices.value.choices + self.choices = coordinator.uiModel.value.choices + self.action = coordinator.uiModel.value.action self.coordinator = coordinator - self.coordinator.uiChoices + self.coordinator.uiModel .receive(on: DispatchQueue.main) - .sink { [weak self] choices in - self?.choices = choices.choices + .sink { [weak self] model in + self?.choices = model.choices } .store(in: &self.cancellables) } @@ -29,8 +31,11 @@ public class DnDGridViewModel: ObservableObject { // MARK: Internal + @Published var isActionTriggered = false @Published var choices: [DnDAnswerNode] = [] + let action: Exercise.Action? + // MARK: Private private let coordinator: DnDGridGameplayCoordinatorProtocol From 5fe2a10a397375a5d3a82910e3ff4689d14ae8d4 Mon Sep 17 00:00:00 2001 From: Hugo Pezziardi Date: Fri, 13 Dec 2024 14:04:41 +0100 Subject: [PATCH 5/8] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20(NewGEK):=20DnDGrid=20?= =?UTF-8?q?now=20can=20display=20or=20not=20action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/DnD/Grid/DnDGridView.swift | 49 +++++++++++++++++-- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/DnDGridView.swift b/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/DnDGridView.swift index ba2e032f0..f1c938163 100644 --- a/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/DnDGridView.swift +++ b/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/DnDGridView.swift @@ -17,12 +17,41 @@ public struct DnDGridView: View { // MARK: Public public var body: some View { - GeometryReader { proxy in - SpriteView(scene: self.makeScene(size: proxy.size), options: [.allowsTransparency]) - .frame(width: proxy.size.width, height: proxy.size.height) - .onAppear { - self.scene = self.getScene(for: self.viewModel.choices.count, size: proxy.size) + HStack(spacing: 0) { + if let action = self.viewModel.action { + Button { + // nothing to do } + label: { + ActionButtonView(action: action) + .padding(20) + } + .simultaneousGesture( + TapGesture() + .onEnded { _ in + withAnimation { + self.viewModel.isActionTriggered = true + } + } + ) + + Divider() + .opacity(0.4) + .frame(maxHeight: 500) + .padding(.vertical, 20) + + Spacer() + + self.standardDnDGridView + .colorMultiply(self.viewModel.isActionTriggered ? .white : .gray.opacity(0.4)) + .animation(.easeOut(duration: 0.3), value: self.viewModel.isActionTriggered) + .allowsHitTesting(self.viewModel.isActionTriggered) + + Spacer() + + } else { + self.standardDnDGridView + } } } @@ -31,6 +60,16 @@ public struct DnDGridView: View { @StateObject private var viewModel: DnDGridViewModel @State private var scene: SKScene = .init() + private var standardDnDGridView: some View { + GeometryReader { proxy in + SpriteView(scene: self.makeScene(size: proxy.size), options: [.allowsTransparency]) + .frame(width: proxy.size.width, height: proxy.size.height) + .onAppear { + self.scene = self.getScene(for: self.viewModel.choices.count, size: proxy.size) + } + } + } + private func makeScene(size: CGSize) -> SKScene { guard let finalScene = scene as? DnDGridBaseScene else { return SKScene() From f56ffa0819a43e25fb13fd477d2989b0a3be6ca0 Mon Sep 17 00:00:00 2001 From: Hugo Pezziardi Date: Fri, 13 Dec 2024 14:05:48 +0100 Subject: [PATCH 6/8] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20(NewGEK):=20Display=20?= =?UTF-8?q?all=20sorts=20of=20actionThenDnDGrid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/App/ContentView.swift | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/Modules/GameEngineKit/Examples/GameEngineKitExample/Sources/App/ContentView.swift b/Modules/GameEngineKit/Examples/GameEngineKitExample/Sources/App/ContentView.swift index 85e53e5fc..a5a1ce5b2 100644 --- a/Modules/GameEngineKit/Examples/GameEngineKitExample/Sources/App/ContentView.swift +++ b/Modules/GameEngineKit/Examples/GameEngineKitExample/Sources/App/ContentView.swift @@ -195,6 +195,80 @@ struct ContentView: View { Spacer() } + + HStack(spacing: 20) { + Text("Action Then DnDGrid") + .font(.title) + .padding() + + NavigationLink("Observe Image Then Drag & Drop Categories", destination: { + let gameplay = NewGameplayAssociateCategories(choices: NewGameplayAssociateCategories.kDefaultChoices) + let coordinator = DnDGridCoordinatorAssociateCategories(gameplay: gameplay, + action: .ipad(type: .image("sport_dance_player_man"))) + let viewModel = DnDGridViewModel(coordinator: coordinator) + + return DnDGridView(viewModel: viewModel) + .navigationTitle("Observe Image Then Drag & Drop Categories") + .navigationBarTitleDisplayMode(.large) + }) + .tint(.pink) + .buttonStyle(.borderedProminent) + .frame(maxWidth: .infinity) + + NavigationLink("Observe SFSymbol Then Drag & Drop Categories", destination: { + let gameplay = NewGameplayAssociateCategories(choices: NewGameplayAssociateCategories.kDefaultChoices) + let coordinator = DnDGridCoordinatorAssociateCategories(gameplay: gameplay, action: .ipad(type: .sfsymbol("star"))) + let viewModel = DnDGridViewModel(coordinator: coordinator) + + return DnDGridView(viewModel: viewModel) + .navigationTitle("Observe SFSymbol Then Drag & Drop Categories") + .navigationBarTitleDisplayMode(.large) + }) + .tint(.pink) + .buttonStyle(.borderedProminent) + .frame(maxWidth: .infinity) + + NavigationLink("Listen Then Drag & Drop Categories", destination: { + let gameplay = NewGameplayAssociateCategories(choices: NewGameplayAssociateCategories.kDefaultChoices) + let coordinator = DnDGridCoordinatorAssociateCategories(gameplay: gameplay, action: .ipad(type: .audio("sound_animal_duck"))) + let viewModel = DnDGridViewModel(coordinator: coordinator) + + return DnDGridView(viewModel: viewModel) + .navigationTitle("Listen Then Drag & Drop Categories") + .navigationBarTitleDisplayMode(.large) + }) + .tint(.pink) + .buttonStyle(.borderedProminent) + .frame(maxWidth: .infinity) + + NavigationLink("Listen Speech Then Drag & Drop Categories", destination: { + let gameplay = NewGameplayAssociateCategories(choices: NewGameplayAssociateCategories.kDefaultImageChoices) + let coordinator = DnDGridCoordinatorAssociateCategories(gameplay: gameplay, action: .ipad(type: .speech("Correct answer"))) + let viewModel = DnDGridViewModel(coordinator: coordinator) + + return DnDGridView(viewModel: viewModel) + .navigationTitle("Listen Speech Then Drag & Drop Categories") + .navigationBarTitleDisplayMode(.large) + }) + .tint(.pink) + .buttonStyle(.borderedProminent) + .frame(maxWidth: .infinity) + + NavigationLink("Robot Then Drag & Drop Categories", destination: { + let gameplay = NewGameplayAssociateCategories(choices: NewGameplayAssociateCategories.kDefaultChoices) + let coordinator = DnDGridCoordinatorAssociateCategories(gameplay: gameplay, action: .robot(type: .color("red"))) + let viewModel = DnDGridViewModel(coordinator: coordinator) + + return DnDGridView(viewModel: viewModel) + .navigationTitle("Listen Speech Then Drag & Drop Categories") + .navigationBarTitleDisplayMode(.large) + }) + .tint(.pink) + .buttonStyle(.borderedProminent) + .frame(maxWidth: .infinity) + + Spacer() + } } Text("Or choose a template") From 3e052f160741c053b997c8971517b83a93715c2d Mon Sep 17 00:00:00 2001 From: Hugo Pezziardi Date: Tue, 17 Dec 2024 13:08:02 +0100 Subject: [PATCH 7/8] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20(NewGek):=20Remove=20G?= =?UTF-8?q?ridSize=20enum=20from=20UIModel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/DnD/Grid/DnDGridUIModel.swift | 110 +++++++----------- 1 file changed, 39 insertions(+), 71 deletions(-) diff --git a/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/DnDGridUIModel.swift b/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/DnDGridUIModel.swift index a6b168e27..7f2a385ba 100644 --- a/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/DnDGridUIModel.swift +++ b/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/DnDGridUIModel.swift @@ -9,83 +9,51 @@ import SwiftUI // MARK: - DnDGridViewUIChoicesWrapper public struct DnDGridUIModel { - // MARK: Internal - static let zero = DnDGridUIModel(action: nil, choices: []) var action: Exercise.Action? var choices: [DnDAnswerNode] - func choiceSize(for choiceNumber: Int) -> CGSize { - DnDGridSize(choiceNumber).choiceSize(for: self.action) - } - - // MARK: Private - - // swiftlint:disable identifier_name cyclomatic_complexity - - private enum DnDGridSize: Int { - case one = 1 - case two - case three - case four - case five - case six - case none - - // MARK: Lifecycle - - init(_ rawValue: Int) { - self = DnDGridSize(rawValue: rawValue) ?? .none - } - - // MARK: Internal - - func choiceSize(for action: Exercise.Action?) -> CGSize { - switch action { - case .ipad(type: .image), - .ipad(type: .sfsymbol): - switch self { - case .one, - .two, - .three, - .four: - CGSize(width: 180, height: 180) - case .five, - .six, - .none: - CGSize(width: 150, height: 150) - } - case .none: - switch self { - case .one, - .two: - CGSize(width: 300, height: 300) - case .three, - .four: - CGSize(width: 240, height: 240) - case .five, - .six, - .none: - CGSize(width: 200, height: 200) - } - default: - switch self { - case .one, - .two: - CGSize(width: 220, height: 220) - case .three, - .four: - CGSize(width: 200, height: 200) - case .five: - CGSize(width: 160, height: 160) - case .six, - .none: - CGSize(width: 150, height: 150) - } - } + // swiftlint:disable cyclomatic_complexity + + func choiceSize(for numberOfChoices: Int) -> CGSize { + switch self.action { + case .ipad(type: .image), + .ipad(type: .sfsymbol): + switch numberOfChoices { + case 1...4: + CGSize(width: 180, height: 180) + case 5...6: + CGSize(width: 150, height: 150) + default: + CGSize(width: 150, height: 150) + } + case .none: + switch numberOfChoices { + case 1...2: + CGSize(width: 300, height: 300) + case 3...4: + CGSize(width: 240, height: 240) + case 5...6: + CGSize(width: 200, height: 200) + default: + CGSize(width: 200, height: 200) + } + default: + switch numberOfChoices { + case 1...2: + CGSize(width: 220, height: 220) + case 3...4: + CGSize(width: 200, height: 200) + case 5: + CGSize(width: 160, height: 160) + case 6: + CGSize(width: 150, height: 150) + default: + CGSize(width: 150, height: 150) + } } } - // swiftlint:enable identifier_name cyclomatic_complexity + // swiftlint:enable cyclomatic_complexity } From 0bd2e7433ddbd9ad02123e73f841f2603e18f8ef Mon Sep 17 00:00:00 2001 From: Hugo Pezziardi Date: Tue, 17 Dec 2024 13:08:49 +0100 Subject: [PATCH 8/8] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20(NewGEK):=20Improve=20?= =?UTF-8?q?GridView=20code=20without=20doublons?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/DnD/Grid/DnDGridView.swift | 33 ++++++++----------- .../Views/DnD/Grid/DnDGridViewModel.swift | 1 + 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/DnDGridView.swift b/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/DnDGridView.swift index f1c938163..ca21614a4 100644 --- a/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/DnDGridView.swift +++ b/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/DnDGridView.swift @@ -39,19 +39,22 @@ public struct DnDGridView: View { .opacity(0.4) .frame(maxHeight: 500) .padding(.vertical, 20) + } - Spacer() - - self.standardDnDGridView - .colorMultiply(self.viewModel.isActionTriggered ? .white : .gray.opacity(0.4)) - .animation(.easeOut(duration: 0.3), value: self.viewModel.isActionTriggered) - .allowsHitTesting(self.viewModel.isActionTriggered) - - Spacer() + Spacer() - } else { - self.standardDnDGridView + GeometryReader { proxy in + SpriteView(scene: self.makeScene(size: proxy.size), options: [.allowsTransparency]) + .frame(width: proxy.size.width, height: proxy.size.height) + .onAppear { + self.scene = self.getScene(for: self.viewModel.choices.count, size: proxy.size) + } } + .colorMultiply(self.viewModel.isActionTriggered ? .white : .gray.opacity(0.4)) + .animation(.easeOut(duration: 0.3), value: self.viewModel.isActionTriggered) + .allowsHitTesting(self.viewModel.isActionTriggered) + + Spacer() } } @@ -60,16 +63,6 @@ public struct DnDGridView: View { @StateObject private var viewModel: DnDGridViewModel @State private var scene: SKScene = .init() - private var standardDnDGridView: some View { - GeometryReader { proxy in - SpriteView(scene: self.makeScene(size: proxy.size), options: [.allowsTransparency]) - .frame(width: proxy.size.width, height: proxy.size.height) - .onAppear { - self.scene = self.getScene(for: self.viewModel.choices.count, size: proxy.size) - } - } - } - private func makeScene(size: CGSize) -> SKScene { guard let finalScene = scene as? DnDGridBaseScene else { return SKScene() diff --git a/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/DnDGridViewModel.swift b/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/DnDGridViewModel.swift index a3f21e700..79d8c8fbf 100644 --- a/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/DnDGridViewModel.swift +++ b/Modules/GameEngineKit/Sources/_NewSystem/Views/DnD/Grid/DnDGridViewModel.swift @@ -14,6 +14,7 @@ public class DnDGridViewModel: ObservableObject { public init(coordinator: DnDGridGameplayCoordinatorProtocol) { self.choices = coordinator.uiModel.value.choices self.action = coordinator.uiModel.value.action + self.isActionTriggered = (self.action == nil) ? true : false self.coordinator = coordinator self.coordinator.uiModel .receive(on: DispatchQueue.main)