支持指定路径保存关卡数据包并移除旧中台导出
This commit is contained in:
+36
-13
@@ -16,7 +16,7 @@
|
||||
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');
|
||||
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><button id="project-export-staging" value="staging"><i data-lucide="folder-down"></i>导出中台测试包</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></div></form>';
|
||||
document.body.append(exportDialog);
|
||||
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');
|
||||
@@ -181,20 +181,44 @@
|
||||
} catch (error) { $('mainline-error').textContent = error.message; }
|
||||
finally { setSubmitting(false); setBusy(false); }
|
||||
};
|
||||
function download(bundle) {
|
||||
const url = URL.createObjectURL(new Blob([JSON.stringify(bundle, null, 2)], { type: 'application/json' }));
|
||||
const link = document.createElement('a'); link.href = url; link.download = '主线关卡数据包.json'; link.click(); setTimeout(() => URL.revokeObjectURL(url), 1000);
|
||||
}
|
||||
exportButton.onclick = guarded(async () => {
|
||||
exportButton.onclick = async () => {
|
||||
if (state.busy || !state.level) return;
|
||||
setBusy(true);
|
||||
try { const result = await snapshot(); download(result.package); message('已下载完整数据包 JSON,包含主线顺序、新增关卡和当前布局;可用“导入完整数据包 JSON”直接导入'); }
|
||||
finally { setBusy(false); }
|
||||
});
|
||||
const name = '主线关卡数据包.json';
|
||||
try {
|
||||
let handle;
|
||||
// 保存窗口必须在点击事件内打开,不能等异步校验结束后再请求权限。
|
||||
if (typeof window.showSaveFilePicker === 'function') {
|
||||
try {
|
||||
handle = await window.showSaveFilePicker({ id: 'mainline-package', suggestedName: name,
|
||||
types: [{ description: '关卡数据包 JSON', accept: { 'application/json': ['.json'] } }] });
|
||||
} catch (error) {
|
||||
if (error.name === 'AbortError') return;
|
||||
if (error.name !== 'SecurityError') throw error;
|
||||
}
|
||||
}
|
||||
if (!handle && !window.confirm('当前环境无法打开保存窗口。是否改用浏览器下载?同名文件可能会另存为副本。')) return;
|
||||
const result = await snapshot();
|
||||
const blob = new Blob([JSON.stringify(result.package, null, 2)], { type: 'application/json' });
|
||||
if (handle) {
|
||||
const stream = await handle.createWritable();
|
||||
try { await stream.write(blob); await stream.close(); }
|
||||
catch (error) { await stream.abort().catch(() => {}); throw error; }
|
||||
message('已保存完整数据包:' + handle.name);
|
||||
} else {
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a'); link.href = url; link.download = name; link.click();
|
||||
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
||||
message('已下载完整数据包 JSON');
|
||||
}
|
||||
} catch (error) {
|
||||
message('导出数据包失败:' + (error.name === 'NotAllowedError' ? '没有文件写入权限' : error.message), true);
|
||||
} finally { setBusy(false); }
|
||||
};
|
||||
projectExport.onclick = () => { if (!state.busy && state.level) { exportDialog.returnValue = 'cancel'; exportDialog.showModal(); } };
|
||||
exportDialog.addEventListener('close', guarded(async () => {
|
||||
const mode = exportDialog.returnValue;
|
||||
if (!['changes', 'all', 'staging'].includes(mode)) return;
|
||||
if (!['changes', 'all'].includes(mode)) return;
|
||||
if (state.busy || !state.level) return;
|
||||
setBusy(true); projectExport.disabled = true;
|
||||
try {
|
||||
@@ -204,10 +228,9 @@
|
||||
const result = await ProjectExport.create(prepared, mode);
|
||||
const url = URL.createObjectURL(new Blob([result.bytes], { type: 'application/zip' }));
|
||||
const link = document.createElement('a'); link.href = url;
|
||||
link.download = mode === 'staging' ? '中台关卡测试包-' + result.revision + '.zip'
|
||||
: '关卡项目文件包-' + (mode === 'all' ? '全部-' : '变更-') + new Date().toISOString().replace(/[:.]/g, '-') + '.zip'; link.click();
|
||||
link.download = '关卡项目文件包-' + (mode === 'all' ? '全部-' : '变更-') + new Date().toISOString().replace(/[:.]/g, '-') + '.zip'; link.click();
|
||||
setTimeout(() => URL.revokeObjectURL(url), 60000);
|
||||
message(mode === 'staging' ? '已下载中台关卡测试包' : '已下载' + (mode === 'all' ? '全部' : '变更') + '项目 JSON 包,共 ' + result.manifest.files.length + ' 个文件;请在浏览器下载记录中查看,覆盖前先备份');
|
||||
message('已下载' + (mode === 'all' ? '全部' : '变更') + '项目 JSON 包,共 ' + result.manifest.files.length + ' 个文件;请在浏览器下载记录中查看,覆盖前先备份');
|
||||
} finally { projectExport.disabled = false; setBusy(false); }
|
||||
}));
|
||||
importButton.onclick = () => { if (!state.busy) input.click(); };
|
||||
|
||||
+1
-10
@@ -7,7 +7,7 @@
|
||||
return Array.from(new Uint8Array(digest), value => value.toString(16).padStart(2, '0')).join('');
|
||||
}
|
||||
async function create(prepared, mode = 'changes') {
|
||||
if (!['changes', 'all', 'staging'].includes(mode)) throw new Error('导出范围无效');
|
||||
if (!['changes', 'all'].includes(mode)) throw new Error('导出范围无效');
|
||||
const { data, files, package: bundle } = prepared, hashes = new Map(), uuids = new Map();
|
||||
const uuid = name => {
|
||||
if (!uuids.has(name)) {
|
||||
@@ -27,15 +27,6 @@
|
||||
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”');
|
||||
const manifest = { formatVersion: 1, createdAt: new Date().toISOString(), dataVersion: data.dataVersion,
|
||||
rulesVersion: data.rulesVersion, levelCount: bundle.order.length, exportMode: mode, changedCount,
|
||||
|
||||
@@ -6,9 +6,11 @@
|
||||
|
||||
Boss 和小怪列表展示所有已配置的敌人。不符合当前关卡条件的条目置灰,不可选择,并标注解锁关数、适用场景或资源不可用等原因;调整关卡顺序或场景后会重新判断。
|
||||
|
||||
## 中台测试包
|
||||
## 中台游戏内导入棋盘
|
||||
|
||||
在「导出项目文件包 ZIP」窗口选「导出中台测试包」,将下载的 ZIP 原样交给中台「上传数据」,不需要手动重打包。ZIP 自带完整关卡批次和发布清单。中台上传接口需将 ZIP 解压到游戏同级的 `data/` 并保留子目录。上传完成后刷新游戏,核对是否读到了新批次。
|
||||
导出完整数据包时,可以在保存窗口选择目录和文件名。默认文件名为 `主线关卡数据包.json`,选同名文件并确认替换即可覆盖。若当前浏览器无法打开保存窗口,编辑器会询问是否改用普通下载。
|
||||
|
||||
编辑完成后点击「导出完整数据包 JSON」,也可以直接选用随编辑器附带的 `默认数据包.json`。在中台游戏打开「设置 → 导入棋盘」,选择 JSON 后重新进入主线。只覆盖棋盘,刷新网页即可恢复,不会上传服务器。
|
||||
|
||||
在右侧切换“关卡属性”,可修改场景、Boss、小怪组合、难度档位及展开后的战斗参数。至少保留一种小怪,敌人必须符合场景和解锁条件;校验失败不能保存或交付。仅显示资源与棋盘边界完整的场景。难度档位与战斗数值独立,切换档位不自动重算血量。面板下方显示游戏适配后的生效数值和只读特殊玩法配置,逐鹿不开放此项编辑。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user