From 3c4404dc7cda08c1078728a489d642690fdffe40 Mon Sep 17 00:00:00 2001 From: Darkatse <39111369+Darkatse@users.noreply.github.com> Date: Thu, 5 Sep 2024 23:01:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=B3=E5=8D=A1=E6=89=8B?= =?UTF-8?q?=E5=8A=A8=E9=80=89=E6=8B=A9=20&=20=E8=90=A8=E5=8D=A1=E5=85=B9?= =?UTF-8?q?=E8=82=89=E9=B8=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/src/events/config.rs | 18 ++++ src-tauri/src/events/mod.rs | 2 +- src-tauri/src/main.rs | 6 +- src/apis/FightStages.ts | 105 +++++++++++++++++++++ src/components/OneKey/FightSetting.vue | 32 +++++-- src/components/OneKey/RoguelikeSetting.vue | 3 +- 6 files changed, 155 insertions(+), 11 deletions(-) create mode 100644 src/apis/FightStages.ts diff --git a/src-tauri/src/events/config.rs b/src-tauri/src/events/config.rs index cb9b71c..0e87e6a 100644 --- a/src-tauri/src/events/config.rs +++ b/src-tauri/src/events/config.rs @@ -156,4 +156,22 @@ pub fn get_item_index() -> payload::Payload { .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 { + 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 { + 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) } \ No newline at end of file diff --git a/src-tauri/src/events/mod.rs b/src-tauri/src/events/mod.rs index de2e4d9..a8a8695 100644 --- a/src-tauri/src/events/mod.rs +++ b/src-tauri/src/events/mod.rs @@ -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; diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 8f47ac1..b9d3989 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -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, }; @@ -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) diff --git a/src/apis/FightStages.ts b/src/apis/FightStages.ts new file mode 100644 index 0000000..8fa7bce --- /dev/null +++ b/src/apis/FightStages.ts @@ -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): 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 => { + try { + const result = await invoke('get_fight_stages'); + const sideStoryData = await invoke('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; \ No newline at end of file diff --git a/src/components/OneKey/FightSetting.vue b/src/components/OneKey/FightSetting.vue index 394ce0f..da188ef 100644 --- a/src/components/OneKey/FightSetting.vue +++ b/src/components/OneKey/FightSetting.vue @@ -91,14 +91,18 @@ " > - - - + + (userConfigStore.GetTaskParams('Fight') as FightTaskParams) @@ -168,7 +174,19 @@ const drops_set = () => { } } +// Reactive data for stages +const stage_options = ref([]); +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] } diff --git a/src/components/OneKey/RoguelikeSetting.vue b/src/components/OneKey/RoguelikeSetting.vue index 44fe2b2..df31a0e 100644 --- a/src/components/OneKey/RoguelikeSetting.vue +++ b/src/components/OneKey/RoguelikeSetting.vue @@ -23,6 +23,7 @@ + @@ -40,7 +41,7 @@ @change="modeChange" :disabled="userConfig!.status == 1 && params.enable" > - +