Skip to content

Commit

Permalink
refactor: #107-변수명 직관적으로 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
HyunJaeyeon committed Nov 30, 2024
1 parent ab2d6bb commit 73417b9
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions PepperoniV2/Presentation/Game/RankingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ struct RankingView: View {
ScrollView {
ForEach(rankedPlayers.indices, id: \.self) { index in
let player = rankedPlayers[index]
let isAboveHost = player.score > rankedPlayers.first(where: { $0.isHost })?.score ?? 0
let isWin = player.score > rankedPlayers.first(where: { $0.isHost })?.score ?? 0

RankRow(player: player,
rank: index + 1,
isFirst: isAboveHost, // 호스트 보다 위인 사람은 first 효과
isLast: player.isHost, // host는 last 효과
isWin: isWin, // 호스트 보다 위인 사람은 first 효과
isHost: player.isHost)
.opacity(rowVisible[index] ? 1 : 0) // 초기 상태는 보이지 않음
.offset(y: rowVisible[index] ? 0 : 20) // 약간 아래에서 올라오는 효과
Expand All @@ -44,7 +43,8 @@ struct RankingView: View {
}
}
.padding(.horizontal, 16)
.padding(.bottom, (index == 0 || index == rankedPlayers.count - 2) ? 16 : 4)
.padding(.bottom, player.isHost ? 8 : 4)
.padding(.top, player.isHost ? 4 : 0)
}
}

Expand Down Expand Up @@ -75,50 +75,49 @@ struct RankingView: View {
struct RankRow: View {
let player: Player
let rank: Int
let isFirst: Bool
let isLast: Bool
let isWin: Bool
let isHost: Bool

var body: some View {
RoundedRectangle(cornerRadius: 10)
.frame(height: isFirst ? 80 : 70)
.frame(height: isWin ? 80 : 70)
.foregroundStyle(backgroundStyle)
.overlay {
ZStack {
if isFirst || isLast {
if isWin || isHost {
RoundedRectangle(cornerRadius: 10)
.stroke(isLast ? lastPlaceStroke : firstPlaceStroke,
lineWidth: isFirst || isLast ? 1 : 0.5)
.frame(height: isFirst ? 80 : 70)
.stroke(isHost ? lastPlaceStroke : firstPlaceStroke,
lineWidth: isWin || isHost ? 1 : 0.5)
.frame(height: isWin ? 80 : 70)
}
HStack {
Text(rankText)
.hakgyoansim(size: isFirst ? 26 : 20)
.hakgyoansim(size: isWin ? 26 : 20)
.foregroundStyle(rankColor)
Spacer()
Text(player.nickname)
.suit(isFirst ? .bold : .medium, size: isFirst ? 22 : 18)
.suit(isWin ? .bold : .medium, size: isWin ? 22 : 18)
.foregroundStyle(nicknameColor)
Spacer()
Text("\(player.score / 3)")
.hakgyoansim(size: isFirst ? 20 : 18)
.hakgyoansim(size: isWin ? 20 : 18)
.foregroundStyle(scoreColor)
}
.padding(.horizontal, isFirst ? 15 : 18)
.padding(.horizontal, isWin ? 15 : 18)
}
}
.shadow(color: .white.opacity(isLast ? 0.38 : 0), radius: 8.2, x: 0, y: 0)
.shadow(color: .white.opacity(isHost ? 0.38 : 0), radius: 8.2, x: 0, y: 0)

}

private var backgroundStyle: AnyShapeStyle {
if isLast {
if isHost {
return AnyShapeStyle(LinearGradient(
colors: [Color.black],
startPoint: .leading,
endPoint: .trailing
))
} else if isFirst {
} else if isWin {
return AnyShapeStyle(firstPlaceGradient)
} else {
return AnyShapeStyle(LinearGradient(
Expand Down Expand Up @@ -170,25 +169,25 @@ struct RankRow: View {
}

private var rankText: String {
if isFirst {
if isWin {
return "Win"
} else if isLast {
} else if isHost {
return "-"
} else {
return "Lose"
}
}

private var rankColor: Color {
isFirst ? .white : Color.ppBlueGray
isWin ? .white : Color.ppBlueGray
}

private var nicknameColor: Color {
isFirst ? .white : Color.ppWhiteGray
isWin ? .white : Color.ppWhiteGray
}

private var scoreColor: Color {
isFirst ? .white : Color.ppDarkGray_01
isWin ? .white : Color.ppDarkGray_01
}
}

Expand Down

0 comments on commit 73417b9

Please sign in to comment.