Skip to content

Commit

Permalink
add mcmod format export
Browse files Browse the repository at this point in the history
  • Loading branch information
IAFEnvoy committed Sep 21, 2024
1 parent c2d26b7 commit 9ad6fe8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
</div>
&nbsp;&nbsp;&nbsp;&nbsp;
<div id="loading-process"></div>
&nbsp;&nbsp;&nbsp;&nbsp;
<button id="export-list">导出列表<br>(MCMOD可识别)</button>
</fieldset>
<div id="main" style="display:flex;height:420px;">
<div class="info-container" style="flex:4;">
Expand Down
20 changes: 20 additions & 0 deletions frontend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ let currentLoader = 'fabric', currentDisplayMod = 'unknown'

window.onload = async _ => {
document.getElementById("open-folder").onclick = openModFolder
document.getElementById("export-list").onclick = exportModList
tauri.event.listen('mod-config-read', e => {
let index = processingFiles.indexOf(e.payload.file)
if (index == -1) return
Expand Down Expand Up @@ -247,6 +248,25 @@ const openModFolder = async _ => {
loadMods(selected)
}

const exportModList = async _ => {
const selected = await tauri.dialog.save({
filters: [{
name: 'export-modlist',
extensions: ['json']
}]
})
if (!selected) return
await tauri.fs.writeTextFile(selected, JSON.stringify(Object.values(modData).reduce((p, c) => {
if (c.id && c.name && c.version)
p.push({
modid: c.id,
name: c.name,
version: c.version
})
return p
}, []), null, '\t'))
}

const updateLoadingStatus = _ => {
let dom = document.getElementById('loading-process')
dom.innerHTML = `解析元数据:${totalMods - processingFiles.length}/${totalMods}<br>解析Logo:${totalMods - processingFiles.length - processingIcon.length}/${totalMods}`
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ edition = "2021"
tauri-build = { version = "1.4", features = [] }

[dependencies]
tauri = { version = "1.4", features = [ "path-all", "dialog-open", "fs-read-dir"] }
tauri = { version = "1.4", features = [ "fs-write-file", "dialog-save", "path-all", "dialog-open", "fs-read-dir"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
zip = "0.5.5"
Expand Down
4 changes: 3 additions & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
"all": false,
"dialog": {
"all": false,
"open": true
"open": true,
"save": true
},
"fs": {
"all": false,
"readDir": true,
"writeFile": true,
"scope": [
"**"
]
Expand Down

0 comments on commit 9ad6fe8

Please sign in to comment.