发布关卡编辑器独立离线版

This commit is contained in:
2026-11-23 19:01:21 +08:00
commit 7f83f146a4
16 changed files with 636931 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
(() => {
'use strict';
const encode = text => new TextEncoder().encode(text);
async function sha256(text) {
if (!globalThis.crypto?.subtle) throw new Error('当前浏览器不支持文件校验,请使用 Chrome 或 Edge 打开编辑器');
const digest = await crypto.subtle.digest('SHA-256', encode(text));
return Array.from(new Uint8Array(digest), value => value.toString(16).padStart(2, '0')).join('');
}
async function create(prepared, mode = 'changes') {
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)) {
const bytes = crypto.getRandomValues(new Uint8Array(16)); bytes[6] = (bytes[6] & 15) | 64; bytes[8] = (bytes[8] & 63) | 128;
const hex = Array.from(bytes, value => value.toString(16).padStart(2, '0')).join('');
uuids.set(name, hex.slice(0, 8) + '-' + hex.slice(8, 12) + '-' + hex.slice(12, 16) + '-' + hex.slice(16, 20) + '-' + hex.slice(20));
}
return uuids.get(name);
};
// 首遍收集分块摘要输入,异步完成哈希后再生成最终索引,避免复制两套索引生成逻辑。
ProjectFiles.plan(data, files, bundle, text => { hashes.set(text, null); return ''; }, uuid);
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 changedCount = Object.keys(writes).length;
if (mode === 'all') {
for (const [name, text] of Object.entries(files)) {
if (name.endsWith('.json') && !writes[name]) writes[name] = { before: text, text };
}
}
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,
warning: '覆盖包不是自动合并。必须确认目标项目仍为该基线;不同策划的包不能直接连续覆盖。请先备份或提交 Git,再覆盖并在 Cocos 验收。玩家进度不会自动迁移。',
baselineFiles: {}, files: [] };
await Promise.all(Object.entries(files).map(async ([name, text]) => { manifest.baselineFiles[name] = await sha256(text); }));
const archive = {};
for (const [name, value] of Object.entries(writes)) {
archive[name] = encode(value.text);
manifest.files.push({ path: name, existed: value.before !== null, changed: value.before !== value.text, beforeSha256: value.before === null ? null : await sha256(value.before), sha256: await sha256(value.text) });
}
archive['交付信息/变更清单.json'] = encode(JSON.stringify(manifest, null, 2));
archive['交付信息/主线关卡数据包.json'] = encode(JSON.stringify(bundle, null, 2));
archive['交付信息/应用说明.md'] = encode('# 关卡项目文件包\n\n' +
'本包由关卡编辑器生成,assets/ 下为游戏实际使用的关卡 JSON。导出范围:' + (mode === 'all' ? '全部关卡配置(含未修改文件)' : '相对本版基线的变更文件') + '。全部导出不包含素材、游戏规则或其他非关卡配置,不能作为整个游戏资源目录的替代。\n\n' +
'## 应用步骤\n\n1. 先提交 Git 或备份项目。\n2. 核对变更清单中的基线版本与文件摘要。目标文件有后续修改,或本次新增路径已存在时,不要直接覆盖;改用项目内编辑器导入本目录的数据包,或由程序合并。\n3. 将本包 assets/ 合并到 nixingnishanglo-refactor 项目根目录的 assets/,只覆盖清单列出的文件,不要删除原目录。交付信息/ 无需放入游戏项目。\n4. 打开 Cocos 等待资源刷新,检查 Git 差异并运行相关关卡。\n5. 应用后由程序重新生成离线版,作为下一轮编辑基线。\n\n' +
'## 注意\n\n单个 Mainline JSON 通常包含 50 关,不能只按文件名理解成一关。涉及新增或调序时,务必一起应用 LevelSequence.json、索引和关联配置。逐鹿布局在 GhostKingLayouts.json 中,不会覆盖主线布局。策划交付的 assets/ 只包含 JSON,不包含 TypeScript 或 .meta。已有 .meta 必须保留,新分块由 Cocos 自动导入并生成 .meta,等待资源刷新完成后再运行或构建游戏。\n\n覆盖包不会自动备份、检测冲突或迁移玩家存档。不要混合不同基线或不同策划的覆盖包;自动校验不保证关卡可解。\n\n基线版本:`' + data.dataVersion + '`\n');
await new Promise(resolve => setTimeout(resolve, 0));
return { bytes: fflate.zipSync(archive, { level: 6 }), manifest };
}
window.ProjectExport = { create };
})();