feat(Like Button): add half star if item is not completed
* Add an half star to show that the item has been partially completed,
meaning at least one of its variants is liked, but not all of them.
MODIFY
ACHNBrowserUI/ACHNBrowserUI/viewModels/LikeButtonViewModel.swift
ACHNBrowserUI/ACHNBrowserUI/viewModels/LikeButtonViewModel.swift
@@ -18,6 +18,7 @@ class LikeButtonViewModel: ObservableObject {
let villager: Villager?
@Published var isInCollection = false
+ @Published var variantsCompletionStatus: VariantsCompletionStatus = .unstarted
private let collection: UserCollection
private var cancellable: AnyCancellable?
@@ -42,6 +43,11 @@ class LikeButtonViewModel: ObservableObject {
self.isInCollection = variants.contains(for: item, variant: variant)
return
}
+ if item.hasSomeVariations {
+ self.variantsCompletionStatus = variants.completionStatus(for: item)
+ self.isInCollection = self.variantsCompletionStatus != .unstarted
+ return
+ }
self.isInCollection = items.contains(item) || critters.contains(item)
return
} else if let villager = villager {

MODIFY
ACHNBrowserUI/ACHNBrowserUI/views/shared/LikeButtonView.swift
ACHNBrowserUI/ACHNBrowserUI/views/shared/LikeButtonView.swift
@@ -25,6 +25,13 @@ struct LikeButtonView: View {
if viewModel.item?.isCritter == true {
return viewModel.isInCollection ? "checkmark.seal.fill" : "checkmark.seal"
} else {
+ if viewModel.item?.hasSomeVariations == true && viewModel.variant == nil {
+ switch viewModel.variantsCompletionStatus {
+ case .unstarted: return "star"
+ case .partial: return "star.leadinghalf.fill"
+ case .complete: return "star.fill"
+ }
+ }
return viewModel.isInCollection ? "star.fill" : "star"
}
} else {

MODIFY
ACHNBrowserUI/Packages/Backend/Sources/Backend/Environments/UserCollection.swift
ACHNBrowserUI/Packages/Backend/Sources/Backend/Environments/UserCollection.swift
@@ -499,10 +499,37 @@ public class UserCollection: ObservableObject {
}
public extension Dictionary where Key == String, Value == [Variant] {
- public func contains(for item: Item, variant: Variant) -> Bool {
+ func contains(for item: Item, variant: Variant) -> Bool {
guard let filename = item.filename else {
return false
}
return self[filename]?.contains(variant) == true
}
+
+ func completionStatus(for item: Item) -> VariantsCompletionStatus {
+ guard let filename = item.filename,
+ let itemVariations = item.variations,
+ let currentVariations = self[filename]
+ else { return .unstarted }
+
+ if currentVariations.count <= 0 {
+ return .unstarted
+ } else if currentVariations.count < itemVariations.count {
+ return .partial
+ } else {
+ return .complete
+ }
+ }
+}
+
+public enum VariantsCompletionStatus {
+ case unstarted
+ case partial
+ case complete
+}
+
+public extension Item {
+ var hasSomeVariations: Bool {
+ variations?.count ?? 0 > 1
+ }
}

feat(Like Button): add half star if item is not completed

* Add an half star to show that the item has been partially completed,
  meaning at least one of its variants is liked, but not all of them.