refactor(hero-config): 移除旧的本地导出hexport.ts功能

删除了前后端中与本地导出hexport.ts相关的API、页面按钮和实现代码,不再支持生成本地hexport.ts配置文件。
This commit is contained in:
panFD
2026-09-05 12:55:35 +08:00
parent 1806f4b1a5
commit 30748536d0
4 changed files with 1 additions and 249 deletions

View File

@@ -8,7 +8,6 @@ import url from 'node:url'
const __dirname = path.dirname(url.fileURLToPath(import.meta.url))
const PROJECT_ROOT = path.resolve(__dirname, '..', '..')
const CONFIG_DIR = path.join(PROJECT_ROOT, 'assets/script/game/common/config')
const EXPORT_PATH = path.join(CONFIG_DIR, 'hexport.ts')
const HEROSET_PATH = path.join(CONFIG_DIR, 'heroSet.ts')
const CSV_PATH = path.join(CONFIG_DIR, '英雄设计表.csv')
// heroSet.ts 中英雄条目区域标记(怪物配置在 end 标记之后,不受替换影响)
@@ -114,28 +113,7 @@ function serializeOverrides(o) {
return s
}
/** 生成 hexport.ts 内容 */
function renderHeroTs(heroes) {
const nl = '\n'
let out = ''
out += `/**${nl}`
out += ` * 英雄配置导出文件 - 由英雄配置编辑器生成${nl}`
out += ` * 生成时间: ${new Date().toISOString()}${nl}`
out += ` * 使用方式: import { HexportHeroInfo } from "./hexport" 后合并进 HeroInfo${nl}`
out += ` */${nl}`
out += `import { v3 } from "cc"${nl}`
out += `import { FacSet } from "./GameSet"${nl}`
out += `import { TGroup, BuffTarget } from "./SkillSet"${nl}`
out += `import { SkillLv, HType, HGrowType, HRole, HERO_ROLE_BASE, AtkSpeedSet, AtkSpeedLv, heroInfo } from "./heroSet"${nl}`
out += nl
out += `export const HexportHeroInfo: Record<number, heroInfo> = {${nl}`
for (const h of heroes) {
out += renderSingleHero(h)
}
out += `}${nl}`
return out
}
/** 生成英雄 TS 条目(供 /api/apply 使用) */
function renderSingleHero(h) {
const lines = []
const indent = ' '
@@ -235,26 +213,6 @@ function renderSingleHero(h) {
return lines.join('\n') + '\n'
}
app.post('/api/export', (req, res) => {
try {
const heroes = req.body?.heroes
if (!Array.isArray(heroes) || !heroes.length) {
return res.status(400).json({ error: 'heroes 不能为空' })
}
const content = renderHeroTs(heroes)
fs.writeFileSync(EXPORT_PATH, content, 'utf8')
res.json({ ok: true, path: EXPORT_PATH, bytes: Buffer.byteLength(content) })
} catch (e) {
res.status(500).json({ error: String(e?.message || e) })
}
})
app.get('/api/export', (_req, res) => {
if (!fs.existsSync(EXPORT_PATH)) return res.status(404).json({ error: '尚未生成' })
res.setHeader('Content-Type', 'text/plain; charset=utf-8')
res.send(fs.readFileSync(EXPORT_PATH, 'utf8'))
})
/**
* 直接写回 heroSet.ts:用编辑器数据替换英雄条目区域(HEROES_BEGIN/END 标记之间),
* 怪物条目与区域外的其它配置保持不变。
@@ -427,5 +385,4 @@ app.post('/api/apply', (req, res) => {
const PORT = 3001
app.listen(PORT, () => {
console.log(`[hero-config-tool] server listening http://localhost:${PORT}`)
console.log(`[hero-config-tool] export path: ${EXPORT_PATH}`)
})

View File

@@ -5,7 +5,6 @@
<div class="actions">
<el-button size="small" @click="refreshMeta" :loading="loadingMeta">刷新配置数据</el-button>
<el-button size="small" type="success" @click="doSave" :disabled="!heroes.length">保存到服务器</el-button>
<el-button size="small" type="warning" @click="doExport" :disabled="!heroes.length">导出 hexport.ts</el-button>
<el-button size="small" type="primary" @click="doApply" :disabled="!heroes.length">写入 heroSet.ts</el-button>
<el-button size="small" type="danger" @click="doExportCsv" :disabled="!heroes.length">导出英雄设计表.csv</el-button>
</div>
@@ -375,22 +374,6 @@ async function doSave() {
}
}
async function doExport() {
try {
await ElMessageBox.confirm(
`将写入 ${heroes.value.length} 个英雄到 assets/script/game/common/config/hexport.ts`,
'导出确认',
{ confirmButtonText: '写入', cancelButtonText: '取消', type: 'warning' }
)
} catch { return }
try {
const r = await api.exportHeroes(heroes.value)
ElMessage.success(`已写入 ${r.bytes} 字节 → ${r.path}`)
} catch (e) {
ElMessage.error('导出失败: ' + (e?.response?.data?.error || e.message))
}
}
async function doApply() {
try {
await ElMessageBox.confirm(

View File

@@ -5,8 +5,6 @@ export const api = {
refresh: () => axios.post('/api/refresh').then((r) => r.data),
fetchHeroes: () => axios.get('/api/heroes').then((r) => r.data),
saveHeroes: (heroes) => axios.post('/api/heroes', { heroes }).then((r) => r.data),
exportHeroes: (heroes) => axios.post('/api/export', { heroes }).then((r) => r.data),
applyHeroes: (heroes) => axios.post('/api/apply', { heroes }).then((r) => r.data),
exportCsv: (heroes) => axios.post('/api/export-csv', { heroes }).then((r) => r.data),
fetchExport: () => axios.get('/api/export', { responseType: 'text' }).then((r) => r.data),
}