Skip to content

Commit

Permalink
alpha build 1
Browse files Browse the repository at this point in the history
  • Loading branch information
hguandl committed Oct 10, 2022
1 parent f5bb76b commit afb42c3
Show file tree
Hide file tree
Showing 23 changed files with 1,614 additions and 12 deletions.
54 changes: 54 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
MeoAsstMac/Resources/resource.zip

# Created by https://www.toptal.com/developers/gitignore/api/xcode,macos
# Edit at https://www.toptal.com/developers/gitignore?templates=xcode,macos

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

### Xcode ###
## User settings
xcuserdata/

## Xcode 8 and earlier
*.xcscmblueprint
*.xccheckout

### Xcode Patch ###
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcworkspace/contents.xcworkspacedata
/*.gcno
**/xcshareddata/WorkspaceSettings.xcsettings

# End of https://www.toptal.com/developers/gitignore/api/xcode,macos
Expand Down
Binary file added ExternalTools/adb
Binary file not shown.
10 changes: 10 additions & 0 deletions ExternalTools/adb.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.inherit</key>
<true/>
</dict>
</plist>
9 changes: 9 additions & 0 deletions MeoAssistant/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
DerivedData/
.swiftpm/config/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
24 changes: 24 additions & 0 deletions MeoAssistant/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "MeoAssistant",
platforms: [.macOS(.v11)],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(name: "MeoAssistant", targets: ["MeoAssistant"]),
.library(name: "opencv2", targets: ["opencv2"])
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.binaryTarget(name: "MeoAssistant", path: "../../../build/MeoAssistant.xcframework"),
.binaryTarget(name: "opencv2", path: "../../../build/opencv2.xcframework")
]
)
3 changes: 3 additions & 0 deletions MeoAssistant/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# MeoAssistant

Metapackage for OpenCV and MeoAssistant.
170 changes: 167 additions & 3 deletions MeoAsstMac.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions MeoAsstMac/ConnectionSettingsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// ConnectionSettingsView.swift
// MeoAsstMac
//
// Created by hguandl on 10/10/2022.
//

import SwiftUI

struct ConnectionSettingsView: View {
@EnvironmentObject private var appDelegate: AppDelegate

var body: some View {
VStack {
HStack {
Text("ADB地址")
TextField("", text: $appDelegate.connectionAddress)
}
}
.padding(.horizontal)
}
}

struct ConnectionSettingsView_Previews: PreviewProvider {
static var previews: some View {
ConnectionSettingsView()
}
}
34 changes: 29 additions & 5 deletions MeoAsstMac/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,38 @@
import SwiftUI

struct ContentView: View {
@EnvironmentObject private var appDelegate: AppDelegate

@State private var tab = 1

var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundColor(.accentColor)
Text("Hello, world!")
TabView(selection: $tab) {
ManageView().tabItem { Text("一键长草") }.tag(1)
Text("敬请期待").tabItem { Text("自动战斗") }.tag(2)
Text("敬请期待").tabItem { Text("公招识别") }.tag(3)
Text("敬请期待").tabItem { Text("仓库识别 beta") }.tag(4)
SettingsView().tabItem { Text("设置") }.tag(5)
}
.padding()
.sheet(isPresented: $appDelegate.extractingResource, content: {
ProgressView("解压数据中").padding()
})
.onAppear {
appDelegate.initializeResource()
appDelegate.initializeMaa()
}
}
}

// Removes background from List in SwiftUI
extension NSTableView {
override open func viewDidMoveToWindow() {
super.viewDidMoveToWindow()

backgroundColor = NSColor.clear
if let esv = enclosingScrollView {
esv.drawsBackground = false
}
}
}

Expand Down
58 changes: 58 additions & 0 deletions MeoAsstMac/FightSettingsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// FightSettingsView.swift
// MeoAsstMac
//
// Created by hguandl on 9/10/2022.
//

import SwiftUI

struct FightSettingsView: View {
@EnvironmentObject private var appDelegate: AppDelegate

var body: some View {
VStack(alignment: .leading) {
HStack {
Toggle("吃理智药", isOn: $appDelegate.useSanityPotion).frame(width: 80, alignment: .leading)
TextField("", value: $appDelegate.sanityPotion, format: .number).frame(width: 80)
}
HStack {
Toggle("吃源石*", isOn: $appDelegate.useOriginitePrime).frame(width: 80, alignment: .leading)
TextField("", value: $appDelegate.originitePrime, format: .number).frame(width: 80)
}
HStack {
Toggle("指定次数*", isOn: $appDelegate.limitPerformBattles).frame(width: 80, alignment: .leading)
TextField("", value: $appDelegate.performBattles, format: .number).frame(width: 80)
}
Toggle(isOn: .constant(false)) {
Picker("指定材料", selection: .constant(0)) {}
}
.disabled(true)
Picker("关卡选择", selection: $appDelegate.stageSelect) {
Text("当前/上次").tag("")
Text("1-7").tag("1-7")
Text("CE-6").tag("CE-6")
Text("AP-5").tag("AP-5")
Text("CA-5").tag("CA-5")
Text("LS-6").tag("LS-5")
Text("剿灭模式").tag("Annihilation")
}
Picker("剩余理智", selection: $appDelegate.remainingSanityStage) {
Text("不选择").tag("")
Text("1-7")
Text("龙门币 CE-6").tag("CE-6")
Text("红票 AP-5").tag("AP-5")
Text("技能书 CA-5").tag("CA-5")
Text("经验书 LS-6").tag("LS-5")
Text("剿灭模式").tag("Annihilation")
}
Text("标注 * 的选项重启后不保存").font(.footnote)
}
}
}

struct FightSettingsView_Previews: PreviewProvider {
static var previews: some View {
FightSettingsView()
}
}
75 changes: 75 additions & 0 deletions MeoAsstMac/InfrastSettingsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//
// InfrastSettingsView.swift
// MeoAsstMac
//
// Created by hguandl on 9/10/2022.
//

import SwiftUI

struct InfrastSettingsView: View {
@EnvironmentObject private var appDelegate: AppDelegate

@Environment(\.defaultMinListRowHeight) private var rowHeight

var body: some View {
VStack {
HStack {
List {
ForEach(appDelegate.facilities, id: \.name) { facility in
Toggle(facility.description, isOn: binding(for: facility))
}
.onMove { source, destination in
appDelegate.facilities.move(fromOffsets: source, toOffset: destination)
}
}
.frame(height: 12 * rowHeight)

Form {
Section {
Text("无人机用途")
Picker("", selection: $appDelegate.droneUsage) {
ForEach(DroneUsage.allCases, id: \.self) { usage in
Text(usage.description).tag(usage.rawValue)
}
}
.padding(.bottom)
}
Divider()
Section {
Text("基建工作心情阈值: \(appDelegate.dormThreshold * 100, specifier: "%.0f")%")
Slider(value: $appDelegate.dormThreshold, in: 0 ... 1)
}
Divider()
Section {
Toggle("宿舍空余位置蹭信赖", isOn: $appDelegate.dormTrust)
Toggle("不将已进驻的干员放入宿舍", isOn: $appDelegate.dormFilterStationed)
Toggle("源石碎片自动补货", isOn: $appDelegate.originiumReplenishment)
}
}
}
.padding()

Toggle("启用自定义基建配置(beta)", isOn: .constant(false)).disabled(true)
.padding(.vertical)
}
}

// MARK: Custom bindings

private func binding(for facility: MaaInfrastFacility) -> Binding<Bool> {
return Binding {
facility.enabled
} set: { newValue in
if let i = appDelegate.facilities.firstIndex(where: { $0.name == facility.name }) {
appDelegate.facilities[i].enabled = newValue
}
}
}
}

struct InfrastSettingsView_Previews: PreviewProvider {
static var previews: some View {
InfrastSettingsView()
}
}
70 changes: 70 additions & 0 deletions MeoAsstMac/Maa.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// Maa.swift
// MeoAsstMac
//
// Created by hguandl on 9/10/2022.
//

import Foundation
import MeoAssistant

public struct Maa {
static var resourceLoaded = false

private let handle: AsstHandle

public static func loadResource(path: String) -> Bool {
if AsstLoadResource(path) {
resourceLoaded = true
return true
}
return false
}

public static func setUserDirectory(path: String) -> Bool {
AsstSetUserDir(path)
}

public init() {
let callback: AsstApiCallback = { msg, details, _ in
if msg >= 20000 {
return
}
if let details = details {
let details = String(cString: details, encoding: .utf8) ?? "<nil>"
let message = MaaMessage(msg: msg, details: details)
Self.publishLogMessage(message: message)
}
}

self.handle = AsstCreateEx(callback, nil)
}

public func appendTask(taskType: String, taskConfig: String) -> Int32 {
AsstAppendTask(handle, taskType, taskConfig)
}

public func connect(adbPath: String, address: String) -> Bool {
AsstConnect(handle, adbPath, address, "General")
}

public func start() -> Bool {
AsstStart(handle)
}

public func stop() -> Bool {
AsstStop(handle)
}

public var running: Bool {
AsstRunning(handle)
}

static func publishLogMessage(message: MaaMessage) {
NotificationCenter.default.post(name: .MAAReceivedCallbackMessage, object: message)
}
}

public extension Notification.Name {
static let MAAReceivedCallbackMessage = Notification.Name("MAAReceivedCallbackMessage")
}
Loading

0 comments on commit afb42c3

Please sign in to comment.