Skip to content

Commit

Permalink
Fixed mocking of games view
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph Mattiello <[email protected]>
  • Loading branch information
JoeMatt committed Oct 24, 2024
1 parent 4236165 commit e67acaa
Showing 1 changed file with 51 additions and 48 deletions.
99 changes: 51 additions & 48 deletions PVUI/Sources/PVSwiftUI/Consoles/ConsoleGamesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,59 @@ struct ConsoleGamesView: SwiftUI.View, GameContextMenuDelegate {
// Games section
if games.isEmpty && isSimulator {
// Show mock games in simulator
showMockGames()
let fakeGames = PVGame.mockGenerate(systemID: console.identifier)
if viewModel.viewGamesAsGrid {
let columns = [GridItem(.adaptive(minimum: calculateGridItemSize()), spacing: 2)]
LazyVGrid(columns: columns, spacing: 2) {
ForEach(fakeGames, id: \.self) { game in
GameItemView(game: game, constrainHeight: false) {
// No action needed for fake games
}
}
}
} else {
LazyVStack(spacing: 8) {
ForEach(fakeGames, id: \.self) { game in
GameItemView(game: game, constrainHeight: false) {
// No action needed for fake games
}
}
}
}
} else {
// Show real games
showRealGames()
if viewModel.viewGamesAsGrid {
let columns = [GridItem(.adaptive(minimum: calculateGridItemSize()), spacing: 2)]
LazyVGrid(columns: columns, spacing: 2) {
ForEach(filteredAndSortedGames(), id: \.self) { game in
GameItemView(game: game, constrainHeight: false) {
loadGame(game)
}
.contextMenu { GameContextMenu(game: game, rootDelegate: rootDelegate, contextMenuDelegate: self) }
}
}
.gesture(
MagnificationGesture()
.onChanged { value in
let delta = value / lastScale
lastScale = value
adjustZoom(delta: delta)
}
.onEnded { _ in
lastScale = 1.0
saveScale()
}
)
} else {
LazyVStack(spacing: 8) {
ForEach(filteredAndSortedGames(), id: \.self) { game in
GameItemView(game: game, constrainHeight: false) {
loadGame(game)
}
.contextMenu { GameContextMenu(game: game, rootDelegate: rootDelegate, contextMenuDelegate: self) }
}
}
}
}

BiosesView(console: console)
Expand Down Expand Up @@ -239,52 +288,6 @@ struct ConsoleGamesView: SwiftUI.View, GameContextMenuDelegate {
}
}

private func showMockGames() -> some View {
let fakeGames = PVGame.mockGenerate(systemID: console.identifier)
return HomeSection(title: "Games") {
ForEach(fakeGames, id: \.self) { game in
GameItemView(game: game, constrainHeight: false) {
// No action needed for fake games
}
}
}
}

private func showRealGames() -> some View {
if viewModel.viewGamesAsGrid {
let columns = [GridItem(.adaptive(minimum: calculateGridItemSize()), spacing: 2)]
return LazyVGrid(columns: columns, spacing: 2) {
ForEach(filteredAndSortedGames(), id: \.self) { game in
GameItemView(game: game, constrainHeight: false) {
loadGame(game)
}
.contextMenu { GameContextMenu(game: game, rootDelegate: rootDelegate, contextMenuDelegate: self) }
}
}
.gesture(
MagnificationGesture()
.onChanged { value in
let delta = value / lastScale
lastScale = value
adjustZoom(delta: delta)
}
.onEnded { _ in
lastScale = 1.0
saveScale()
}
)
} else {
return LazyVStack(spacing: 8) {
ForEach(filteredAndSortedGames(), id: \.self) { game in
GameItemView(game: game, constrainHeight: false) {
loadGame(game)
}
.contextMenu { GameContextMenu(game: game, rootDelegate: rootDelegate, contextMenuDelegate: self) }
}
}
}
}

// MARK: - Zoom Helpers

private func calculateGridItemSize() -> CGFloat {
Expand Down

0 comments on commit e67acaa

Please sign in to comment.