Skip to content

Commit

Permalink
[#27] fix : 정보 업데이트 순서에 따른 리셋 미반영 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
eeeesong committed May 13, 2021
1 parent caa4510 commit 9c7f6bb
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class BallCountView: UIView {
private func fill(with property: DrawingProperty, upto count: Int) {
guard let targetLayers = countCircleLayers[property.row] else { return }

if count > property.maxColumn {
if count > property.maxColumn || count == 0 {
targetLayers.forEach { layer in
layer.backgroundColor = Color.clear
}
Expand Down
43 changes: 12 additions & 31 deletions iOS/baseball-game/baseball-game/GamePlay/Model/BallCounter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,13 @@ class BallCounter {
self.ball = 0
self.out = 0

notiStrikeChange()
notiBallChange()
notiOutChange()
notiBallChange(ballType: BallCount.strike, count: self.strike)
notiBallChange(ballType: BallCount.ball, count: self.ball)
notiBallChange(ballType: BallCount.out, count: self.out)
}

private func notiStrikeChange() {
let updateInfo: [String: Any] = ["ballType": BallCount.strike, "count": self.strike]
NotificationCenter.default.post(name: BallCounter.notiName, object: nil, userInfo: updateInfo)
}

private func notiBallChange() {
let updateInfo: [String: Any] = ["ballType": BallCount.ball, "count": self.ball]
NotificationCenter.default.post(name: BallCounter.notiName, object: nil, userInfo: updateInfo)
}

private func notiOutChange() {
let updateInfo: [String: Any] = ["ballType": BallCount.out, "count": self.out]
private func notiBallChange(ballType: BallCount, count: Int) {
let updateInfo: [String: Any] = ["ballType": ballType, "count": count]
NotificationCenter.default.post(name: BallCounter.notiName, object: nil, userInfo: updateInfo)
}

Expand All @@ -65,31 +55,22 @@ class BallCounter {
private func updateStrike(_ count: Int) {
self.strike += count

notiStrikeChange()

if self.strike == 3 {
self.strike = 0
}
notiBallChange(ballType: BallCount.strike, count: self.strike)
if self.strike == 3 { self.strike = 0 }
}

private func updateBall(_ count: Int) {
self.ball += count

notiBallChange()

if self.ball == 4 {
self.ball = 0
}

notiBallChange(ballType: BallCount.ball, count: self.ball)
if self.ball == 4 { self.ball = 0 }
}

private func updateOut(_ count: Int) {
self.out += count

notiOutChange()

if self.out == 3 {
self.out = 0
}
notiBallChange(ballType: BallCount.out, count: self.out)
if self.out == 3 { self.out = 0 }
}

}
Expand Down
24 changes: 14 additions & 10 deletions iOS/baseball-game/baseball-game/GamePlay/Model/BaseManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ class BaseManager {
self.first = false
self.second = false
self.third = false

notiBaseChanged(movement: BaseMovement.reset)
}

static let notiName = Notification.Name.init("baseChanged")

private func notiBaseChanged(movement: BaseMovement) {
let updateInfo: [String: Any] = ["movement": movement]
NotificationCenter.default.post(name: BaseManager.notiName, object: nil, userInfo: updateInfo)
}

func update(with baseInfo: BaseChanged) {
Expand All @@ -62,36 +71,30 @@ class BaseManager {

}

static let notiName = Notification.Name.init("baseChanged")

private func thirdToHome() {
self.third = false

let updateInfo: [String: Any] = ["movement": BaseMovement.thirdToHome]
NotificationCenter.default.post(name: BaseManager.notiName, object: nil, userInfo: updateInfo)
notiBaseChanged(movement: BaseMovement.thirdToHome)
}

private func secondToThird() {
self.second = false
self.third = true

let updateInfo: [String: Any] = ["movement": BaseMovement.secondToThird]
NotificationCenter.default.post(name: BaseManager.notiName, object: nil, userInfo: updateInfo)
notiBaseChanged(movement: BaseMovement.secondToThird)
}

private func firstToSecond() {
self.first = false
self.second = true

let updateInfo: [String: Any] = ["movement": BaseMovement.firstToSecond]
NotificationCenter.default.post(name: BaseManager.notiName, object: nil, userInfo: updateInfo)
notiBaseChanged(movement: BaseMovement.firstToSecond)
}

private func homeToFirst() {
self.first = true

let updateInfo: [String: Any] = ["movement": BaseMovement.homeToFirst]
NotificationCenter.default.post(name: BaseManager.notiName, object: nil, userInfo: updateInfo)
notiBaseChanged(movement: BaseMovement.homeToFirst)
}

}
Expand All @@ -101,4 +104,5 @@ enum BaseMovement {
case firstToSecond
case secondToThird
case thirdToHome
case reset
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ extension GameManager: GameUpdatable {
}

func changeBatter(to newBatter: Player) {
if self.batter.name != newBatter.name { self.ballCounter.reset() }
self.batter = newBatter
self.ballCounter.reset()
}

func updateBallCount(with ballChanged: BallChanged) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,8 @@ class GamePlayViewModel {
self.gameUpdator = self.gameManager
self.pitchList = self.gameUpdator.pitchInfo()
}

}.store(in: &cancelBag)
self.gameManager = GameManager(userTeamSide: self.userTeamSide, teams: Teams(home: "하하하", away: "귀찮다"), batter: Player(name: "롤로", info: "귀찮음"), pitcher: Player(name: "리아", info: "화이팅!"))
self.gameUpdator = self.gameManager
self.pitchList = self.gameUpdator.pitchInfo()
}

func requestPitch() {
Expand All @@ -53,42 +50,37 @@ class GamePlayViewModel {
if let data = value.data {
if let newInning = data.inning {
self.gameManager.resetForNewInning(with: newInning)
} else {
if let newScore = data.score {
self.gameManager.updateScore(with: newScore)
}

if let newPitch = data.newPitch {
self.gameManager.updatePitchList(with: newPitch)
self.pitchList = self.gameManager.pitchInfo()
}

if let newBallInfo = data.ballChanged {
self.gameManager.updateBallCount(with: newBallInfo)
}

if let newBaseInfo = data.baseChanged {
self.gameManager.updateBase(with: newBaseInfo)
}
}

if let newScore = data.score {
self.gameManager.updateScore(with: newScore)
}


if let newBatter = data.batter {
self.gameManager.changeBatter(to: newBatter)
}

if let newPitcher = data.pitcher {
self.gameManager.changePitcher(to: newPitcher)
}

if let newPitch = data.newPitch {
self.gameManager.updatePitchList(with: newPitch)
self.pitchList = self.gameManager.pitchInfo()
}

if let newBallInfo = data.ballChanged {
self.gameManager.updateBallCount(with: newBallInfo)
}

if let newBaseInfo = data.baseChanged {
self.gameManager.updateBase(with: newBaseInfo)
}
self.gameUpdator = self.gameManager
}

}.store(in: &cancelBag)
self.gameManager.updatePitchList(with: Pitch(count: 1, result: "테스트", log: "1-1"))
self.gameManager.changeBatter(to: Player(name: "깔깔", info: "랄랄"))
self.gameManager.updateBallCount(with: BallChanged(strike: 1, ball: 0, out: 0))
self.gameManager.updateBase(with: BaseChanged(first: BaseChanged.BaseStatus(baseIn: true, baseOut: false), second: nil, third: nil))
self.gameUpdator = self.gameManager
self.pitchList = self.gameManager.pitchInfo()
}

}

0 comments on commit 9c7f6bb

Please sign in to comment.