(function (root) { 'use strict'; const model = typeof module !== 'undefined' && module.exports ? require('./workspace.cjs') : root.MainlineWorkspace; const directory = 'assets/resources/Ynyk/Data/'; const sequence = directory + 'LevelSequence.json'; const json = value => JSON.stringify(value, null, 2) + '\n'; function plan(data, files, input, hash, uuid) { const bundle = model.normalize(input, data), writes = {}; const read = name => JSON.parse(files[directory + name + '.json']); const index = read('MainlineIndex'), difficulty = read('MainlineDifficulty'), encounters = read('MainlineEncounterConfig'); const positions = new Set(data.sourceOrder || data.order); const schedule = (name, text) => { if (files[name] !== text) writes[name] = { before: files[name] ?? null, text }; }; const scheduleJson = (name, value) => { if (files[name] && JSON.stringify(JSON.parse(files[name])) === JSON.stringify(value)) return; schedule(name, json(value)); }; const metadata = name => { if (!files[name + '.meta']) schedule(name + '.meta', json({ ver: '2.0.1', importer: name.endsWith('.json') ? 'json' : 'typescript', imported: true, uuid: uuid(name), files: name.endsWith('.json') ? ['.json'] : [], subMetas: {}, userData: {} })); }; const inventory = model.sourceOrder(bundle), count = inventory.length; if (index.chunkSize !== 50 || count > 20000) throw new Error('项目分块规格不受支持'); const byId = new Map(inventory.map(id => { const source = { ...model.sourceLevel(bundle, id), displayLevel: id }; // 游戏以敌人、难度文件为唯一来源,避免分块中残留另一份过期配置。 delete source.levelSettings; return [id, source]; })); const chunks = []; for (let first = 1; first <= count; first += index.chunkSize) { const chunkId = String(chunks.length + 1).padStart(3, '0'), last = Math.min(count, first + index.chunkSize - 1); const name = directory + 'Chunks/Mainline' + chunkId + '.json'; const old = files[name] ? JSON.parse(files[name]) : { schemaVersion: 2, chunkId }; scheduleJson(name, { ...old, firstDisplayLevel: first, lastDisplayLevel: last, levels: Array.from({ length: last - first + 1 }, (_, position) => byId.get(first + position)) }); const meta = index.chunks.find(item => item.chunkId === chunkId) || { chunkId, json: 'chunks/mainline-' + chunkId + '.v1.json', script: 'js/data/sheep-mainline/v1/mainline-' + chunkId + '.v1.js' }; chunks.push({ ...meta, firstDisplayLevel: first, lastDisplayLevel: last, ...(writes[name] ? { sha256: hash(writes[name].text) } : {}) }); metadata(name); } const templates = { ...data.sourceTemplates }; for (const id of inventory) { if (positions.has(id)) continue; const template = bundle.templates[id]; difficulty.levels[id] = JSON.parse(JSON.stringify(difficulty.levels[template])); encounters.levels[id] = JSON.parse(JSON.stringify(encounters.levels[template])); templates[id] = data.sourceTemplates[template] ?? template; } for (const id of inventory) { const settings = model.sourceLevel(bundle, id).levelSettings; if (!settings) continue; encounters.levels[id] = settings.encounter; difficulty.levels[id] = settings.difficulty; } difficulty.levelCount = count; scheduleJson(directory + 'MainlineDifficulty.json', difficulty); scheduleJson(directory + 'MainlineEncounterConfig.json', encounters); scheduleJson(directory + 'MainlineIndex.json', { ...index, levelCount: count, chunks }); const sequenceConfig = JSON.parse(files[sequence]); scheduleJson(sequence, { ...sequenceConfig, mainline: { ...sequenceConfig.mainline, order: bundle.order, templates, ...(count !== bundle.order.length || sequenceConfig.mainline.sourceCount !== undefined ? { sourceCount: count } : {}) } }); scheduleJson(directory + 'GhostKingLayouts.json', { schemaVersion: 1, levels: bundle.ghostLayouts }); return writes; } const api = { plan, directory, sequence }; if (typeof module !== 'undefined' && module.exports) module.exports = api; else root.ProjectFiles = api; })(globalThis);