1
1
<script setup lang="ts">
2
2
import { $t } from " ../i18n" ;
3
- import type { SaveUnit , Device } from " ../bindings" ;
3
+ import type { SaveUnit , Device , Game } from " ../bindings" ;
4
4
import { commands } from " ../bindings" ;
5
5
import { useNotification } from " ../composables/useNotification" ;
6
6
import { ref , watch } from " vue" ;
@@ -9,12 +9,12 @@ import PathVariableSelector from "./PathVariableSelector.vue";
9
9
const { showSuccess, showError } = useNotification ();
10
10
11
11
const props = defineProps ({
12
- locations: Array < SaveUnit > ,
12
+ game: Object as () => Game ,
13
13
})
14
14
15
15
const emits = defineEmits <{
16
16
(event : ' closed' ): void
17
- (event : ' saveChanges' , tempLocations : SaveUnit [] ): void
17
+ (event : ' saveChanges' , game : Game ): void
18
18
}>()
19
19
20
20
// 当前设备信息
@@ -24,7 +24,7 @@ const availableDevices = ref<Device[]>([]);
24
24
// 当前选中的设备ID
25
25
const selectedDeviceId = ref <string >(' ' );
26
26
// 临时存储修改的数据
27
- const tempLocations = ref <SaveUnit []>([] );
27
+ const tempGame = ref <Game >({ name: " " , save_paths: [], game_paths: {} } );
28
28
// 是否有未保存的修改
29
29
const hasUnsavedChanges = ref (false );
30
30
@@ -45,9 +45,9 @@ async function fetchCurrentDevice() {
45
45
}
46
46
}
47
47
48
- // 从SaveUnit中提取所有设备ID
48
+ // 从Game中提取所有设备ID
49
49
function extractDeviceIdsFromSaveUnits() {
50
- if (! props .locations ) return ;
50
+ if (! props .game ) return ;
51
51
52
52
// 收集所有设备ID
53
53
const deviceIds = new Set <string >();
@@ -58,13 +58,22 @@ function extractDeviceIdsFromSaveUnits() {
58
58
}
59
59
60
60
// 从所有SaveUnit的paths中提取设备ID
61
- props .locations .forEach (unit => {
62
- if (unit .paths ) {
63
- Object .keys (unit .paths ).forEach (deviceId => {
64
- deviceIds .add (deviceId );
65
- });
66
- }
67
- });
61
+ if (props .game .save_paths ) {
62
+ props .game .save_paths .forEach (unit => {
63
+ if (unit .paths ) {
64
+ Object .keys (unit .paths ).forEach (deviceId => {
65
+ deviceIds .add (deviceId );
66
+ });
67
+ }
68
+ });
69
+ }
70
+
71
+ // 从game_paths中提取设备ID
72
+ if (props .game .game_paths ) {
73
+ Object .keys (props .game .game_paths ).forEach (deviceId => {
74
+ deviceIds .add (deviceId );
75
+ });
76
+ }
68
77
69
78
// 转换为设备对象数组
70
79
availableDevices .value = Array .from (deviceIds ).map (id => {
@@ -86,23 +95,23 @@ function extractDeviceIdsFromSaveUnits() {
86
95
}
87
96
}
88
97
89
- // 监听locations变化 ,重新提取设备ID并初始化临时数据
90
- watch (() => props .locations , () => {
98
+ // 监听game变化 ,重新提取设备ID并初始化临时数据
99
+ watch (() => props .game , () => {
91
100
extractDeviceIdsFromSaveUnits ();
92
- initTempLocations ();
101
+ initTempGame ();
93
102
}, { deep: true });
94
103
95
104
// 初始化设备信息
96
105
fetchCurrentDevice ().then (() => {
97
106
extractDeviceIdsFromSaveUnits ();
98
- initTempLocations ();
107
+ initTempGame ();
99
108
});
100
109
101
- // 初始化临时locations数据
102
- function initTempLocations () {
103
- if (! props .locations ) return ;
104
- // 深拷贝locations数据
105
- tempLocations .value = JSON .parse (JSON .stringify (props .locations ));
110
+ // 初始化临时game数据
111
+ function initTempGame () {
112
+ if (! props .game ) return ;
113
+ // 深拷贝game数据
114
+ tempGame .value = JSON .parse (JSON .stringify (props .game ));
106
115
hasUnsavedChanges .value = false ;
107
116
}
108
117
@@ -112,11 +121,17 @@ function getDevicePath(unit: SaveUnit, deviceId: string): string {
112
121
return unit .paths [deviceId ] || ' ' ;
113
122
}
114
123
124
+ // 获取当前设备的游戏启动路径
125
+ function getGameLaunchPath(deviceId : string ): string {
126
+ if (! tempGame .value .game_paths ) return ' ' ;
127
+ return tempGame .value .game_paths [deviceId ] || ' ' ;
128
+ }
129
+
115
130
// 更新临时设备路径
116
131
function updateDevicePath(index : number , deviceId : string , path : string ) {
117
- if (! tempLocations .value ) return ;
132
+ if (! tempGame .value || ! tempGame . value . save_paths ) return ;
118
133
119
- const unit = tempLocations .value [index ];
134
+ const unit = tempGame .value . save_paths [index ];
120
135
if (! unit .paths ) {
121
136
unit .paths = {};
122
137
}
@@ -125,11 +140,23 @@ function updateDevicePath(index: number, deviceId: string, path: string) {
125
140
hasUnsavedChanges .value = true ;
126
141
}
127
142
143
+ // 更新临时游戏启动路径
144
+ function updateGameLaunchPath(deviceId : string , path : string ) {
145
+ if (! tempGame .value ) return ;
146
+
147
+ if (! tempGame .value .game_paths ) {
148
+ tempGame .value .game_paths = {};
149
+ }
150
+
151
+ tempGame .value .game_paths [deviceId ] = path ;
152
+ hasUnsavedChanges .value = true ;
153
+ }
154
+
128
155
// 在路径输入框中插入变量
129
156
function insertPathVariable(variable : string , index : number , deviceId : string ) {
130
- if (! tempLocations .value ) return ;
157
+ if (! tempGame .value || ! tempGame . value . save_paths ) return ;
131
158
132
- const unit = tempLocations .value [index ];
159
+ const unit = tempGame .value . save_paths [index ];
133
160
if (! unit .paths ) {
134
161
unit .paths = {};
135
162
}
@@ -139,6 +166,19 @@ function insertPathVariable(variable: string, index: number, deviceId: string) {
139
166
hasUnsavedChanges .value = true ;
140
167
}
141
168
169
+ // 在游戏启动路径输入框中插入变量
170
+ function insertGamePathVariable(variable : string , deviceId : string ) {
171
+ if (! tempGame .value ) return ;
172
+
173
+ if (! tempGame .value .game_paths ) {
174
+ tempGame .value .game_paths = {};
175
+ }
176
+
177
+ const currentPath = tempGame .value .game_paths [deviceId ] || ' ' ;
178
+ tempGame .value .game_paths [deviceId ] = currentPath + variable ;
179
+ hasUnsavedChanges .value = true ;
180
+ }
181
+
142
182
async function open(url : string ) {
143
183
let result = await commands .openUrl (url );
144
184
if (result .status === " error" ) {
@@ -148,26 +188,24 @@ async function open(url: string) {
148
188
149
189
// 由父组件处理具体任务,此处只传递下标
150
190
function switch_delete_before_apply(unit : SaveUnit ) {
151
- const index = tempLocations .value ?.indexOf (unit )
152
- if (index != undefined ) {
153
- // 只在临时数据中切换状态,不触发父组件事件
154
- hasUnsavedChanges .value = true ;
155
- }
191
+ // 这里不需要特殊处理,直接修改tempGame中的值即可
192
+ // 因为是引用类型,所以直接修改unit的属性会反映到tempGame中
193
+ hasUnsavedChanges .value = true ;
156
194
}
157
195
158
196
// 保存修改
159
197
function saveChanges() {
160
- if (! tempLocations .value ) return ;
198
+ if (! tempGame .value ) return ;
161
199
162
200
// 将所有修改发送给父组件
163
- emits (' saveChanges' , tempLocations .value );
201
+ emits (' saveChanges' , tempGame .value );
164
202
165
203
hasUnsavedChanges .value = false ;
166
204
}
167
205
168
206
// 取消修改
169
207
function cancelChanges() {
170
- initTempLocations ();
208
+ initTempGame ();
171
209
}
172
210
</script >
173
211
@@ -198,8 +236,25 @@ function cancelChanges() {
198
236
</el-tag >
199
237
</div >
200
238
201
- <!-- 路径表格 -->
202
- <el-table :data =" tempLocations" style =" width : 100% " :border =" true" >
239
+ <!-- 游戏启动路径 -->
240
+ <div class =" launch-path-section" >
241
+ <h3 >{{ $t('save_location_drawer.launch_path') }}</h3 >
242
+ <div class =" path-input-container" >
243
+ <el-input :model-value =" getGameLaunchPath(selectedDeviceId)" size =" small"
244
+ @update:model-value =" (value) => updateGameLaunchPath(selectedDeviceId, value)" >
245
+ <template #append >
246
+ <div class =" path-actions" >
247
+ <path-variable-selector :current-path =" getGameLaunchPath(selectedDeviceId)"
248
+ @insert =" (variable) => insertGamePathVariable(variable, selectedDeviceId)" />
249
+ </div >
250
+ </template >
251
+ </el-input >
252
+ </div >
253
+ </div >
254
+
255
+ <!-- 存档路径表格 -->
256
+ <h3 >{{ $t('save_location_drawer.save_locations') }}</h3 >
257
+ <el-table :data =" tempGame.save_paths" style =" width : 100% " :border =" true" >
203
258
<el-table-column prop =" unit_type" :label =" $t('save_location_drawer.type')" width =" 70" />
204
259
<el-table-column :label =" $t('save_location_drawer.prompt')" min-width =" 300" >
205
260
<template #default =" scope " >
0 commit comments