Skip to content

Commit

Permalink
Update all clothing data #97
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimillian committed May 10, 2020
1 parent d832af2 commit 5438e48
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 75 deletions.
52 changes: 4 additions & 48 deletions ACHNBrowserUI/ACHNBrowserUI.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,21 @@ public class Items: ObservableObject {
@Published public var villagersHouse: [String: VillagerHouse] = [:]

private var villagerItemsCache: [String: [Item]] = [:]

private let migrated: [Category] = [.housewares, .art, .miscellaneous, .wallMounted, .recipes]

init() {
for category in Category.allCases {
if Category.furnitures().contains(category) {
// Migrated to new JSOn format
if let filename = Category.dataFilename(category: category) {
_ = NookPlazaAPIService
.fetchFile(name: "furnitures")
.fetchFile(name: filename)
.replaceError(with: NewItemResponse(total: 0, results: []))
.eraseToAnyPublisher()
.map{ $0.results.filter{ $0.content.appCategory == category }.map{ $0.content }}
.subscribe(on: DispatchQueue.global())
.receive(on: DispatchQueue.main)
.sink(receiveValue: { [weak self] items in self?.categories[category] = items })
} else if migrated.contains(category) {
_ = NookPlazaAPIService
.fetch(endpoint: category)
.replaceError(with: NewItemResponse(total: 0, results: []))
.eraseToAnyPublisher()
.map{ $0.results.map{ $0.content }}
.subscribe(on: DispatchQueue.global())
.receive(on: DispatchQueue.main)
.sink(receiveValue: { [weak self] items in self?.categories[category] = items })
} else {
// Old JSON format
_ = NookPlazaAPIService
.fetch(endpoint: category)
.replaceError(with: ItemResponse(total: 0, results: []))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public enum Category: String, CaseIterable {
case housewares, miscellaneous
case wallMounted = "wall-mounted"
case wallpapers, floors, rugs, photos, posters, fencing, tools
case tops, bottoms, dresses, headwear, accessories, socks, shoes, bags
case tops, bottoms, headwear, accessories, socks, shoes, bags
case dressup = "Dress-Up"
case umbrellas, music, recipes, construction, nookmiles, other
case art, bugs, fish, fossils

Expand Down Expand Up @@ -65,16 +66,31 @@ public enum Category: String, CaseIterable {
return "icon-fish"
case .tools:
return "icon-tool"
case .dresses:
case .dressup:
return "icon-top"
case .shoes:
return "icon-shoes"
}
}

public static func furnitures() -> [Category] {
public static func dataFilename(category: Category) -> String? {
if APIFurnitures().contains(category) {
return "furnitures"
} else if APIClothing().contains(category) {
return "clothing"
} else if category == .recipes {
return category.rawValue
}
return nil
}

public static func APIFurnitures() -> [Category] {
[.housewares, .miscellaneous, .wallMounted, .art]
}

public static func APIClothing() -> [Category] {
[.accessories, .headwear, .tops, .bottoms, .dressup, .socks, .shoes, .bags]
}

public static func villagerFurnitures() -> [Category] {
[.housewares, .miscellaneous, .wallMounted, .art,
Expand All @@ -88,7 +104,7 @@ public enum Category: String, CaseIterable {
}

public static func wardrobe() -> [Category] {
[.tops, .bottoms, .dresses, .headwear,
[.tops, .bottoms, .dressup, .headwear,
.accessories, .socks, .shoes, .bags, .umbrellas]
}

Expand All @@ -99,7 +115,7 @@ public enum Category: String, CaseIterable {
public static func icons() -> [Category] {
return [.housewares, .recipes, .floors, .rugs, .wallpapers,
.fencing, .music, .tools, .nookmiles, .construction, .tops,
.bottoms, .dresses, .headwear, .accessories, .socks, .bags, .umbrellas,
.bottoms, .dressup, .headwear, .accessories, .socks, .bags, .umbrellas,
.fish, .bugs, .fossils]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public struct Item: Codable, Equatable, Identifiable, Hashable {

public let obtainedFrom: String?
public let obtainedFromNew: [String]?
public let sourceNote: String?
public let dIY: Bool?
public let customize: Bool?

Expand All @@ -69,6 +70,8 @@ public struct Item: Codable, Equatable, Identifiable, Hashable {
return .bugs
} else if category == "Nook Miles" {
return .nookmiles
} else if category == "Dress-Up" {
return .dressup
}
return Category(rawValue: category.lowercased())!
}
Expand Down Expand Up @@ -157,6 +160,7 @@ public let static_item = Item(name: "Acoustic guitar",
itemImage: nil,
obtainedFrom: "Crafting",
obtainedFromNew: ["Crafting"],
sourceNote: "From somewhere",
dIY: true,
customize: true,
variants: nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct CategoriesView: View {
icon: Backend.Category.fossils.iconName(),
categories: Backend.Category.nature())
makeSubCategories(name: "Wardrobe",
icon: Backend.Category.dresses.iconName(),
icon: Backend.Category.dressup.iconName(),
categories: Backend.Category.wardrobe())
makeCategories()
} else {
Expand Down
1 change: 0 additions & 1 deletion ACHNBrowserUI/Resources/json/accessories

This file was deleted.

1 change: 0 additions & 1 deletion ACHNBrowserUI/Resources/json/bags

This file was deleted.

1 change: 0 additions & 1 deletion ACHNBrowserUI/Resources/json/bottoms

This file was deleted.

1 change: 1 addition & 0 deletions ACHNBrowserUI/Resources/json/clothing

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion ACHNBrowserUI/Resources/json/dresses

This file was deleted.

1 change: 0 additions & 1 deletion ACHNBrowserUI/Resources/json/headwear

This file was deleted.

1 change: 0 additions & 1 deletion ACHNBrowserUI/Resources/json/shoes

This file was deleted.

1 change: 0 additions & 1 deletion ACHNBrowserUI/Resources/json/socks

This file was deleted.

1 change: 0 additions & 1 deletion ACHNBrowserUI/Resources/json/tops

This file was deleted.

0 comments on commit 5438e48

Please sign in to comment.