新增中台关卡测试包导出

This commit is contained in:
2026-11-26 14:16:35 +08:00
parent 30a59acb69
commit f470dc524c
3 changed files with 20 additions and 6 deletions
+5 -4
View File
@@ -16,7 +16,7 @@
helpButton.onclick = () => { const help = $('help-dialog'); if (!help.open) help.showModal(); }; helpButton.onclick = () => { const help = $('help-dialog'); if (!help.open) help.showModal(); };
const exportDialog = document.createElement('dialog'); exportDialog.id = 'project-export-dialog'; exportDialog.setAttribute('aria-labelledby', 'project-export-title'); const exportDialog = document.createElement('dialog'); exportDialog.id = 'project-export-dialog'; exportDialog.setAttribute('aria-labelledby', 'project-export-title');
exportDialog.innerHTML = '<form method="dialog"><div class="mainline-heading"><h2 id="project-export-title">导出项目 JSON</h2><button value="cancel" title="关闭" aria-label="关闭"><i data-lucide="x"></i></button></div>' + exportDialog.innerHTML = '<form method="dialog"><div class="mainline-heading"><h2 id="project-export-title">导出项目 JSON</h2><button value="cancel" title="关闭" aria-label="关闭"><i data-lucide="x"></i></button></div>' +
'<div class="mainline-row"><button id="project-export-changes" value="changes"><i data-lucide="file-diff"></i>导出变更 JSON</button><button id="project-export-all" class="primary" value="all"><i data-lucide="files"></i>导出全部 JSON</button></div></form>'; '<div class="mainline-row"><button id="project-export-changes" value="changes"><i data-lucide="file-diff"></i>导出变更 JSON</button><button id="project-export-all" class="primary" value="all"><i data-lucide="files"></i>导出全部 JSON</button><button id="project-export-staging" value="staging"><i data-lucide="folder-down"></i>导出中台测试包</button></div></form>';
document.body.append(exportDialog); document.body.append(exportDialog);
const input = document.createElement('input'); input.type = 'file'; input.accept = '.json'; input.hidden = true; document.body.append(input); const input = document.createElement('input'); input.type = 'file'; input.accept = '.json'; input.hidden = true; document.body.append(input);
const dialog = document.createElement('dialog'); dialog.id = 'mainline-dialog'; dialog.setAttribute('aria-labelledby', 'mainline-title'); const dialog = document.createElement('dialog'); dialog.id = 'mainline-dialog'; dialog.setAttribute('aria-labelledby', 'mainline-title');
@@ -194,7 +194,7 @@
projectExport.onclick = () => { if (!state.busy && state.level) { exportDialog.returnValue = 'cancel'; exportDialog.showModal(); } }; projectExport.onclick = () => { if (!state.busy && state.level) { exportDialog.returnValue = 'cancel'; exportDialog.showModal(); } };
exportDialog.addEventListener('close', guarded(async () => { exportDialog.addEventListener('close', guarded(async () => {
const mode = exportDialog.returnValue; const mode = exportDialog.returnValue;
if (!['changes', 'all'].includes(mode)) return; if (!['changes', 'all', 'staging'].includes(mode)) return;
if (state.busy || !state.level) return; if (state.busy || !state.level) return;
setBusy(true); projectExport.disabled = true; setBusy(true); projectExport.disabled = true;
try { try {
@@ -204,9 +204,10 @@
const result = await ProjectExport.create(prepared, mode); const result = await ProjectExport.create(prepared, mode);
const url = URL.createObjectURL(new Blob([result.bytes], { type: 'application/zip' })); const url = URL.createObjectURL(new Blob([result.bytes], { type: 'application/zip' }));
const link = document.createElement('a'); link.href = url; const link = document.createElement('a'); link.href = url;
link.download = '关卡项目文件包-' + (mode === 'all' ? '全部-' : '变更-') + new Date().toISOString().replace(/[:.]/g, '-') + '.zip'; link.click(); link.download = mode === 'staging' ? '中台关卡测试包-' + result.revision + '.zip'
: '关卡项目文件包-' + (mode === 'all' ? '全部-' : '变更-') + new Date().toISOString().replace(/[:.]/g, '-') + '.zip'; link.click();
setTimeout(() => URL.revokeObjectURL(url), 60000); setTimeout(() => URL.revokeObjectURL(url), 60000);
message('已下载' + (mode === 'all' ? '全部' : '变更') + '项目 JSON 包,共 ' + result.manifest.files.length + ' 个文件;请在浏览器下载记录中查看,覆盖前先备份'); message(mode === 'staging' ? '已下载中台关卡测试包' : '已下载' + (mode === 'all' ? '全部' : '变更') + '项目 JSON 包,共 ' + result.manifest.files.length + ' 个文件;请在浏览器下载记录中查看,覆盖前先备份');
} finally { projectExport.disabled = false; setBusy(false); } } finally { projectExport.disabled = false; setBusy(false); }
})); }));
importButton.onclick = () => { if (!state.busy) input.click(); }; importButton.onclick = () => { if (!state.busy) input.click(); };
+11 -2
View File
@@ -7,7 +7,7 @@
return Array.from(new Uint8Array(digest), value => value.toString(16).padStart(2, '0')).join(''); return Array.from(new Uint8Array(digest), value => value.toString(16).padStart(2, '0')).join('');
} }
async function create(prepared, mode = 'changes') { async function create(prepared, mode = 'changes') {
if (!['changes', 'all'].includes(mode)) throw new Error('导出范围无效'); if (!['changes', 'all', 'staging'].includes(mode)) throw new Error('导出范围无效');
const { data, files, package: bundle } = prepared, hashes = new Map(), uuids = new Map(); const { data, files, package: bundle } = prepared, hashes = new Map(), uuids = new Map();
const uuid = name => { const uuid = name => {
if (!uuids.has(name)) { if (!uuids.has(name)) {
@@ -22,11 +22,20 @@
await Promise.all([...hashes.keys()].map(async text => hashes.set(text, await sha256(text)))); await Promise.all([...hashes.keys()].map(async text => hashes.set(text, await sha256(text))));
const writes = Object.fromEntries(Object.entries(ProjectFiles.plan(data, files, bundle, text => hashes.get(text), uuid)).filter(([name]) => name.endsWith('.json'))); const writes = Object.fromEntries(Object.entries(ProjectFiles.plan(data, files, bundle, text => hashes.get(text), uuid)).filter(([name]) => name.endsWith('.json')));
const changedCount = Object.keys(writes).length; const changedCount = Object.keys(writes).length;
if (mode === 'all') { if (mode !== 'changes') {
for (const [name, text] of Object.entries(files)) { for (const [name, text] of Object.entries(files)) {
if (name.endsWith('.json') && !writes[name]) writes[name] = { before: text, text }; if (name.endsWith('.json') && !writes[name]) writes[name] = { before: text, text };
} }
} }
if (mode === 'staging') {
const revision = 'test-' + uuid('中台批次');
const archive = Object.fromEntries(Object.entries(writes)
.filter(([name]) => name.startsWith(ProjectFiles.directory))
.map(([name, value]) => [revision + '/' + name.slice(ProjectFiles.directory.length), encode(value.text)]));
archive['release.json'] = encode(JSON.stringify({ schemaVersion: 1, revision }) + '\n');
await new Promise(resolve => setTimeout(resolve, 0));
return { bytes: fflate.zipSync(archive, { level: 6 }), revision };
}
if (!Object.keys(writes).length) throw new Error('没有变更的 JSON,请选择“导出全部 JSON”'); if (!Object.keys(writes).length) throw new Error('没有变更的 JSON,请选择“导出全部 JSON”');
const manifest = { formatVersion: 1, createdAt: new Date().toISOString(), dataVersion: data.dataVersion, const manifest = { formatVersion: 1, createdAt: new Date().toISOString(), dataVersion: data.dataVersion,
rulesVersion: data.rulesVersion, levelCount: bundle.order.length, exportMode: mode, changedCount, rulesVersion: data.rulesVersion, levelCount: bundle.order.length, exportMode: mode, changedCount,
+4
View File
@@ -6,6 +6,10 @@
Boss 和小怪列表展示所有已配置的敌人。不符合当前关卡条件的条目置灰,不可选择,并标注解锁关数、适用场景或资源不可用等原因;调整关卡顺序或场景后会重新判断。 Boss 和小怪列表展示所有已配置的敌人。不符合当前关卡条件的条目置灰,不可选择,并标注解锁关数、适用场景或资源不可用等原因;调整关卡顺序或场景后会重新判断。
## 中台测试包
在「导出项目文件包 ZIP」窗口选「导出中台测试包」,将下载的 ZIP 原样交给中台「上传数据」,不需要手动重打包。ZIP 自带完整关卡批次和发布清单。中台上传接口需将 ZIP 解压到游戏同级的 `data/` 并保留子目录。上传完成后刷新游戏,核对是否读到了新批次。
在右侧切换“关卡属性”,可修改场景、Boss、小怪组合、难度档位及展开后的战斗参数。至少保留一种小怪,敌人必须符合场景和解锁条件;校验失败不能保存或交付。仅显示资源与棋盘边界完整的场景。难度档位与战斗数值独立,切换档位不自动重算血量。面板下方显示游戏适配后的生效数值和只读特殊玩法配置,逐鹿不开放此项编辑。 在右侧切换“关卡属性”,可修改场景、Boss、小怪组合、难度档位及展开后的战斗参数。至少保留一种小怪,敌人必须符合场景和解锁条件;校验失败不能保存或交付。仅显示资源与棋盘边界完整的场景。难度档位与战斗数值独立,切换档位不自动重算血量。面板下方显示游戏适配后的生效数值和只读特殊玩法配置,逐鹿不开放此项编辑。
新增主线关卡先确认模板配置摘要,再新增并按需修改属性。存本机、完整数据包及项目文件包均保留这些属性;单关 JSON 导入只读取棋盘,不会覆盖关卡属性。交付前导出项目文件包,程序应用后需重启游戏预览并验收,不会热更新运行中的游戏。 新增主线关卡先确认模板配置摘要,再新增并按需修改属性。存本机、完整数据包及项目文件包均保留这些属性;单关 JSON 导入只读取棋盘,不会覆盖关卡属性。交付前导出项目文件包,程序应用后需重启游戏预览并验收,不会热更新运行中的游戏。