Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] #106-Default Player 설정 (쇼케이스용) #108

Merged
merged 8 commits into from
Dec 1, 2024
3 changes: 2 additions & 1 deletion PepperoniV2/Data/GameData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ struct Player: Identifiable {
var nickname: String = ""
var turn: Int
var score: Int = 0
var isHost = false
}

@Observable class GameData {
var selectedAnime: Anime?
var selectedQuote: AnimeQuote?
var players: [Player] = [Player(turn: 1), Player(turn: 2)]
var players: [Player] = [Player(turn: 1, isHost: true), Player(turn: 2)]
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,13 @@ struct AnimeSelectView: View {

/// 현재 보여지는 애니 리스트
private var currentAnimes: [Anime] {
let sortedAnimes = animes.sorted { $0.title.localizedCompare($1.title) == .orderedAscending }
if searchText.isEmpty {
return animes
return sortedAnimes
} else {
// 검색어 공백 제거
let normalizedSearchText = searchText.replacingOccurrences(of: " ", with: "")
return animes.filter {
return sortedAnimes.filter {
// 애니 제목 공백 제거
let normalizedTitle = $0.title.replacingOccurrences(of: " ", with: "")
return normalizedTitle.localizedCaseInsensitiveContains(normalizedSearchText)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,16 @@ struct PlayerRowView: View {

VStack {
TextField(
"\(index + 1)",
player.isHost ? "진행자" : "도전자\(player.turn - 1)",
text: Binding(
mosiccan marked this conversation as resolved.
Show resolved Hide resolved
get: {
player.nickname ?? ""
player.nickname
},
set: { newValue in
updateNickname(index, newValue)
}
),
prompt: Text(isFocused ? "" : "\(index + 1)번")
prompt: Text(isFocused ? "" : (player.isHost ? "진행자" : "도전자\(player.turn - 1)"))
.foregroundStyle(Color.ppWhiteGray)
)
.foregroundStyle(.white)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ import SwiftUI

/// 플레이어 초기화
func resetPlayer() {
tempPlayers = [Player(turn: 1), Player(turn: 2)]
tempPlayers = [Player(turn: 1, isHost: true), Player(turn: 2)]
}

/// 변경사항 저장
func saveChanges() {
for (index, player) in tempPlayers.enumerated() {
if player.nickname.isEmpty {
tempPlayers[index].nickname = "\(index + 1)번"
if player.isHost {
tempPlayers[index].nickname = "진행자"
} else {
tempPlayers[index].nickname = "참가자\(player.turn - 1)"
}
}
}
gameData.players = tempPlayers
Expand Down
4 changes: 2 additions & 2 deletions PepperoniV2/Presentation/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,11 @@ struct PlayerGridView: View {
// 10번째일때만 중앙에 오게
if index == 9 && gameData.players.count == 10 {
Spacer()
PlayerCellView(nickname: player.nickname ?? "")
PlayerCellView(nickname: player.nickname)
.frame(width: 106, height: 32)
Spacer()
} else {
PlayerCellView(nickname: player.nickname ?? "")
PlayerCellView(nickname: player.nickname)
.frame(width: 106, height: 32)
}
}
Expand Down