Skip to content

Commit

Permalink
♻️ (NewGEK): Improve GridView code without doublons
Browse files Browse the repository at this point in the history
  • Loading branch information
HPezz authored and ladislas committed Dec 17, 2024
1 parent 3e052f1 commit 0bd2e74
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0bd2e74

Please sign in to comment.