poi-plugin-kcsave-exporter 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.es CHANGED
@@ -6,7 +6,6 @@ import {
6
6
  Button,
7
7
  Callout,
8
8
  Card,
9
- Checkbox,
10
9
  Divider,
11
10
  Elevation,
12
11
  Intent,
@@ -14,12 +13,22 @@ import {
14
13
  } from '@blueprintjs/core'
15
14
  import { dialog } from '@electron/remote'
16
15
  import { ApiCaptureStore } from './lib/capture'
17
- import { exportToKcsaveBuffer } from './lib/exporter'
16
+ import { exportPatchedKcsaveBuffer } from './lib/exporter'
18
17
 
18
+ const BASE_PATH_STORAGE_KEY = 'poi_plugin_kcsave_exporter_base_path_v1'
19
19
  const captureStore = new ApiCaptureStore()
20
20
 
21
21
  const formatTime = (ts) => (ts ? new Date(ts).toLocaleTimeString() : '未捕获')
22
22
 
23
+ const loadSavedBasePath = () => {
24
+ try {
25
+ const p = window.localStorage?.getItem(BASE_PATH_STORAGE_KEY) || ''
26
+ return p && fs.existsSync(p) ? p : ''
27
+ } catch (_) {
28
+ return ''
29
+ }
30
+ }
31
+
23
32
  const KcsaveExporter = () => {
24
33
  const basic = useSelector((state) => state.info?.basic || {})
25
34
  const shipsCount = useSelector((state) => Object.keys(state.info?.ships || {}).length)
@@ -28,8 +37,7 @@ const KcsaveExporter = () => {
28
37
  const airbaseCount = useSelector((state) => (Array.isArray(state.info?.airbase) ? state.info.airbase.length : 0))
29
38
 
30
39
  const [captured, setCaptured] = useState(() => ({ ...captureStore.data }))
31
- const [baseFilePath, setBaseFilePath] = useState('')
32
- const [inheritOfflineProgress, setInheritOfflineProgress] = useState(true)
40
+ const [baseFilePath, setBaseFilePath] = useState(loadSavedBasePath)
33
41
  const [exporting, setExporting] = useState(false)
34
42
  const [status, setStatus] = useState(null)
35
43
  const [lastStats, setLastStats] = useState(null)
@@ -45,48 +53,50 @@ const KcsaveExporter = () => {
45
53
  const handlePickBase = useCallback(async () => {
46
54
  try {
47
55
  const res = await dialog.showOpenDialog({
48
- title: '选择已有单机版 .kcsave 模板(可选)',
56
+ title: '选择原单机版 .kcsave 存档(必选)',
49
57
  filters: [{ name: 'KanColle Offline Save', extensions: ['kcsave'] }],
50
58
  properties: ['openFile'],
51
59
  })
52
60
  const filePath = !res.canceled && res.filePaths?.[0]
53
61
  if (filePath) {
54
62
  setBaseFilePath(filePath)
55
- setStatus({ text: `已选择模板:${path.basename(filePath)}`, intent: Intent.PRIMARY })
63
+ try {
64
+ window.localStorage?.setItem(BASE_PATH_STORAGE_KEY, filePath)
65
+ } catch (_) {}
66
+ const sizeMb = (fs.statSync(filePath).size / 1024 / 1024).toFixed(2)
67
+ setStatus({
68
+ text: `已选定基底存档:${path.basename(filePath)}(${sizeMb} MB)`,
69
+ intent: Intent.PRIMARY,
70
+ })
56
71
  }
57
72
  } catch (err) {
58
- setStatus({ text: `选择模板失败:${err.message}`, intent: Intent.DANGER })
73
+ setStatus({ text: `选择原存档失败:${err.message}`, intent: Intent.DANGER })
59
74
  }
60
75
  }, [])
61
76
 
62
- const handleClearBase = useCallback(() => {
63
- setBaseFilePath('')
64
- setStatus({ text: '已清除模板,将使用内置默认配置独立导出。', intent: Intent.NONE })
65
- }, [])
66
-
67
77
  const handleClearCache = useCallback(() => {
68
78
  captureStore.clearCache()
69
79
  setStatus({ text: '已清空本地捕获缓存,重新打开对应游戏界面后会自动记录。', intent: Intent.NONE })
70
80
  }, [])
71
81
 
72
82
  const handleExport = useCallback(async () => {
83
+ if (!baseFilePath || !fs.existsSync(baseFilePath)) {
84
+ setStatus({ text: '必须先选择一份原单机版 .kcsave 存档作为基底。', intent: Intent.WARNING })
85
+ return
86
+ }
73
87
  setExporting(true)
74
- setStatus({ text: '正在汇总数据并生成 .kcsave 存档...', intent: Intent.PRIMARY })
88
+ setStatus({ text: '正在原存档基础上替换舰队数据并重算校验和...', intent: Intent.PRIMARY })
75
89
  try {
76
90
  const reduxState = typeof window.getStore === 'function' ? window.getStore() : {}
77
- const baseBuf =
78
- baseFilePath && fs.existsSync(baseFilePath) ? fs.readFileSync(baseFilePath) : null
79
-
80
- const { buffer, stats } = exportToKcsaveBuffer(reduxState, captureStore.data, baseBuf, {
81
- inheritOfflineProgress: Boolean(baseBuf && inheritOfflineProgress),
82
- })
91
+ const baseBuf = fs.readFileSync(baseFilePath)
92
+ const { buffer, stats } = exportPatchedKcsaveBuffer(reduxState, captureStore.data, baseBuf)
83
93
 
84
94
  const safeName = (stats.nickname || 'admiral').replace(/[\\/:*?"<>|]/g, '_')
85
95
  const stamp = new Date().toISOString().slice(0, 10).replace(/-/g, '')
86
96
  const defaultPath = `kancolle-${safeName}-${stamp}.kcsave`
87
97
 
88
98
  const res = await dialog.showSaveDialog({
89
- title: '导出单机版 .kcsave 存档',
99
+ title: '保存替换后的单机版 .kcsave 存档',
90
100
  defaultPath,
91
101
  filters: [{ name: 'KanColle Offline Save', extensions: ['kcsave'] }],
92
102
  })
@@ -99,7 +109,7 @@ const KcsaveExporter = () => {
99
109
  fs.writeFileSync(res.filePath, buffer)
100
110
  setLastStats(stats)
101
111
  setStatus({
102
- text: `导出成功!已保存至 ${res.filePath}(${(buffer.length / 1024 / 1024).toFixed(2)} MB)`,
112
+ text: `导出成功!已基于原存档原地替换并保存至 ${res.filePath}(${(buffer.length / 1024 / 1024).toFixed(2)} MB)`,
103
113
  intent: Intent.SUCCESS,
104
114
  })
105
115
  } catch (err) {
@@ -110,7 +120,7 @@ const KcsaveExporter = () => {
110
120
  } finally {
111
121
  setExporting(false)
112
122
  }
113
- }, [baseFilePath, inheritOfflineProgress])
123
+ }, [baseFilePath])
114
124
 
115
125
  const capAt = captured.capturedAt || {}
116
126
  const furnitureCount = (captured.furnitureOwned || []).length
@@ -148,39 +158,36 @@ const KcsaveExporter = () => {
148
158
  </div>
149
159
  <Divider style={{ margin: '10px 0' }} />
150
160
  <div style={{ fontSize: 12, opacity: 0.78 }}>
151
- 提示:舰娘、装备、资源、舰队、渠位、道具、海域与陆航可直接导出;如需连带家具、远征、编成记录、图鉴与任务一起导出,请先在游戏内打开对应界面一次即可自动捕获。
161
+ 提示:导出会在你提供的原单机版 .kcsave 基础上原地替换舰娘、装备、资源、舰队与家具数据,完整保留原存档数据库的所有历史表、版本链、立绘外观与单机进度。
152
162
  </div>
153
163
  </Card>
154
164
 
155
165
  <Card elevation={Elevation.ONE}>
156
- <div style={{ fontSize: 12, marginBottom: 8 }}>
157
- <strong>可选基础模板:</strong>
158
- {baseFilePath ? path.basename(baseFilePath) : '无(使用内置默认模板独立导出)'}
166
+ <div style={{ fontSize: 12, marginBottom: 10 }}>
167
+ <strong>原单机版基底存档(必选):</strong>
168
+ {baseFilePath ? (
169
+ <Tag intent={Intent.SUCCESS} minimal style={{ marginLeft: 4 }}>
170
+ {path.basename(baseFilePath)}
171
+ </Tag>
172
+ ) : (
173
+ <Tag intent={Intent.WARNING} minimal style={{ marginLeft: 4 }}>
174
+ 未选择(请先选择原 .kcsave 文件)
175
+ </Tag>
176
+ )}
159
177
  </div>
160
- <Checkbox
161
- checked={inheritOfflineProgress}
162
- disabled={!baseFilePath}
163
- onChange={(e) => setInheritOfflineProgress(e.currentTarget.checked)}
164
- label="继承模板中的单机进度(军费、任务进度与历史、活动海域、已探索节点、开发配方、图鉴与单机设置)"
165
- style={{ fontSize: 12, marginBottom: 10 }}
166
- />
167
178
  <div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
179
+ <Button icon="document-open" intent={!baseFilePath ? Intent.PRIMARY : Intent.NONE} onClick={handlePickBase}>
180
+ {baseFilePath ? '更换原存档 .kcsave' : '选择原存档 .kcsave(必选)'}
181
+ </Button>
168
182
  <Button
169
183
  intent={Intent.PRIMARY}
170
184
  icon="export"
185
+ disabled={!baseFilePath}
171
186
  loading={exporting}
172
187
  onClick={handleExport}
173
188
  >
174
- 一键完全导出 .kcsave
189
+ 基于原存档完全导出 .kcsave
175
190
  </Button>
176
- <Button icon="document-open" onClick={handlePickBase}>
177
- 选择模板 .kcsave(可选)
178
- </Button>
179
- {baseFilePath && (
180
- <Button icon="cross" onClick={handleClearBase}>
181
- 清除模板
182
- </Button>
183
- )}
184
191
  <Button icon="trash" minimal onClick={handleClearCache}>
185
192
  清空捕获缓存
186
193
  </Button>
@@ -194,20 +201,16 @@ const KcsaveExporter = () => {
194
201
  )}
195
202
 
196
203
  {lastStats && (
197
- <Callout title="本次导出明细" intent={Intent.SUCCESS}>
204
+ <Callout title="本次导出明细(基于原存档原地替换)" intent={Intent.SUCCESS}>
198
205
  <div style={{ fontSize: 12, lineHeight: 1.7 }}>
199
206
  <div>
200
- 提督 {lastStats.nickname} (Lv.{lastStats.level}) | 舰娘 {lastStats.ships} | 装备 {lastStats.equipment} |
201
- 舰队 {lastStats.decks} | 道具 {lastStats.inventory} | 家具 {lastStats.furniture} |
202
- 海域 {lastStats.maps} | 陆航 {lastStats.airBases} | 编成记录 {lastStats.presets} |
203
- 图鉴 {lastStats.albumShips}/{lastStats.albumEquips}
207
+ 提督 {lastStats.nickname} (Lv.{lastStats.level}) | Revision {lastStats.revision} | 舰娘 {lastStats.ships} |
208
+ 装备 {lastStats.equipment} | 舰队 {lastStats.decks} | 道具 {lastStats.inventory} | 家具 {lastStats.furniture}
209
+ </div>
210
+ <div style={{ marginTop: 4 }}>
211
+ 保留单机进度:军费 {lastStats.treasuryBalance} | 任务 {lastStats.quests}(历史 {lastStats.questHistoryCount}) |
212
+ 海域 {lastStats.maps} | 活动 {lastStats.eventsCount} | 图鉴 {lastStats.albumShips}/{lastStats.albumEquips}
204
213
  </div>
205
- {lastStats.inheritedOffline && (
206
- <div style={{ marginTop: 4 }}>
207
- 已继承单机进度:军费 {lastStats.inheritedOffline.treasuryBalance} | 任务 {lastStats.inheritedOffline.questsCount}(历史 {lastStats.inheritedOffline.questHistoryCount}) |
208
- 活动 {lastStats.inheritedOffline.eventsCount} | 探索海域 {lastStats.inheritedOffline.exploredMapsCount}
209
- </div>
210
- )}
211
214
  </div>
212
215
  </Callout>
213
216
  )}