mirror of
https://github.com/AkiChase/scrcpy-mask
synced 2025-02-22 23:12:16 +08:00
feat(KeyBoard): import default key config
This commit is contained in:
parent
d708bfe7e8
commit
5c23ced8b5
1
src-tauri/resource/default-key-config.json
Normal file
1
src-tauri/resource/default-key-config.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
[{"relativeSize":{"w":1280,"h":720},"title":"王者荣耀-暃","list":[{"type":"SteeringWheel","note":"方向轮盘","key":{"left":"KeyA","right":"KeyD","up":"KeyW","down":"KeyS"},"posX":180,"posY":560,"offset":100,"pointerId":1},{"type":"DirectionalSkill","note":"技能1","key":"KeyQ","posX":950,"posY":610,"range":200,"pointerId":2},{"type":"DirectionalSkill","note":"技能2","key":"AltLeft","posX":1025,"posY":500,"range":200,"pointerId":2},{"type":"DirectionalSkill","note":"技能3","key":"KeyE","posX":1160,"posY":420,"range":200,"pointerId":2},{"type":"TriggerWhenPressedSkill","note":"技能3","key":"M4","posX":1160,"posY":420,"directional":true,"rangeOrTime":0,"pointerId":2},{"type":"DirectionlessSkill","note":"无方向装备技能","key":"M1","posX":1150,"posY":280,"pointerId":2},{"type":"CancelSkill","note":"取消技能","key":"Space","posX":1160,"posY":140,"pointerId":2},{"type":"Tap","note":"回城","key":"KeyB","time":80,"posX":650,"posY":650,"pointerId":3},{"type":"Tap","note":"回复","key":"KeyC","time":80,"posX":740,"posY":650,"pointerId":3},{"type":"DirectionalSkill","note":"召唤师技能","key":"KeyF","posX":840,"posY":650,"range":200,"pointerId":2},{"type":"TriggerWhenPressedSkill","note":"无方向召唤师技能","key":"ControlLeft","posX":840,"posY":650,"directional":false,"rangeOrTime":80,"pointerId":3},{"type":"Tap","note":"攻击","key":"M2","time":80,"posX":1165,"posY":620,"pointerId":3},{"type":"Tap","note":"技能1升级","key":"Digit1","time":80,"posX":880,"posY":560,"pointerId":3},{"type":"Tap","note":"技能2升级","key":"Digit2","time":80,"posX":960,"posY":430,"pointerId":3},{"type":"Tap","note":"技能3升级","key":"Digit3","time":80,"posX":1090,"posY":350,"pointerId":3},{"type":"Tap","note":"快速购买1","key":"Digit5","time":80,"posX":130,"posY":300,"pointerId":3},{"type":"Tap","note":"快速购买2","key":"Digit6","time":80,"posX":130,"posY":370,"pointerId":3},{"type":"TriggerWhenPressedSkill","note":"装备技能","key":"WheelDown","posX":1150,"posY":280,"directional":false,"rangeOrTime":80,"pointerId":3},{"type":"Observation","note":"观察","key":"M3","posX":1000,"posY":200,"scale":0.5,"pointerId":4},{"type":"Macro","note":"战绩面板","key":"Tab","macro":{"down":[{"type":"touch","args":["default",5,1185,40,80]}],"loop":null,"up":[{"type":"touch","args":["default",5,1220,100,80]}]},"posX":1185,"posY":40,"pointerId":5},{"type":"Macro","note":"商店","key":"ShiftLeft","macro":{"down":[{"type":"touch","args":["default",5,40,300,80]}],"loop":null,"up":[{"type":"touch","args":["default",5,1200,60,80]}]},"posX":40,"posY":300,"pointerId":5},{"type":"Macro","note":"地图","key":"KeyZ","macro":{"down":[{"type":"touch","args":["default",5,250,230,80]}],"loop":null,"up":[{"type":"touch","args":["default",5,640,150,80]}]},"posX":250,"posY":230,"pointerId":5}]}]
|
@ -4,10 +4,10 @@
|
|||||||
use scrcpy_mask::{
|
use scrcpy_mask::{
|
||||||
adb::{Adb, Device},
|
adb::{Adb, Device},
|
||||||
client::ScrcpyClient,
|
client::ScrcpyClient,
|
||||||
resource::ResHelper,
|
resource::{ResHelper, ResourceName},
|
||||||
socket::connect_socket,
|
socket::connect_socket,
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
use std::{fs::read_to_string, sync::Arc};
|
||||||
use tauri::Manager;
|
use tauri::Manager;
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@ -108,6 +108,16 @@ fn start_scrcpy_server(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn load_default_keyconfig(app: tauri::AppHandle) -> Result<String, String> {
|
||||||
|
let dir = app.path().resource_dir().unwrap().join("resource");
|
||||||
|
let file = ResHelper::get_file_path(&dir, ResourceName::DefaultKeyConfig);
|
||||||
|
match read_to_string(file) {
|
||||||
|
Ok(content) => Ok(content),
|
||||||
|
Err(e) => Err(e.to_string()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
@ -141,7 +151,16 @@ async fn main() {
|
|||||||
}))
|
}))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
None => {}
|
None => {
|
||||||
|
let main_window: tauri::WebviewWindow =
|
||||||
|
app.get_webview_window("main").unwrap();
|
||||||
|
main_window
|
||||||
|
.set_size(tauri::Size::Logical(tauri::LogicalSize {
|
||||||
|
width: (800 + 70) as f64,
|
||||||
|
height: (600 + 30) as f64,
|
||||||
|
}))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -162,7 +181,8 @@ async fn main() {
|
|||||||
adb_devices,
|
adb_devices,
|
||||||
forward_server_port,
|
forward_server_port,
|
||||||
push_server_file,
|
push_server_file,
|
||||||
start_scrcpy_server
|
start_scrcpy_server,
|
||||||
|
load_default_keyconfig
|
||||||
])
|
])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
|
@ -4,6 +4,7 @@ use std::path::PathBuf;
|
|||||||
pub enum ResourceName {
|
pub enum ResourceName {
|
||||||
Adb,
|
Adb,
|
||||||
ScrcpyServer,
|
ScrcpyServer,
|
||||||
|
DefaultKeyConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ResHelper {
|
pub struct ResHelper {
|
||||||
@ -32,6 +33,7 @@ impl ResHelper {
|
|||||||
ResourceName::Adb => dir.join("adb"),
|
ResourceName::Adb => dir.join("adb"),
|
||||||
|
|
||||||
ResourceName::ScrcpyServer => dir.join("scrcpy-server-v2.4"),
|
ResourceName::ScrcpyServer => dir.join("scrcpy-server-v2.4"),
|
||||||
|
ResourceName::DefaultKeyConfig => dir.join("default-key-config.json"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@ import KeySetting from "./KeySetting.vue";
|
|||||||
|
|
||||||
// TODO 右键空白区域添加按键
|
// TODO 右键空白区域添加按键
|
||||||
// TODO 左键可拖动按钮(并显示到顶部),右键按钮进行修改、删除
|
// TODO 左键可拖动按钮(并显示到顶部),右键按钮进行修改、删除
|
||||||
// TODO 导入默认配置(重复的用新名称)
|
|
||||||
// TODO 设置界面添加清空本地数据的按钮
|
// TODO 设置界面添加清空本地数据的按钮
|
||||||
|
// TODO 添加开发者工具打开按钮
|
||||||
|
|
||||||
const keyInfoShowFlag = ref(false);
|
const keyInfoShowFlag = ref(false);
|
||||||
</script>
|
</script>
|
||||||
|
@ -15,6 +15,8 @@ import {
|
|||||||
import { computed, onMounted, ref } from "vue";
|
import { computed, onMounted, ref } from "vue";
|
||||||
import { useGlobalStore } from "../../store/global";
|
import { useGlobalStore } from "../../store/global";
|
||||||
import { Store } from "@tauri-apps/plugin-store";
|
import { Store } from "@tauri-apps/plugin-store";
|
||||||
|
import { loadDefaultKeyconfig } from "../../invoke";
|
||||||
|
import { KeyMappingConfig } from "../../keyMappingConfig";
|
||||||
|
|
||||||
const store = useGlobalStore();
|
const store = useGlobalStore();
|
||||||
const localStore = new Store("store.bin");
|
const localStore = new Store("store.bin");
|
||||||
@ -141,6 +143,26 @@ function importKeyMappingConfig() {
|
|||||||
localStore.set("curKeyMappingIndex", store.curKeyMappingIndex);
|
localStore.set("curKeyMappingIndex", store.curKeyMappingIndex);
|
||||||
message.success("按键方案已导入");
|
message.success("按键方案已导入");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function importDefaultKeyMappingConfig() {
|
||||||
|
const data = await loadDefaultKeyconfig();
|
||||||
|
let defaultConfigs: KeyMappingConfig[];
|
||||||
|
let count = 0;
|
||||||
|
try {
|
||||||
|
defaultConfigs = JSON.parse(data);
|
||||||
|
for (const config of defaultConfigs) {
|
||||||
|
store.keyMappingConfigList.push(config);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
message.error("默认按键方案导入失败");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
localStore.set("keyMappingConfigList", store.keyMappingConfigList);
|
||||||
|
message.success(`已导入${count}个默认方案`);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -179,7 +201,7 @@ function importKeyMappingConfig() {
|
|||||||
<NFlex>
|
<NFlex>
|
||||||
<NButton @click="showImportModal = true">导入</NButton>
|
<NButton @click="showImportModal = true">导入</NButton>
|
||||||
<NButton>导出</NButton>
|
<NButton>导出</NButton>
|
||||||
<NButton>导入默认</NButton>
|
<NButton @click="importDefaultKeyMappingConfig">导入默认</NButton>
|
||||||
<NButton @click="showKeyInfoFlag = !showKeyInfoFlag">按键信息</NButton>
|
<NButton @click="showKeyInfoFlag = !showKeyInfoFlag">按键信息</NButton>
|
||||||
</NFlex>
|
</NFlex>
|
||||||
</div>
|
</div>
|
||||||
|
@ -29,4 +29,8 @@ export async function startScrcpyServer(
|
|||||||
return await invoke("start_scrcpy_server", { id, scid, address });
|
return await invoke("start_scrcpy_server", { id, scid, address });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function loadDefaultKeyconfig(): Promise<string> {
|
||||||
|
return await invoke("load_default_keyconfig");
|
||||||
|
}
|
||||||
|
|
||||||
export type { Device };
|
export type { Device };
|
||||||
|
Loading…
Reference in New Issue
Block a user