Skip to content

Commit

Permalink
Merge pull request #182 from jmshgs/main
Browse files Browse the repository at this point in the history
fix edit games buttons
  • Loading branch information
Shock9616 authored Oct 3, 2024
2 parents d97420e + 0880f7f commit 3898121
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 102 deletions.
4 changes: 2 additions & 2 deletions Phoenix/Phoenix.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@
CURRENT_PROJECT_VERSION = 33;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Phoenix/Preview Content\"";
DEVELOPMENT_TEAM = UC7RC43VZH;
DEVELOPMENT_TEAM = SPWQRB7M9L;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand Down Expand Up @@ -911,7 +911,7 @@
CURRENT_PROJECT_VERSION = 33;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Phoenix/Preview Content\"";
DEVELOPMENT_TEAM = UC7RC43VZH;
DEVELOPMENT_TEAM = SPWQRB7M9L;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand Down
88 changes: 6 additions & 82 deletions Phoenix/Phoenix/Models/Game.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,94 +35,18 @@ struct Game: Codable, Comparable, Hashable, Sendable {

/**
Compares two `Game` objects based on their `name` property.

- Parameters:
- lhs: The left-hand side of the comparison.
- rhs: The right-hand side of the comparison.

- lhs: The left-hand side of the comparison.
- rhs: The right-hand side of the comparison.
- Returns: `true` if the `name` property of the left-hand side is
lexicographically less than the `name` property of the
right-hand side, `false` otherwise.
lexicographically less than the `name` property of the
right-hand side, `false` otherwise.
*/
static func < (lhs: Game, rhs: Game) -> Bool {
return lhs.name.compareSpecial(rhs.name) == .orderedAscending
}

func changedFields() -> [String: Any] {
let mirror = Mirror(reflecting: self)
let defaultGame = Game()
let defaultMirror = Mirror(reflecting: defaultGame)

var changedFields: [String: Any] = [:]

for (property, value) in mirror.children {
guard let property = property else { continue }

if let defaultValue = defaultMirror.children.first(where: { $0.label == property })?.value {
if !isEqual(value, defaultValue) {
changedFields[property] = value
}
}
}

return changedFields
}

private func isEqual(_ lhs: Any, _ rhs: Any) -> Bool {
switch (lhs, rhs) {
case (let lhs as UUID, let rhs as UUID):
return lhs == rhs
case (let lhs as String, let rhs as String):
return lhs == rhs
case (let lhs as [String: String], let rhs as [String: String]):
return lhs == rhs
case (let lhs as [String?], let rhs as [String?]):
return lhs == rhs
case (let lhs as Status, let rhs as Status):
return lhs == rhs
case (let lhs as Recency, let rhs as Recency):
return lhs == rhs
case (let lhs as Bool, let rhs as Bool):
return lhs == rhs
default:
return false
}
}

mutating func applyChanges(from changes: [String: Any]) {
for (key, value) in changes {
switch key {
case "steamID":
if let newValue = value as? String { self.steamID = newValue }
case "igdbID":
if let newValue = value as? String { self.igdbID = newValue }
case "gameFile":
if let newValue = value as? String { self.gameFile = newValue }
case "launcher":
if let newValue = value as? String { self.launcher = newValue }
case "metadata":
if let newValue = value as? [String: String] { self.metadata = newValue }
case "screenshots":
if let newValue = value as? [String?] { self.screenshots = newValue }
case "icon":
if let newValue = value as? String { self.icon = newValue }
case "name":
if let newValue = value as? String { self.name = newValue }
case "platformName":
if let newValue = value as? String { self.platformName = newValue }
case "status":
if let newValue = value as? Status { self.status = newValue }
case "recency":
if let newValue = value as? Recency { self.recency = newValue }
case "isHidden":
if let newValue = value as? Bool { self.isHidden = newValue }
case "isFavorite":
if let newValue = value as? Bool { self.isFavorite = newValue }
default:
break
}
}
}
}

extension String {
Expand Down
13 changes: 0 additions & 13 deletions Phoenix/Phoenix/Views/GameDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,19 +250,6 @@ struct GameDetailView: View {
.stroke(Color.secondary.opacity(0.5), lineWidth: 1)
)
}
Button(action: {
gameViewModel.selectedGameIDs.count == 1 ? appViewModel.isEditingGame.toggle() : ()
}, label: {
Text(String(localized: "multiple_EditGames"))
.padding(.horizontal, 10)
.padding(.vertical, 3)
.foregroundStyle(.gray)
})
.buttonStyle(PlainButtonStyle())
.overlay(
RoundedRectangle(cornerRadius: 5)
.stroke(Color.secondary.opacity(0.5), lineWidth: 1)
)
}
.navigationTitle("Games")
.onChange(of: gameViewModel.selectedGameIDs) { _ in
Expand Down
10 changes: 5 additions & 5 deletions Phoenix/Phoenix/Views/GameListItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ struct GameListItem: View {
ContextButton(action: {
delete(contextGameIDs)
}, symbol: "trash", text: gameViewModel.selectedGameIDs.count == 1 ? String(localized: "context_DeleteGame") : String(localized: "multiple_DeleteGames"))

//edit game(s) button
ContextButton(action: {
gameViewModel.selectedGameIDs.count == 1 ? appViewModel.isEditingGame.toggle() : ()
}, symbol: "pencil", text: gameViewModel.selectedGameIDs.count == 1 ? String(localized: "context_EditGame") : String(localized: "multiple_EditGames"))


if gameViewModel.selectedGameIDs.count == 1 {
//edit game button
ContextButton(action: {
appViewModel.isEditingGame.toggle()
}, symbol: "pencil", text: String(localized: "context_EditGame"))
Divider()
//edit name button
ContextButton(action: { changeName.toggle() }, symbol: "character.cursor.ibeam", text: String(localized: "context_EditName"))
Expand Down

0 comments on commit 3898121

Please sign in to comment.