diff --git a/MeoAsstMac/Task Configurations/CopilotConfiguration.swift b/MeoAsstMac/Task Configurations/CopilotConfiguration.swift index 6221ceb88..dbb60dd8a 100644 --- a/MeoAsstMac/Task Configurations/CopilotConfiguration.swift +++ b/MeoAsstMac/Task Configurations/CopilotConfiguration.swift @@ -7,17 +7,75 @@ import Foundation -struct RegularCopilotConfiguration: Codable { +struct RegularCopilotConfiguration: Codable, Hashable { var enable = true + var filename: String + + struct CopilotItem: Codable, Hashable { + let filename: String + let stage_name: String + let is_raid: Bool + } + + var copilot_list: [CopilotItem] + + var loop_times = 1 + + var use_sanity_potion = false + var formation = false + var formation_index = 0 + static let formationCount = 4 + + struct UserUnit: Codable, Hashable { + let name: String + let skill: Int + } + + var user_additional = [UserUnit]() + var add_trust = false + var ignore_requirements = false + + enum SupportUnitUsage: Int, CaseIterable, Codable { + /// 不加助战干员 + case none = 0 + /// 如果仅缺一名干员则尝试补助战 + case whenNeeded = 1 + /// 如果仅缺一名干员则尝试补助战,如无缺失则随机加一个助战干员 + case random = 3 + /// 如果仅缺一名干员则尝试补助战,如无缺失则使用指定助战干员 + case specific = 2 + + var description: String { + switch self { + case .none: + return String(localized: "不借", comment: "") + case .whenNeeded: + return String(localized: "补漏", comment: "") + case .specific: + return String(localized: "指定", comment: "") + case .random: + return String(localized: "随机", comment: "") + } + } + } + + var support_unit_usage: SupportUnitUsage = .none + var support_unit_name = "" } -struct SSSCopilotConfiguration: Codable { - var enable = true - var filename: String - var loop_times = 1 +typealias SSSCopilotConfiguration = RegularCopilotConfiguration + +extension RegularCopilotConfiguration { + init(filename: String) { + self.init(filename: filename, copilot_list: []) + } + + init(copilotList: [CopilotItem]) { + self.init(filename: "", copilot_list: copilotList) + } } struct VideoRecognitionConfiguration: Codable { @@ -29,7 +87,7 @@ struct VideoRecognitionConfiguration: Codable { } } -enum CopilotConfiguration { +enum CopilotConfiguration: Hashable { case regular(RegularCopilotConfiguration) case sss(SSSCopilotConfiguration) diff --git a/MeoAsstMac/Views/CopilotView.swift b/MeoAsstMac/Views/CopilotView.swift index b00662e38..82497fd61 100644 --- a/MeoAsstMac/Views/CopilotView.swift +++ b/MeoAsstMac/Views/CopilotView.swift @@ -14,15 +14,16 @@ struct CopilotView: View { var body: some View { if let copilot = MAACopilot(url: url) { VStack(spacing: 20) { - pilotConfiguration() + CopilotConfigView(config: $viewModel.copilot).padding(.top) Divider() ScrollView { - pilotDescription(pilot: copilot) + CopilotDescriptionView(pilot: copilot) } } .task(id: url) { updateCopilot() } + .animation(.default, value: formation) } else { Text("文件格式错误") } @@ -41,41 +42,96 @@ struct CopilotView: View { MAACopilot(url: url) } - // MARK: - Copilot Config - - @ViewBuilder private func pilotConfiguration() -> some View { + private var formation: Bool { switch viewModel.copilot { case .regular(let innerConfig): - let binding = Binding { + innerConfig.formation + default: + false + } + } +} + +// MARK: - Copilot Config + +private struct CopilotConfigView: View { + @Binding var config: CopilotConfiguration? + + var body: some View { + switch config { + case .regular(let innerConfig): + let binding = Binding { innerConfig } set: { newValue in - viewModel.copilot = .regular(newValue) + self.config = .regular(newValue) } - HStack { - Toggle("自动编队", isOn: binding.formation) - Toggle("信赖干员", isOn: binding.add_trust) - } - + RegularCopilotConfigView(config: binding) case .sss(let innerConfig): - let binding = Binding { + let binding = Binding { innerConfig } set: { newValue in - viewModel.copilot = .sss(newValue) + self.config = .sss(newValue) } - HStack { - Text("循环次数") - TextField("1", value: binding.loop_times, format: .number) - } - .frame(maxWidth: 130) - + SSSCopilotConfigView(config: binding) case .none: EmptyView() } } +} - // MARK: - Copilot Document +private struct RegularCopilotConfigView: View { + @Binding var config: RegularCopilotConfiguration - @ViewBuilder private func pilotDescription(pilot: MAACopilot) -> some View { + var body: some View { + VStack { + Toggle("自动编队", isOn: $config.formation) + if config.formation { + HStack { + Picker("编队栏位", selection: $config.formation_index) { + Text("当前").tag(0) + ForEach(0..