Skip to content

Commit

Permalink
Refactor: Rename methods in view classes #26
Browse files Browse the repository at this point in the history
  • Loading branch information
jinios committed May 14, 2018
1 parent 87e9b29 commit 414db39
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 39 deletions.
15 changes: 7 additions & 8 deletions CardGameApp/CardGameApp/View/CardDeckView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CardDeckView: UIView {
self.deckManager = gameManager.getDeckDelegate()
}

func drawDefault() {
func setup() {
let newOrigin = CGPoint(x: PositionX.seventh.value, y: PositionY.upper.value)
let frameForDraw = CGRect(origin: newOrigin, size: ViewController.cardSize)
self.closedCardDeck = CardImageView(frame: frameForDraw)
Expand All @@ -57,7 +57,7 @@ class CardDeckView: UIView {
}
}

func drawOpenDeck() {
func setOpenDeck() {
let newOrigin = CGPoint(x: PositionX.sixth.value, y: PositionY.upper.value)
let frameForDraw = CGRect(origin: newOrigin, size: ViewController.cardSize)

Expand All @@ -69,7 +69,7 @@ class CardDeckView: UIView {
addSubview(pickedCardView)
}

func drawRefresh() {
func loadRefreshIcon() {
closedCardDeck.getRefreshImage()
}

Expand All @@ -86,11 +86,10 @@ class CardDeckView: UIView {
}
}

func redraw() {
// after double tapped?
func reload() {
self.subviews.forEach{ $0.removeFromSuperview() }
drawDefault()
drawOpenDeck()
setup()
setOpenDeck()
}

func movableCardView() -> CardImageView {
Expand All @@ -100,7 +99,7 @@ class CardDeckView: UIView {

func resetByShake() {
self.subviews.forEach{ $0.removeFromSuperview() }
drawDefault()
setup()
}

}
14 changes: 7 additions & 7 deletions CardGameApp/CardGameApp/View/CardStacksView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ class CardStacksView: UIView {
super.init(coder: aDecoder)
}

func newDraw() {
func setup() {
for i in 0...6 {
oneStackViews.append(OneStack(column: i, manager: wholeStackManager))
addSubview(oneStackViews[i])
oneStackViews[i].newDrawCards()
oneStackViews[i].setup()
}
}

func redraw(column: Int) {
oneStackViews[column].redraw()
func reload(column: Int) {
oneStackViews[column].reload()
}

func getOneStack(of column: Int) -> OneStack{
Expand Down Expand Up @@ -73,7 +73,7 @@ class OneStack: UIView {
fatalError("init(coder:) has not been implemented")
}

func newDrawCards() {
func setup() {
for i in 0..<stackManager.countOfCard() {
let card = stackManager.cardInTurn(at: i)
let newOrigin = CGPoint(x: 0, y: ViewController.spaceY * CGFloat(i))
Expand All @@ -87,9 +87,9 @@ class OneStack: UIView {
}
}

func redraw() {
func reload() {
self.subviews.forEach{ $0.removeFromSuperview() }
newDrawCards()
setup()
}

private func setDoubleTabToCard(to card: CardImageView) {
Expand Down
10 changes: 5 additions & 5 deletions CardGameApp/CardGameApp/View/FoundationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ class FoundationView: UIView {
self.foundationManager = gameManager.getFoundationDelegate()
}

func drawDefault() {
func setup() {
for i in 0..<numberOfFoundation {
let newOrigin = CGPoint(x: PositionX.allValues[i].value, y: PositionY.upper.value)
let frameForDraw = CGRect(origin: newOrigin, size: ViewController.cardSize)
self.drawEmptyDock(in: frameForDraw)
self.setEmptyDock(in: frameForDraw)
}
}

private func drawEmptyDock(in frameForDraw: CGRect) {
private func setEmptyDock(in frameForDraw: CGRect) {
let foundation = UIView(frame: frameForDraw)
foundation.clipsToBounds = true
foundation.layer.cornerRadius = 5.0
Expand All @@ -43,13 +43,13 @@ class FoundationView: UIView {
addSubview(foundation)
}

func redraw() {
func reload() {
self.subviews.forEach({ $0.removeFromSuperview() })
for i in FoundationManager.range {
let newOrigin = CGPoint(x: PositionX.allValues[i].value, y: PositionY.upper.value)
let frameForDraw = CGRect(origin: newOrigin, size: ViewController.cardSize)
if foundationManager.countOfCards(of: i) == 0 {
self.drawEmptyDock(in: frameForDraw)
self.setEmptyDock(in: frameForDraw)
} else {
for card in foundationManager.cards(in: i) {
let cardImage = CardImageView(frame: frameForDraw)
Expand Down
38 changes: 19 additions & 19 deletions CardGameApp/CardGameApp/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class ViewController: UIViewController {
}

private func initialView() {
drawFoundation()
setFoundationView()
self.view.backgroundColor = UIColor(patternImage: UIImage(named: "bg_pattern")!)
drawDeck()
drawStacks()
setDeckView()
setStacksView()
setNotification()
}

Expand Down Expand Up @@ -62,35 +62,35 @@ class ViewController: UIViewController {
// MARK: ChangedView Related

@objc func updateDeck() {
self.deckView.redraw()
self.deckView.reload()
}

@objc func updateOpenDeck(notification: Notification) {
guard notification.object as! Bool else {
self.deckView.drawRefresh()
self.deckView.loadRefreshIcon()
return
}
self.deckView.drawOpenDeck()
self.deckView.setOpenDeck()
}

// MARK: InitialView Related

private func drawDeck() {
private func setDeckView() {
self.deckView = CardDeckView()
self.view.addSubview(deckView)
deckView.drawDefault()
deckView.setup()
}

private func drawFoundation() {
private func setFoundationView() {
self.foundationView = FoundationView()
self.view.addSubview(foundationView)
foundationView.drawDefault()
foundationView.setup()
}

private func drawStacks() {
private func setStacksView() {
self.stackView = CardStacksView()
self.view.addSubview(stackView)
stackView.newDraw()
stackView.setup()
}

// MARK: Shake motion Related
Expand Down Expand Up @@ -138,9 +138,9 @@ class ViewController: UIViewController {
targetCard.frame.origin.y += moveTo.y
},
completion: { _ in
self.foundationView.redraw()
self.deckView.redraw()
self.stackView.redraw(column: toIndex)
self.foundationView.reload()
self.deckView.reload()
self.stackView.reload(column: toIndex)
targetCard.removeFromSuperview()
})

Expand Down Expand Up @@ -186,10 +186,10 @@ class ViewController: UIViewController {
},
completion: { _ in
targetCard.removeFromSuperview()
self.foundationView.redraw()
self.deckView.redraw()
self.stackView.redraw(column: fromIndex)
self.stackView.redraw(column: toIndex)
self.foundationView.reload()
self.deckView.reload()
self.stackView.reload(column: fromIndex)
self.stackView.reload(column: toIndex)
})
}

Expand Down

0 comments on commit 414db39

Please sign in to comment.