Skip to content

Commit

Permalink
🚚 (NewGEK): Rename positionning functions
Browse files Browse the repository at this point in the history
  • Loading branch information
HPezz committed Dec 18, 2024
1 parent b6aba67 commit b6938f8
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DnDGridBaseScene: SKScene {
backgroundColor = .clear
removeAllChildren()
removeAllActions()
self.setFirstAnswerPosition()
self.setPositionVariables()
self.layoutChoices()
}

Expand Down Expand Up @@ -75,7 +75,7 @@ class DnDGridBaseScene: SKScene {

func layoutChoices() {
for (index, choice) in self.viewModel.choices.enumerated() {
choice.initialPosition = self.setInitialPosition(index)
choice.initialPosition = self.setChoicePosition(index)
choice.position = choice.initialPosition!
self.bindNodesToSafeArea([choice])
self.dropDestinations.append(choice)
Expand All @@ -94,11 +94,11 @@ class DnDGridBaseScene: SKScene {

// MARK: - Answer Positioning

func setFirstAnswerPosition() {
fatalError("setFirstAnswerPosition() must be implemented in the sub-scene")
func setPositionVariables() {
fatalError("setPositionVariables() must be implemented in the sub-scene")
}

func setInitialPosition(_: Int) -> CGPoint {
func setChoicePosition(_: Int) -> CGPoint {
fatalError("setNextAnswerPosition(_ index:) must be implemented in the sub-scene")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import SwiftUI

class DnDGridFiveChoicesScene: DnDGridBaseScene {
override func setFirstAnswerPosition() {
override func setPositionVariables() {
self.horizontalSpacer = size.width / 3
self.verticalSpacer = size.height / 3
self.initialNodeX = (size.width / 2) - self.horizontalSpacer
}

override func setInitialPosition(_ index: Int) -> CGPoint {
override func setChoicePosition(_ index: Int) -> CGPoint {
if index / 3 < 1 {
let positionX = self.initialNodeX + (self.horizontalSpacer * CGFloat(index % 3))
let positionY = 2 * self.verticalSpacer + 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import SwiftUI

class DnDGridFourChoicesScene: DnDGridBaseScene {
override func setFirstAnswerPosition() {
override func setPositionVariables() {
self.horizontalSpacer = size.width / 2
self.verticalSpacer = size.height / 3
self.initialNodeX = (size.width - self.horizontalSpacer) / 2
}

override func setInitialPosition(_ index: Int) -> CGPoint {
override func setChoicePosition(_ index: Int) -> CGPoint {
let positionX = self.initialNodeX + (self.horizontalSpacer * CGFloat(index % 2))
if index / 2 < 1 {
let positionY = 2 * self.verticalSpacer + 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import SwiftUI

class DnDGridSixChoicesScene: DnDGridBaseScene {
override func setFirstAnswerPosition() {
override func setPositionVariables() {
self.horizontalSpacer = size.width / 3
self.verticalSpacer = size.height / 3
self.initialNodeX = (size.width / 2) - self.horizontalSpacer
}

override func setInitialPosition(_ index: Int) -> CGPoint {
override func setChoicePosition(_ index: Int) -> CGPoint {
let positionX = self.initialNodeX + (self.horizontalSpacer * CGFloat(index % 3))
if index / 3 < 1 {
let positionY = 2 * self.verticalSpacer + 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import SwiftUI

class DnDGridThreeChoicesScene: DnDGridBaseScene {
override func setFirstAnswerPosition() {
override func setPositionVariables() {
self.horizontalSpacer = size.width / 2
self.verticalSpacer = size.height / 3
self.initialNodeX = (size.width - self.horizontalSpacer) / 2
}

override func setInitialPosition(_ index: Int) -> CGPoint {
override func setChoicePosition(_ index: Int) -> CGPoint {
if index / 2 < 1 {
let positionX = self.initialNodeX + (self.horizontalSpacer * CGFloat(index % 2))
let positionY = 2 * self.verticalSpacer + 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import SwiftUI

class DnDGridTwoChoicesScene: DnDGridBaseScene {
override func setFirstAnswerPosition() {
override func setPositionVariables() {
self.horizontalSpacer = size.width / 2
self.verticalSpacer = size.height / 2
self.initialNodeX = (size.width - self.horizontalSpacer) / 2
}

override func setInitialPosition(_ index: Int) -> CGPoint {
override func setChoicePosition(_ index: Int) -> CGPoint {
let positionX = self.initialNodeX + (self.horizontalSpacer * CGFloat(index % 2))
return CGPoint(x: positionX, y: self.verticalSpacer)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class DnDGridWithZonesBaseScene: SKScene {
removeAllChildren()
removeAllActions()

self.setFirstAnswerPosition()
self.setPositionVariables()
self.layoutDropZones()
self.layoutAnswers()
}
Expand All @@ -80,7 +80,7 @@ class DnDGridWithZonesBaseScene: SKScene {

func layoutAnswers() {
for (index, choice) in self.viewModel.choices.enumerated() {
choice.initialPosition = self.setInitialPosition(index)
choice.initialPosition = self.setChoicePosition(index)
choice.position = choice.initialPosition!

let shadowChoice = DnDShadowNode(node: choice)
Expand All @@ -99,12 +99,11 @@ class DnDGridWithZonesBaseScene: SKScene {
}
}

func setFirstAnswerPosition() {
func setPositionVariables() {
self.spacer = size.width / CGFloat(self.viewModel.choices.count + 1)
self.defaultPosition = CGPoint(x: self.spacer, y: 3 * size.height / 4)
}

func setInitialPosition(_ index: Int) -> CGPoint {
func setChoicePosition(_ index: Int) -> CGPoint {
CGPoint(x: self.spacer * CGFloat(index + 1), y: 3 * size.height / 4)
}

Expand All @@ -128,5 +127,4 @@ class DnDGridWithZonesBaseScene: SKScene {
private var answerNodes: [DnDAnswerNode] = []
private var playedNode: DnDAnswerNode?
private var spacer: CGFloat = .zero
private var defaultPosition = CGPoint.zero
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class DnDOneToOneBaseScene: SKScene {

func layoutChoices() {
for (index, choice) in self.viewModel.choices.enumerated() {
choice.initialPosition = self.setInitialPosition(index)
choice.initialPosition = self.setChoicePosition(index)
choice.position = choice.initialPosition!
self.answerNodes.append(choice)

Expand All @@ -94,17 +94,17 @@ class DnDOneToOneBaseScene: SKScene {

func layoutDropzones() {
for (index, dropzone) in self.viewModel.dropzones.enumerated() {
dropzone.position = self.setInitialDropZonePosition(index)
dropzone.position = self.setDropZonePosition(index)
self.dropZonesNodes.append(dropzone)
addChild(dropzone)
}
}

func setInitialPosition(_ index: Int) -> CGPoint {
func setChoicePosition(_ index: Int) -> CGPoint {
CGPoint(x: self.spacer * CGFloat(index + 1), y: size.height - self.viewModel.choices[0].size.height * 0.8)
}

func setInitialDropZonePosition(_ index: Int) -> CGPoint {
func setDropZonePosition(_ index: Int) -> CGPoint {
CGPoint(x: self.spacer * CGFloat(index + 1), y: self.viewModel.choices[0].size.height * 0.8)
}

Expand Down

0 comments on commit b6938f8

Please sign in to comment.