From 9a87117a95a0c95a131c9bd174fcc2b627e64be1 Mon Sep 17 00:00:00 2001 From: blackxfiied <41133734+blackxfiied@users.noreply.github.com> Date: Tue, 18 Jun 2024 22:45:38 +0800 Subject: [PATCH] feat: sort by favourite, then installed, then others in library view --- Mythic.xcodeproj/project.pbxproj | 4 ++-- Mythic/Views/Unified/GameListEvoView.swift | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Mythic.xcodeproj/project.pbxproj b/Mythic.xcodeproj/project.pbxproj index 76293274..dfcc07c7 100644 --- a/Mythic.xcodeproj/project.pbxproj +++ b/Mythic.xcodeproj/project.pbxproj @@ -703,7 +703,7 @@ "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 2766; + CURRENT_PROJECT_VERSION = 2773; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_ASSET_PATHS = "\"Mythic/Preview Content\""; DEVELOPMENT_TEAM = 67ZBY275P8; @@ -748,7 +748,7 @@ "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 2766; + CURRENT_PROJECT_VERSION = 2773; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_ASSET_PATHS = "\"Mythic/Preview Content\""; DEVELOPMENT_TEAM = 67ZBY275P8; diff --git a/Mythic/Views/Unified/GameListEvoView.swift b/Mythic/Views/Unified/GameListEvoView.swift index 9314b96b..304096cd 100644 --- a/Mythic/Views/Unified/GameListEvoView.swift +++ b/Mythic/Views/Unified/GameListEvoView.swift @@ -19,8 +19,21 @@ struct GameListEvo: View { searchString.isEmpty || $0.title.localizedCaseInsensitiveContains(searchString) } - .sorted(by: { $0.title < $1.title }) - .sorted(by: { $0.isFavourited && !$1.isFavourited }) + .sorted { + if $0.isFavourited != $1.isFavourited { + return $0.isFavourited && !$1.isFavourited + } + + if let games = try? Legendary.getInstalledGames(), games.contains($0) != games.contains($1) { + return games.contains($0) + } + + if let games = LocalGames.library, games.contains($0) != games.contains($1) { + return games.contains($0) + } + + return $0.title < $1.title + } } var body: some View {