Skip to content

Commit

Permalink
Add new variable Game.isInstalled + Minor GameCard updates before r…
Browse files Browse the repository at this point in the history
…efactor
  • Loading branch information
blackxfiied committed Jun 26, 2024
1 parent 909eb32 commit 3c75a9b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 29 deletions.
21 changes: 11 additions & 10 deletions Mythic/Utilities/Game.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,13 @@ enum GameType: String, CaseIterable, Codable, Hashable {
class Game: ObservableObject, Hashable, Codable, Identifiable, Equatable {
// MARK: Stubs
static func == (lhs: Game, rhs: Game) -> Bool {
return lhs.type == rhs.type &&
lhs.title == rhs.title &&
lhs.id == rhs.id &&
lhs.platform == rhs.platform &&
lhs.imageURL == rhs.imageURL &&
lhs.path == rhs.path
return lhs.id == rhs.id && lhs.platform == rhs.platform && lhs.path == rhs.path
}

// MARK: Hash
func hash(into hasher: inout Hasher) {
hasher.combine(type)
hasher.combine(title)
hasher.combine(id)
hasher.combine(platform)
hasher.combine(imageURL)
hasher.combine(wideImageURL)
hasher.combine(path)
}

Expand Down Expand Up @@ -134,6 +125,16 @@ class Game: ObservableObject, Hashable, Codable, Identifiable, Equatable {
}
}

var isInstalled: Bool {
switch self.type {
case .epic:
let games = try? Legendary.getInstalledGames()
return games?.contains(self) == true
case .local:
return true
}
}

// MARK: Functions
func move(to newLocation: URL) async throws {
switch type {
Expand Down
27 changes: 8 additions & 19 deletions Mythic/Views/Unified/Models/GameCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ struct GameCard: View {
if operation.current?.game.id == game.id { // MARK: View if game is being installed
GameInstallProgressView()
.padding(.horizontal)
} else if game.type == .local || ((try? Legendary.getInstalledGames()) ?? .init()).contains(game) { // MARK: Buttons if game is installed
} else if game.isInstalled { // MARK: Buttons if game is installed
if case .windows = game.platform, !Engine.exists {
// MARK: Engine Install Button
Button {
Expand Down Expand Up @@ -139,11 +139,11 @@ struct GameCard: View {
}
.clipShape(.circle)
.disabled(!networkMonitor.isEpicAccessible)
// .disabled(operation.current?.game != nil)
.help("Game verification is required for \"\(game.title)\".")
} else {
// MARK: Play Button
// ! Changes made here must also be reflected in CompactGameCard's play button
// TODO: Unify ^^
if operation.launching == game {
ProgressView()
.controlSize(.small)
Expand Down Expand Up @@ -194,28 +194,15 @@ struct GameCard: View {
game: game, platform: game.platform!, type: .update
)
)
/*
do {
try await Legendary.install(
game: game,
platform: game.platform!,
type: .update
)
} catch {
Logger.app.error("Error repairing \(game.title): \(error.localizedDescription)")
// TODO: add update error
}
*/
}
} label: {
Image(systemName: "arrow.triangle.2.circlepath")
.padding(5)
}
.clipShape(.circle)
.help("Update \"\(game.title)\"")
.disabled(!networkMonitor.isEpicAccessible)
.disabled(operation.runningGames.contains(game))
// .disabled(operation.current?.game != nil)
.help("Update \"\(game.title)\"")
}

// MARK: Settings Button
Expand Down Expand Up @@ -243,9 +230,9 @@ struct GameCard: View {
}
.clipShape(.circle)
.help("Favourite \"\(game.title)\"")
.task { animateFavouriteIcon = game.isFavourited }
.shadow(color: .secondary, radius: animateFavouriteIcon ? 20 : 0)
.symbolEffect(.bounce, value: animateFavouriteIcon)
.task { animateFavouriteIcon = game.isFavourited } // causes bounce on view appearance

// MARK: Delete Button
Button {
Expand All @@ -260,7 +247,9 @@ struct GameCard: View {
.disabled(operation.runningGames.contains(game))
.help("Delete \"\(game.title)\"")
.onHover { hovering in
withAnimation(.easeInOut(duration: 0.1)) { hoveringOverDestructiveButton = hovering }
withAnimation(.easeInOut(duration: 0.1)) {
hoveringOverDestructiveButton = hovering
}
}
.sheet(isPresented: $isUninstallSheetPresented) {
UninstallViewEvo(game: $game, isPresented: $isUninstallSheetPresented)
Expand Down Expand Up @@ -290,7 +279,7 @@ struct GameCard: View {
}
}

/// ViewModifier that enables views to have a fade in effect
/// ViewModifier that enables views to have a fade in effect.
struct FadeInModifier: ViewModifier {
@State private var opacity: Double = 0

Expand Down

0 comments on commit 3c75a9b

Please sign in to comment.