Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[마을 주민] 카테고리: NPC 추가 #77

Merged
merged 2 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@
"images" : [
{
"filename" : "kk.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
"idiom" : "universal"
}
],
"info" : {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "icon-kk.png",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "icon-raymond.png",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
// MARK: - Tab Bar Titles
"Dashboard" = "Dashboard";
"Catalog" = "Catalog";
"Villagers" = "Villagers";
"villagers" = "Villagers";
"Collection" = "Collection";
"animals" = "Animals";

// MARK: - etc
"Cancel" = "Cancel";
Expand Down Expand Up @@ -149,6 +150,7 @@ Find the villagers you have visited and tap the home icon on the villager's page
"Reactions" = "Reactions";
"Fencing" = "Fencing";
"Gyroids" = "Gyroids";
"Villager" = "Villager";

// MARK: - ItemsViewController
"To catch now" = "To catch now";
Expand Down Expand Up @@ -269,6 +271,11 @@ Find the villagers you have visited and tap the home icon on the villager's page
"9 PM – 4 AM" = "9 PM – 4 AM";
"All day" = "All day";

// MARK: - NPCViewController
"Search a npc" = "Search a NPC";
"There are no npc." = "There are no npc.";
"Tap the npc's heart button and it will appear here." = "Tap the npc's heart button and it will appear here.";

// MARK: - VillagersViewController
"All" = "All";
"Personality" = "Personality";
Expand All @@ -278,7 +285,6 @@ Find the villagers you have visited and tap the home icon on the villager's page
"Liked" = "Liked";
"Residents" = "Residents";
"Search a villager" = "Search a villager";
"Villagers" = "Villagers";
"There are no villagers." = "There are no villagers.";
"Please check the network status." = "Please check the network status.";
"Tap the villager's heart button and it will appear here." = "Tap the villager's heart button and it will appear here.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
// MARK: - Tab Bar Titles
"Dashboard" = "대시보드";
"Catalog" = "카탈로그";
"Villagers" = "마을주민";
"villagers" = "마을주민";
"Collection" = "수집품";
"animals" = "동물";

// MARK: - etc
"Cancel" = "취소";
Expand Down Expand Up @@ -150,6 +151,7 @@
"Reactions" = "리액션";
"Fencing" = "울타리";
"Gyroids" = "토용";
"Villager" = "마을주민";

// MARK: - ItemsViewController
"To catch now" = "아직 늦지 않았어요!";
Expand Down Expand Up @@ -272,6 +274,11 @@
"9 PM – 4 AM" = "오후 9시 – 오후 4시";
"All day" = "하루종일";

// MARK: - NPCViewController
"Search a npc" = "NPC를 검색해주세요. (초성도 가능)";
"There are no npc." = "NPC가 없습니다.";
"Tap the npc's heart button and it will appear here." = "NPC의 하트 모양 버튼을 누르면 여기에 표시됩니다.";

// MARK: - VillagersViewController
"All" = "전체";
"Personality" = "성격";
Expand All @@ -281,7 +288,6 @@
"Liked" = "좋아하는 주민";
"Residents" = "내 섬 주민";
"Search a villager" = "주민을 검색해주세요. (초성도 가능)";
"Villagers" = "마을 주민";
"There are no villagers." = "마을 주민이 없습니다.";
"Please check the network status." = "네트워크 상태를 확인해주세요.";
"Tap the villager's heart button and it will appear here." = "마을 주민의 하트 모양 버튼을 누르면 여기에 표시됩니다.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ final class AppCoordinator: Coordinator {
addViewController(catalogCoordinator.rootViewController, title: "Catalog".localized, icon: "icon-leaf-tabbar")
childCoordinators.append(catalogCoordinator)

let villagersCoordinator = VillagersCoordinator()
villagersCoordinator.start()
addViewController(villagersCoordinator.rootViewController, title: "Villagers".localized, icon: "icon-book-tabbar")
childCoordinators.append(villagersCoordinator)
let animalsCoordinator = AnimalsCoordinator()
animalsCoordinator.start()
addViewController(animalsCoordinator.rootViewController, title: "animals".localized, icon: "icon-book-tabbar")
childCoordinators.append(animalsCoordinator)

let collectionCoordinator = CollectionCoordinator()
collectionCoordinator.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ enum CoordinatorType {
case main
case dashboard
case taskEdit
case villagers
case animals
case catalog
case collection
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21512" systemVersion="22A400" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23231" systemVersion="24C5057p" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="DailyTaskEntity" representedClassName="DailyTaskEntity" syncable="YES" codeGenerationType="class">
<attribute name="amount" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="date" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
Expand Down Expand Up @@ -67,6 +67,16 @@
<attribute name="whereHow" optional="YES" attributeType="String"/>
<relationship name="userColletion" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="UserCollectionEntity" inverseName="critters" inverseEntity="UserCollectionEntity"/>
</entity>
<entity name="NPCLikeEntity" representedClassName="NPCLikeEntity" syncable="YES" codeGenerationType="class">
<attribute name="birthday" attributeType="String"/>
<attribute name="gender" attributeType="String"/>
<attribute name="genderAsia" attributeType="String"/>
<attribute name="iconImage" attributeType="String"/>
<attribute name="name" attributeType="String"/>
<attribute name="photoImage" attributeType="String"/>
<attribute name="translations" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" customClassName="[String: String]"/>
<relationship name="userCollection" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="UserCollectionEntity" inverseName="npcLike" inverseEntity="UserCollectionEntity"/>
</entity>
<entity name="UserCollectionEntity" representedClassName="UserCollectionEntity" syncable="YES" codeGenerationType="class">
<attribute name="hemisphere" optional="YES" attributeType="String"/>
<attribute name="islandFruit" optional="YES" attributeType="String"/>
Expand All @@ -75,6 +85,7 @@
<attribute name="name" optional="YES" attributeType="String"/>
<relationship name="critters" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="ItemEntity" inverseName="userColletion" inverseEntity="ItemEntity"/>
<relationship name="dailyTasks" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="DailyTaskEntity" inverseName="userCollection" inverseEntity="DailyTaskEntity"/>
<relationship name="npcLike" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="NPCLikeEntity" inverseName="userCollection" inverseEntity="NPCLikeEntity"/>
<relationship name="villagersHouse" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="VillagersHouseEntity" inverseName="userCollection" inverseEntity="VillagersHouseEntity"/>
<relationship name="villagersLike" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="VillagersLikeEntity" inverseName="userCollection" inverseEntity="VillagersLikeEntity"/>
</entity>
Expand Down Expand Up @@ -124,11 +135,4 @@
<attribute name="translations" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" customClassName="[String: String]"/>
<relationship name="userCollection" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="UserCollectionEntity" inverseName="villagersLike" inverseEntity="UserCollectionEntity"/>
</entity>
<elements>
<element name="DailyTaskEntity" positionX="-97.80707811657339" positionY="133.6700587761588" width="128" height="134"/>
<element name="ItemEntity" positionX="337.44140625" positionY="27.109375" width="128" height="854"/>
<element name="UserCollectionEntity" positionX="117" positionY="198" width="128" height="178"/>
<element name="VillagersHouseEntity" positionX="139.7109375" positionY="445.0390625" width="128" height="344"/>
<element name="VillagersLikeEntity" positionX="-0.90234375" positionY="441.87109375" width="128" height="344"/>
</elements>
</model>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// CoreDataNPCLikeStorage.swift
// Animal-Crossing-Wiki
//
// Created by Ari on 2022/06/10.
//

import Foundation
import RxSwift

final class CoreDataNPCLikeStorage: NPCLikeStorage {

private let coreDataStorage: CoreDataStorage

init(coreDataStorage: CoreDataStorage = CoreDataStorage.shared) {
self.coreDataStorage = coreDataStorage
}

func fetch() -> [NPC] {
let context = coreDataStorage.persistentContainer.viewContext
let object = try? self.coreDataStorage.getUserCollection(context)
let npc = object?.npcLike?.allObjects as? [NPCLikeEntity] ?? []
return npc.map { $0.toDomain() }
.sorted(by: { $0.translations.localizedName() < $1.translations.localizedName() })
}

func update(_ npc: NPC) {
self.coreDataStorage.performBackgroundTask { context in
do {
let object = try self.coreDataStorage.getUserCollection(context)
let npcs = object.npcLike?.allObjects as? [NPCLikeEntity] ?? []
if let index = npcs.firstIndex(where: { $0.name == npc.name }) {
object.removeFromNpcLike(npcs[index])
} else {
let newNPC = NPCLikeEntity(npc, context: context)
object.addToNpcLike(newNPC)
}
context.saveContext()
} catch {
debugPrint(error)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// VillagersLikeEntity+Mapping.swift
// Animal-Crossing-Wiki
//
// Created by Ari on 2022/06/10.
//

import Foundation
import CoreData

extension NPCLikeEntity {
convenience init(_ npc: NPC, context: NSManagedObjectContext) {
self.init(context: context)

self.birthday = npc.birthday
self.gender = npc.gender.rawValue
self.genderAsia = npc.genderAsia.rawValue
self.iconImage = npc.iconImage
self.photoImage = npc.photoImage
self.name = npc.name
self.translations = npc.translations.toDictionary()
}

func toDomain() -> NPC {
return NPC(
name: self.name ?? "",
iconImage: self.iconImage ?? "",
photoImage: self.photoImage ?? "",
gender: Gender(rawValue: self.gender ?? "") ?? .male,
genderAsia: Gender(rawValue: self.gender ?? "") ?? .male,
birthday: self.birthday ?? "",
translations: Translations(self.translations ?? [:])
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// NPCLikeStorage.swift
// Animal-Crossing-Wiki
//
// Created by Ari on 2022/06/10.
//

import Foundation
import RxSwift

protocol NPCLikeStorage {
func fetch() -> [NPC]
func update(_ villager: NPC)
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ enum Category: String, CaseIterable {
case wetSuit = "Wet Suit"
case reactions = "Reactions"
case gyroids = "Gyroids"
case villager = "Villager"
case npc = "NPC"

var iconName: String {
switch self {
Expand Down Expand Up @@ -69,6 +71,8 @@ enum Category: String, CaseIterable {
case .wetSuit: return "icon-wetsuit"
case .reactions: return "icon-reactions"
case .gyroids: return "icon-gyroids"
case .villager: return "icon-raymond"
case .npc: return "icon-kk"
}
}

Expand Down Expand Up @@ -103,6 +107,8 @@ enum Category: String, CaseIterable {
case .wetSuit: return "icon-wetsuit"
case .reactions: return "icon-reactions"
case .gyroids: return "icon-gyroids"
case .villager: return "icon-raymond"
case .npc: return "icon-kk"
}
}

Expand Down Expand Up @@ -135,6 +141,10 @@ enum Category: String, CaseIterable {
.reactions, .gyroids
]
}

static func animals() -> [Category] {
[.npc, .villager]
}
}

extension Category: Comparable {
Expand Down Expand Up @@ -170,6 +180,9 @@ extension Category: Comparable {
case .wetSuit: return 26
case .reactions: return 27
case .gyroids: return 28

case .villager: return 0
case .npc: return 1
}
}

Expand Down
18 changes: 18 additions & 0 deletions Animal-Crossing-Wiki/Projects/App/Sources/Models/NPC.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// NPC.swift
// ACNH-wiki
//
// Created by Ari on 11/23/24.
//

import Foundation

struct NPC {
let name: String
let iconImage: String
let photoImage: String?
let gender: Gender
let genderAsia: Gender
let birthday: String
let translations: Translations
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// NPCRequest.swift
// ACNH-wiki
//
// Created by Ari on 11/23/24.
//

import Foundation
import Alamofire

struct NPCRequest: APIRequest {
typealias Response = [NPCResponseDTO]
let method: HTTPMethod = HTTPMethod.get
let baseURL: URL? = URL(string: EnvironmentsVariable.repoURL)
let path: String = "Special NPCs.json"
var headers: [String: String]? = [:]
var parameters: [String: String] {
return [:]
}
}
Loading
Loading