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

增加关卡手动选择 & 萨卡兹肉鸽 #1

Merged
merged 1 commit into from
Sep 6, 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
18 changes: 18 additions & 0 deletions src-tauri/src/events/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,22 @@ pub fn get_item_index() -> payload::Payload<serde_json::Value> {
.unwrap_or_else(|err| panic!("读取{}失败:{}",maa_cli::data_dir().join(&"resource").join(&"item_index.json").to_str().unwrap(), err.to_string()));
let data =serde_json::from_str(&item_index_str).unwrap_or_else(|err| panic!("读取{}失败:{}",maa_cli::data_dir().join(&"resource").join(&"item_index.json").to_str().unwrap(), err.to_string()));
payload::new(consts::SUCCESS, "success".to_string(), data)
}

#[tauri::command]
pub fn get_fight_stages() -> payload::Payload<serde_json::Value> {
let fight_stages_str =
fs::read_to_string(maa_cli::data_dir().join(&"resource").join(&"stages.json"))
.unwrap_or_else(|err| panic!("读取{}失败:{}",maa_cli::data_dir().join(&"resource").join(&"stages.json").to_str().unwrap(), err.to_string()));
let data =serde_json::from_str(&fight_stages_str).unwrap_or_else(|err| panic!("读取{}失败:{}",maa_cli::data_dir().join(&"resource").join(&"stages").to_str().unwrap(), err.to_string()));
payload::new(consts::SUCCESS, "success".to_string(), data)
}

#[tauri::command]
pub fn get_current_sidestory() -> payload::Payload<serde_json::Value> {
let sidestory_stages_str =
fs::read_to_string(maa_cli::data_dir().join(&"MaaResource").join(&"cache").join(&"resource").join(&"tasks.json"))
.unwrap_or_else(|err| panic!("读取{}失败:{}",maa_cli::data_dir().join(&"MaaResource").join(&"cache").join(&"resource").join(&"tasks.json").to_str().unwrap(), err.to_string()));
let data =serde_json::from_str(&sidestory_stages_str).unwrap_or_else(|err| panic!("读取{}失败:{}",maa_cli::data_dir().join(&"MaaResource").join(&"cache").join(&"resource").join(&"tasks.json").to_str().unwrap(), err.to_string()));
payload::new(consts::SUCCESS, "success".to_string(), data)
}
2 changes: 1 addition & 1 deletion src-tauri/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod payload;
mod run;
mod update;
pub use config::{
delete_user_config, get_cli_config, get_item_index, get_user_configs, save_cli_config,
delete_user_config, get_cli_config, get_item_index, get_fight_stages, get_current_sidestory, get_user_configs, save_cli_config,
save_core_config, save_task_config,
};
pub use init::init_process;
Expand Down
6 changes: 4 additions & 2 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use tauri::{
};

use events::{
copilot, delete_user_config, get_cli_config, get_item_index, get_user_configs,
ignore_maa_cli_update, init_process, maa_cli_update_process, one_key, save_cli_config,
copilot, delete_user_config, get_cli_config, get_item_index, get_fight_stages, get_current_sidestory,
get_user_configs, ignore_maa_cli_update, init_process, maa_cli_update_process, one_key, save_cli_config,
save_core_config, save_task_config, stop,
};

Expand Down Expand Up @@ -67,6 +67,8 @@ fn main() {
ignore_maa_cli_update,
maa_cli_update_process,
get_item_index,
get_fight_stages,
get_current_sidestory,
copilot
])
.system_tray(tray)
Expand Down
105 changes: 105 additions & 0 deletions src/apis/FightStages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { invoke } from '@tauri-apps/api/tauri';

interface StageItem {
value: string;
label: string;
}

interface StageData {
stageId: string;
code: string;
}

interface Payload {
code: number;
msg: string;
data: StageData[];
}

// 标准 / 磨难
const StageExtraSuffix = {
NORMAL: '-NORMAL',
TOUGH: '-HARD',
}

const currentStages: StageItem[] = [
{ label: '当前关卡/上次作战', value: '' },
]

const appendSuffixAndCreateItems = (stage: any, suffix: string) => {
const suffixLabel = suffix === StageExtraSuffix.NORMAL ? ' (标准)' : ' (磨难)';
return {
value: stage.code + suffix,
label: stage.code + suffixLabel
};
};

const basicSupportStages: StageItem[] = [
{ label: '1-7', value: '1-7' },
{ label: '剿灭', value: 'Annihilation' },
{ label: '龙门币-6/5', value: 'CE-6' },
{ label: '经验-6/5', value: 'LS-6' },
{ label: '红票-5', value: 'AP-5' },
{ label: '技能-5', value: 'CA-5' },
{ label: '重装/医疗-小', value: 'PR-A-1' },
{ label: '重装/医疗-大', value: 'PR-A-2' },
{ label: '狙击/术士-小', value: 'PR-B-1' },
{ label: '狙击/术士-大', value: 'PR-B-2' },
{ label: '辅助/先锋-小', value: 'PR-C-1' },
{ label: '辅助/先锋-大', value: 'PR-C-2' },
{ label: '特种/近卫-小', value: 'PR-D-1' },
{ label: '特种/近卫-大', value: 'PR-D-2' },
]

function filterSideStoryStages(sideStoryData: Record<string, any>): StageItem[] {
const stageItems: StageItem[] = [];

for (const key of Object.keys(sideStoryData)) {
// 只取出有效的关卡名称
const parts = key.split('-');
if (parts.length > 1 && /^\d+$/.test(parts[1])) {
stageItems.push({
value: key,
label: key
});
}
}

return stageItems;
}

const GetFightStages = async (): Promise<StageItem[]> => {
try {
const result = await invoke<Payload>('get_fight_stages');
const sideStoryData = await invoke<Payload>('get_current_sidestory');

const filteredStages = result.data
.filter(stage => stage.stageId.includes('main') || stage.stageId.includes('sub'))
.flatMap(stage => {
// 只要关卡号开头为9(如 9-1, 9-2 等)
if (stage.code.startsWith('9-')) {
return [appendSuffixAndCreateItems(stage, StageExtraSuffix.NORMAL)];
}
// 处理关卡号开头为10或更高的情况(如 10-1, 11-1, 12-1 等)
else if (/^1[0-9]-/.test(stage.code)) {
return [
appendSuffixAndCreateItems(stage, StageExtraSuffix.NORMAL),
appendSuffixAndCreateItems(stage, StageExtraSuffix.TOUGH)
];
}
return [{ value: stage.code, label: stage.code }];
});

const filteredSideStoryStages = filterSideStoryStages(sideStoryData.data);

// 合并全部可选关卡
return [...currentStages, ...filteredSideStoryStages,...basicSupportStages, ...filteredStages];
} catch (error) {
console.error('Failed to retrieve fight stages:', error);
return [];
}
}

export type { StageItem };

export default GetFightStages;
32 changes: 25 additions & 7 deletions src/components/OneKey/FightSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,18 @@
"
>
<el-form-item label="关卡">
<el-tooltip
class="box-item"
effect="dark"
content="不填刷上次关卡,可在关卡结尾输入Normal/Hard表示需要切换标准与磨难难度,剿灭作战,必须输入Annihilation"
placement="top"
<el-select
v-model="params.stage"
:disabled="userConfig!.status == 1 && params.enable"
:loading="StageLoading"
>
<el-input v-model="params.stage" :disabled="userConfig!.status == 1 && params.enable" />
</el-tooltip>
<el-option
v-for="stage in stage_options"
:key="stage.value"
:label="stage.label"
:value="stage.value"
/>
</el-select>
</el-form-item>
<el-form-item label="指定次数">
<el-input-number
Expand Down Expand Up @@ -129,6 +133,8 @@ import { type FightTaskParams } from '@/stores/tasks/Fight'
import { onMounted, ref } from 'vue'
import GetFightItems from '@/apis/ItemIndex'
import { type FightItem } from '@/apis/ItemIndex'
import GetFightStages from '@/apis/FightStages'
import { type StageItem } from '@/apis/FightStages'
const userConfigStore = UserConfigStore()
const dialogVisible = ref(userConfigStore.GetSettingDialogObj())
const params = ref<FightTaskParams>(userConfigStore.GetTaskParams('Fight') as FightTaskParams)
Expand Down Expand Up @@ -168,7 +174,19 @@ const drops_set = () => {
}
}

// Reactive data for stages
const stage_options = ref<StageItem[]>([]);
const StageLoading = ref(false);

// Fetch stages data when needed
const fetchStages = async () => {
StageLoading.value = true;
stage_options.value = await GetFightStages();
StageLoading.value = false;
};

onMounted(() => {
fetchStages();
if (params.value.drops) {
drops_value.value = Object.keys(params.value.drops)[0]
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/OneKey/RoguelikeSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<el-option label="傀影与猩红血钻" value="Phantom" default />
<el-option label="水月与深蓝之树" value="Mizuki" />
<el-option label="探索者的银凇止境" value="Sami" />
<el-option label="萨卡兹的无终奇语" value="Sarkaz" />
</el-select>
</el-form-item>
<el-form-item label="开始探索次数">
Expand All @@ -40,7 +41,7 @@
@change="modeChange"
:disabled="userConfig!.status == 1 && params.enable"
>
<el-option label="刷蜡烛" :value="0" default />
<el-option label="刷蜡烛/通关" :value="0" default />
<el-option label="刷源石锭" :value="1" />
<el-option label="刷开局" :value="4" />
<el-option label="刷坍缩范式" :value="5" />
Expand Down