From e67acaacfb7bcf17bdae5d67abca0766d59aeadd Mon Sep 17 00:00:00 2001 From: Joseph Mattiello Date: Thu, 24 Oct 2024 15:09:46 -0400 Subject: [PATCH] Fixed mocking of games view Signed-off-by: Joseph Mattiello --- .../PVSwiftUI/Consoles/ConsoleGamesView.swift | 99 ++++++++++--------- 1 file changed, 51 insertions(+), 48 deletions(-) diff --git a/PVUI/Sources/PVSwiftUI/Consoles/ConsoleGamesView.swift b/PVUI/Sources/PVSwiftUI/Consoles/ConsoleGamesView.swift index 32a9b68f40..0e6c976c17 100644 --- a/PVUI/Sources/PVSwiftUI/Consoles/ConsoleGamesView.swift +++ b/PVUI/Sources/PVSwiftUI/Consoles/ConsoleGamesView.swift @@ -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) @@ -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 {