본문 바로가기

잡다한 것

업보 청산 - 2(혐주의)

728x90
반응형
SMALL

일단 모델, 뷰모델을 따로 분리 했습니다. 

Json데이터 파싱만 800줄이라... 그것도 따로 보관해뒀습니다.

죄송합니다. 죄송합니다.


Model

//
//  CharacterModel.swift
//  LostArkExchange
//
//  Created by Byeon jinha on 2023/05/09.
//

import SwiftUI

struct EquipmentViewData {
    var name: String
    var image: String
    var quality: String
    var basicStat: String
    var basicText: String
    var optionStat: String
    var optionText: String
    var color: String
    var qualityColor: Color
}

struct EngravingViewData {
    var name: String
    var image: String
    var color: String
    var description: String
    var level: String
    var text: String
}


struct AccessoriesViewData {
    var name: String
    var image: String
    var color: String
    var optionalText: String
    var optionalStat: String
    var randomEffect1: String
    var randomEffect2: String
    var randomEffect3: String
    var quality: String
    var qualityColor: Color
    var randomEffectText: String
}

struct BraceletViewData {
    var name: String
    var image: String
    var color: String
    var statText: String
    var optionalStat: String
    var enchantText: String
}

struct AbilitystoneViewData {
    var name: String
    var image: String
    var color: String
    var basicText: String
    var basicStat: String
    var optionText: String
    var optionStat: String
    var option1Text: String
    var option2Text: String
    var option3Text: String
    var quality: String
    var qualityColor: Color
}

ViewModel

//
//  CharacterViewModel  .swift
//  LostArkExchange
//
//  Created by Byeon jinha on 2023/05/09.
//

import SwiftUI
class CharacterViewModel: ObservableObject{    
    var equipmentsArray: [String] = ["무기", "어깨", "투구", "상의", "하의", "장갑"]
    var braceletArray: [String] = ["팔찌"]
    var accessoriesArray: [String] = ["반지", "귀걸이", "목걸이"]
    var abilitystoneArray: [String] = ["어빌리티 스톤"]
    var seal: [String] = ["각인"]
    
    @Published var equipment: EquipmentViewData = EquipmentViewData(name: "",
                                                                image: "",
                                                                quality: "",
                                                                basicStat: "",
                                                                basicText: "",
                                                                optionStat: "",
                                                                optionText: "",
                                                                color: "",
                                                                qualityColor: .white)
    
    @Published var engraving: EngravingViewData = EngravingViewData(name: "",
                                                                image: "",
                                                                color: "",
                                                                description: "",
                                                                level: "",
                                                                text: "")
    
    @Published var accessories: AccessoriesViewData = AccessoriesViewData(name: "",
                                                                      image: "",
                                                                      color: "",
                                                                      optionalText: "",
                                                                      optionalStat: "",
                                                                      randomEffect1: "",
                                                                      randomEffect2: "",
                                                                      randomEffect3: "",
                                                                      quality: "",
                                                                      qualityColor: .white,
                                                                      randomEffectText: "")
    
    @Published var bracelet: BraceletViewData = BraceletViewData(name: "",
                                                             image: "",
                                                             color: "",
                                                             statText: "",
                                                             optionalStat: "",
                                                             enchantText: "")
    
    
    @Published var abilitystone: AbilitystoneViewData = AbilitystoneViewData(name: "",
                                                                         image: "",
                                                                         color: "",
                                                                         basicText: "",
                                                                         basicStat: "",
                                                                         optionText: "",
                                                                         optionStat: "",
                                                                         option1Text: "",
                                                                         option2Text: "",
                                                                         option3Text: "",
                                                                         quality: "",
                                                                         qualityColor: .white)
    
    @Published var isEquipmentsViewStatus: Int = 0
}

View

//
//  CharacterDetailEquipmentsView.swift
//  LostArkExchange
//
//  Created by Byeon jinha on 2023/01/27.
//

import SwiftUI

struct CharacterDetailEquipmentsView: View {
    @StateObject var vm = CharacterViewModel()
    @StateObject private var searchCharacterEqupments = EquipmentsAPI.shared
    @StateObject private var searchCharacterEngraings = EngravingsAPI.shared
    let characterName: String
    
    var body: some View {
        let findEquipmentElements: [[String]] = findEquipments(equipmentsData: searchCharacterEqupments.posts![characterName])
        let findAccessoriesElements: [[String]] = findAccessories(equipmentsData: searchCharacterEqupments.posts![characterName], accessoriesArray: vm.accessoriesArray)
        let findAbilitystoneElements: [[String]] = findAbilityStone(equipmentsData: searchCharacterEqupments.posts![characterName], abilitystoneArray: vm.abilitystoneArray)
        let findBraceletElements: [[String]] = findBracelet(equipmentsData: searchCharacterEqupments.posts![characterName], braceletArray: vm.braceletArray)
        let findEngravingsElements: [[String]] = findEngravings(engravingsData: searchCharacterEngraings.posts![characterName])

        if vm.isEquipmentsViewStatus == 0 {
            HStack {
                VStack(alignment: .leading) {
                    CharacterEquipmentsView(findEquipmentElements: findEquipmentElements,
                                            equipmentsArray: vm.equipmentsArray,
                                            isEquipmentsViewStatus: $vm.isEquipmentsViewStatus,
                                            equipment: $vm.equipment)
                    CharacterEngravingsView(findEngravingsElements: findEngravingsElements,
                                            isEquipmentsViewStatus: $vm.isEquipmentsViewStatus,
                                            engraving: $vm.engraving)
                    Spacer()
                }
                Spacer()
                
                VStack(alignment: .leading) {
                    CharacterAccesoriesView(findAccessoriesElements: findAccessoriesElements,
                                            accessoriesArray: vm.accessoriesArray,
                                            isEquipmentsViewStatus: $vm.isEquipmentsViewStatus,
                                            accessories: $vm.accessories)
                    CharacterBraceletsView(findBraceletElements: findBraceletElements,
                                           braceletArray: vm.braceletArray,
                                           isEquipmentsViewStatus: $vm.isEquipmentsViewStatus,
                                           bracelet: $vm.bracelet)
                    CharacterAbilitystone(findAbilitystoneElements: findAbilitystoneElements,
                                          abilitystoneArray: vm.abilitystoneArray,
                                          isEquipmentsViewStatus: $vm.isEquipmentsViewStatus,
                                          abilitystone: $vm.abilitystone)
                }
                Spacer()
            }
        } else if vm.isEquipmentsViewStatus == 1 {
            Button(action: {
                vm.isEquipmentsViewStatus = 0
            } ) {
                EquipmentDescriptionView(equipmentName: $vm.equipment.name,
                                         equipmentImage: $vm.equipment.image,
                                         equipmentQuality: $vm.equipment.quality,
                                         equipmentBasicStat: $vm.equipment.basicStat,
                                         equipmentOptionStat: $vm.equipment.optionStat,
                                         equipmentBasicText: $vm.equipment.basicText,
                                         equipmentOptionText: $vm.equipment.optionText,
                                         equipmentColor: $vm.equipment.color,
                                         equipmentQulityColor: $vm.equipment.qualityColor)
            }
        } else if vm.isEquipmentsViewStatus == 2 {
            Button(action: {
                vm.isEquipmentsViewStatus = 0
            } ) {
                EngravingDescriptionView(engravingName: $vm.engraving.name,
                                         engravingImage: $vm.engraving.image,
                                         engravingColor: $vm.engraving.color,
                                         engravingDescription: $vm.engraving.description,
                                         engravingLevel: $vm.engraving.level,
                                         engravingText: $vm.engraving.text)
            }
        } else if vm.isEquipmentsViewStatus == 3 {
            Button(action: {
                vm.isEquipmentsViewStatus = 0
            } ) {
                AccessoriesDescriptionView(accessoriesName: $vm.accessories.name,
                                           accessoriesImage: $vm.accessories.image,
                                           accessoriesColor: $vm.accessories.color,
                                           accessoriesOptionalText: $vm.accessories.optionalText,
                                           accessoriesOptionalStat: $vm.accessories.optionalStat,
                                           accessoriesRandomEffect1: $vm.accessories.randomEffect1,
                                           accessoriesRandomEffect2: $vm.accessories.randomEffect2,
                                           accessoriesRandomEffect3: $vm.accessories.randomEffect3,
                                           accessoriesQuality: $vm.accessories.quality,
                                           accessoriesQualityColor: $vm.accessories.qualityColor,
                                           accessoriesRandomEffectText: $vm.accessories.randomEffectText)
            }
        } else if vm.isEquipmentsViewStatus == 4 {
            Button(action: {
                vm.isEquipmentsViewStatus = 0
            } ) {
                BraceletDescriptionView(braceletName: $vm.bracelet.name,
                                        braceletImage: $vm.bracelet.image,
                                        braceletColor: $vm.bracelet.color,
                                        braceletStatText: $vm.bracelet.statText,
                                        braceletOptionalStat: $vm.bracelet.optionalStat,
                                        braceletEnchantText: $vm.bracelet.enchantText)
            }
        } else if vm.isEquipmentsViewStatus == 5 {
            Button(action: {
                vm.isEquipmentsViewStatus = 0
            } ) {
                AbilityStoneDescriptionView(abilitystoneName: $vm.abilitystone.name,
                                            abilitystoneImage: $vm.abilitystone.image,
                                            abilitystoneColor: $vm.abilitystone.color,
                                            abilitystoneBasicText: $vm.abilitystone.basicText,
                                            abilitystoneBasicStat: $vm.abilitystone.basicStat,
                                            abilitystoneOptionText: $vm.abilitystone.optionText,
                                            abilitystoneOptionStat: $vm.abilitystone.optionStat,
                                            abilitystoneOption1Text: $vm.abilitystone.option1Text,
                                            abilitystoneOption2Text: $vm.abilitystone.option2Text,
                                            abilitystoneOption3Text: $vm.abilitystone.option3Text,
                                            abilitystoneQuality: $vm.abilitystone.quality,
                                            abilitystoneQulityColor: $vm.abilitystone.qualityColor)
            }
        }
    }
}

그리고 각각 장비, 각성, 장신구, 팔찌, 어빌스톤 뷰를 나누어 주었습니다.

728x90
반응형
LIST