Skip to content

Commit

Permalink
chore: 拆一下main
Browse files Browse the repository at this point in the history
  • Loading branch information
dongwlin committed Nov 23, 2023
1 parent b107722 commit 21badc3
Show file tree
Hide file tree
Showing 9 changed files with 410 additions and 386 deletions.
7 changes: 5 additions & 2 deletions source/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include_directories(${CMAKE_SOURCE_DIR}/deps/include)
include_directories(${CMAKE_SOURCE_DIR}/deps/include)
if (WIN32)
link_directories(${CMAKE_SOURCE_DIR}/deps/lib)
else ()
Expand All @@ -9,7 +9,10 @@ set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CONFIGURATION_TYPES "Release")

add_executable(MAABH3_CLI
main.cpp
main.cpp
control.cpp
device.cpp
tasks.cpp
CustomAction/CustomAction.cpp
CustomAction/CustomActionRegistrar.cpp
CustomAction/CombatAction.cpp
Expand Down
32 changes: 32 additions & 0 deletions source/cli/control.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "control.h"

bool default_control_init(ControlConfig& control)
{
int server = 0;
if (!select_server(server)) {
return false;
}
control.set_config_server(server);
return true;
}

bool select_server(int& server)
{
std::cout << std::endl
<< "Please select server number: " << std::endl
<< std::endl
<< " 1. Official(CN)\n"
" 2. Bilibili\n"
" 3. Vivo\n"
<< std::endl
<< "Please enter the server number: " << std::endl;

std::cin >> server;

if (server < 1 || server > 3) {
std::cout << "Unknown server number: " << server << std::endl;
return false;
}

return true;
}
7 changes: 7 additions & 0 deletions source/cli/control.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include "Config/ControlConfig.h"

bool default_control_init(ControlConfig& control);

bool select_server(int& server);
125 changes: 125 additions & 0 deletions source/cli/device.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#include "device.h"

bool default_device_init(DeviceConfig& device)
{
std::string name, SN, adb;
if (!select_device(name, SN, adb)) {
return false;
}
device.set_config_device_name(name);
device.set_config_device_SN(SN);
device.set_config_adb(adb);
return true;
}

MaaSize scanning_devices()
{
std::cout << "Scanning for Devices..." << std::endl;
auto device_size = MaaToolKitFindDevice();
if (device_size == 0) {
std::cout << "No Devices Found" << std::endl;
return 0;
}
std::cout << "Scanning Finished" << std::endl;
return device_size;
}

bool select_device(std::string& name, std::string& SN, std::string& adb)
{
auto device_size = scanning_devices();
if (!device_size) {
if (!manually_enter_device_info(name, SN, adb)) {
return false;
}
return true;
}
MaaSize number = 0;
if (!select_device_number(device_size, number)) {
return false;
}
if (!number) {
if (!manually_enter_device_info(name, SN, adb)) {
return false;
}
return true;
}
MaaSize device_index = number - 1;
name = MaaToolKitGetDeviceName(device_index);
SN = MaaToolKitGetDeviceAdbSerial(device_index);
adb = MaaToolKitGetDeviceAdbPath(device_index);
AdbConfigCache adb_config_cache;
if (!adb_config_cache.has(name, SN)) {
adb_config_cache.set_adb_config(name, SN, MaaToolKitGetDeviceAdbConfig(device_index));
}
return true;
}

bool select_device_number(const MaaSize& device_size, MaaSize& number)
{
std::cout << std::endl << "Please select a device:" << std::endl << std::endl;
std::cout << " 0. Manual" << std::endl;
print_device_list(device_size);
std::cout << std::endl << "Please enter option number:" << std::endl;

std::cin >> number;
std::cin.ignore();

if (number > device_size) {
std::cout << std::endl << "Unknown option number: " << number << std::endl;
return false;
}

return true;
}

void print_device_list(const MaaSize& device_size)
{
for (MaaSize i = 0; i < device_size; i++) {
std::cout << " " << i + 1 << ". " << MaaToolKitGetDeviceName(i) << " (" << MaaToolKitGetDeviceAdbSerial(i)
<< ")\n";
}
}

bool manually_enter_device_info(std::string& name, std::string& SN, std::string& adb)
{
if (!manually_enter_device_name(name)) {
return false;
}
if (!manually_enter_device_SN(SN)) {
return false;
}
if (!manually_enter_device_adb(adb)) {
return false;
}
return true;
}

bool manually_enter_device_name(std::string& name)
{
std::cout << std::endl << "Please enter device name: " << std::endl;
std::getline(std::cin, name);
if (name.empty()) {
return false;
}
return true;
}

bool manually_enter_device_SN(std::string& SN)
{
std::cout << std::endl << "Please enter device serial number: " << std::endl;
std::getline(std::cin, SN);
if (SN.empty()) {
return false;
}
return true;
}

bool manually_enter_device_adb(std::string& adb)
{
std::cout << std::endl << "Please enter adb path: " << std::endl;
std::getline(std::cin, adb);
if (adb.empty()) {
return false;
}
return true;
}
25 changes: 25 additions & 0 deletions source/cli/device.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include <MaaToolKit/MaaToolKitAPI.h>
#include <MaaFramework/MaaDef.h>

#include "Config/DeviceConfig.h"
#include "Cache/AdbConfigCache.h"

bool default_device_init(DeviceConfig& device);

MaaSize scanning_devices();

bool select_device(std::string& name, std::string& SN, std::string& adb);

bool select_device_number(const MaaSize& device_size, MaaSize& number);

void print_device_list(const MaaSize& device_size);

bool manually_enter_device_info(std::string& name, std::string& SN, std::string& adb);

bool manually_enter_device_name(std::string& name);

bool manually_enter_device_SN(std::string& SN);

bool manually_enter_device_adb(std::string& adb);
Loading

0 comments on commit 21badc3

Please sign in to comment.