diff --git a/app.js b/app.js index 4bedb28..2fbc9b2 100644 --- a/app.js +++ b/app.js @@ -8,7 +8,7 @@ const state = { mode: 'mainline', level: null, revision: '', baseline: '', defin const images = new Map(); const canvas = $('board'), ctx = canvas.getContext('2d'); let transform = null, validateTimer; -const layoutText = level => JSON.stringify([level.width, level.height, level.characters, level.aoes]); +const layoutText = level => JSON.stringify([level.width, level.height, level.characters, level.aoes, level.levelSettings]); const dirty = () => state.level && layoutText(state.level) !== state.baseline; const sameSelection = (a, b) => a?.collection === b?.collection && a?.index === b?.index; const selections = () => !state.selected ? [] : state.selections?.includes(state.selected) ? state.selections : [state.selected]; @@ -151,7 +151,7 @@ function render() { $('view-state').textContent = state.view === 'source' ? (state.material ? '放置 · ' + state.material.name : '源布局') : '局内预览 · 只读'; $('zoom-label').textContent = Math.round(state.zoom * 100) + '%'; $('draft-actions').hidden = !state.draft; - renderInspector(); draw(); + renderInspector(); renderLevelProperties(); draw(); } function draftSave() { try { @@ -212,6 +212,8 @@ async function openLevel(number) { try { const result = await api('/api/levels/' + number); state.level = result.level; state.sourceLevel = result.sourceLevel; state.revision = result.revision; state.baseline = layoutText(result.level); state.result = result; + state.levelBaseSettings = result.effectiveSettings ? clone(result.effectiveSettings) : null; + state.templateSource = result.templateSource; state.history = []; state.future = []; state.selected = null; state.material = null; state.drag = null; state.view = 'source'; state.zoom = 1; state.pan = { x: 0, y: 0 }; state.draft = null; try { const draft = JSON.parse(localStorage.getItem(draftKey())); if (draft?.level && layoutText(draft.level) !== state.baseline) { draft.level.displayLevel = number; state.draft = draft; } } @@ -236,7 +238,7 @@ async function validate() { $('validation-status').textContent = '正在校验'; const result = await api('/api/validate', { level }); if (sequence !== state.sequence) return; - state.result = result; showValidation(result); $('scene').textContent = result.scene || '-'; refreshExtraEffective(); draw(); + state.result = result; showValidation(result); $('scene').textContent = result.scene || '-'; refreshExtraEffective(); renderLevelProperties(); draw(); return result; } function scheduleValidation() { clearTimeout(validateTimer); $('validation-status').textContent = '待校验'; validateTimer = setTimeout(guarded(validate), 300); } @@ -724,7 +726,7 @@ $('restore-draft').onclick = guarded(() => { const before = clone(state.level); // 草稿保留原始版本号,磁盘已变化时仍由保存接口拦截覆盖。 state.level = { ...state.level, width: draft.level.width, height: draft.level.height, - characters: draft.level.characters, aoes: draft.level.aoes }; + characters: draft.level.characters, aoes: draft.level.aoes, levelSettings: draft.level.levelSettings }; state.revision = draft.revision; state.draft = null; state.view = 'source'; changed(before); message('已恢复本地草稿'); }); $('discard-draft').onclick = () => { if (confirm('删除此关卡的本地草稿?')) { localStorage.removeItem(draftKey()); state.draft = null; render(); } }; @@ -802,6 +804,7 @@ new ResizeObserver(draw).observe($('viewport')); guarded(async () => { icons(); const bootstrap = await api('/api/bootstrap'); Object.assign(state, bootstrap); + initLevelProperties(); $('project-path').textContent = bootstrap.project; $('project-path').title = bootstrap.project; $('level-total').textContent = '/ ' + bootstrap.levelCount; $('level-number').max = bootstrap.levelCount; await openLevel(Number(new URLSearchParams(location.search).get('level') || 1)); diff --git a/level-properties.js b/level-properties.js new file mode 100644 index 0000000..2e68168 --- /dev/null +++ b/level-properties.js @@ -0,0 +1,91 @@ +'use strict'; +function currentLevelSettings() { + return clone(state.level.levelSettings || state.result?.effectiveSettings || state.levelBaseSettings || state.settingsCatalog.records[state.sourceLevel]); +} +function levelSettingsSummary(settings) { + const options = state.settingsCatalog, e = settings.encounter; + const name = (items, id) => items.find(item => item.id === id)?.name || String(id); + return '场景:' + name(options.scenes, e.sceneId) + ' · Boss:' + name(options.monsters, e.bossId) + '\n小怪:' + e.monsterIds.map(id => name(options.monsters, id)).join('、') + ' · 难度:' + options.tiers[settings.difficulty.effectiveDifficultyId]; +} +function levelEnemyChoices(options, sceneId, displayLevel, type) { + return options.monsters.filter(item => item.type === type).map(item => { + const reasons = []; + if (!item.resourceReady) reasons.push('资源不可用'); + if (item.unlockLevel > displayLevel) reasons.push('第 ' + item.unlockLevel + ' 关解锁'); + if (!item.sceneIds.includes(sceneId)) { + const scenes = item.sceneIds.map(id => options.scenes.find(scene => scene.id === id)?.name || String(id)); + reasons.push('适用场景:' + (scenes.join('、') || '无')); + } + return { ...item, disabled: reasons.length > 0, name: item.name + (reasons.length ? '(' + reasons.join(';') + ')' : '') }; + }); +} +function renderLevelProperties() { + if (!state.settingsCatalog || !state.level) return; + const mainline = state.mode !== 'ghost-king', open = mainline && state.propertyView === 'level'; + $('level-properties').hidden = !open; $('object-properties-panel').hidden = open; + document.querySelector('[data-properties="level"]').disabled = !mainline; + document.querySelectorAll('[data-properties]').forEach(button => button.classList.toggle('active', button.dataset.properties === (open ? 'level' : 'object'))); + if (!open) return; + const options = state.settingsCatalog, value = currentLevelSettings(), e = value.encounter, d = value.difficulty; + const fill = (id, items, selected) => { + const select = $(id); select.replaceChildren(); + for (const item of items) { + const option = new Option(item.name + ' · ' + item.id, item.id); + option.disabled = Boolean(item.disabled); + select.add(option); + } + select.value = selected; + }; + fill('level-scene', options.scenes.filter(item => item.resourceReady && item.editorReady !== false), e.sceneId); + const enemies = type => levelEnemyChoices(options, e.sceneId, state.level.displayLevel, type); + fill('level-boss', enemies(2), e.bossId); + fill('level-tier', Object.entries(options.tiers).map(([id, name]) => ({ id, name })), d.effectiveDifficultyId); + $('level-minions').replaceChildren(); + for (const item of enemies(1)) { + const label = document.createElement('label'), checkbox = document.createElement('input'); + checkbox.type = 'checkbox'; checkbox.value = item.id; checkbox.checked = e.monsterIds.includes(item.id); + checkbox.dataset.unavailable = String(item.disabled); + label.classList.toggle('enemy-unavailable', item.disabled); + checkbox.onchange = guarded(() => editLevelSettings(settings => { + settings.encounter.monsterIds = Array.from($('level-minions').querySelectorAll('input:checked'), input => Number(input.value)); + })); + const caption = document.createElement('span'); caption.textContent = item.name + ' · ' + item.id; + label.append(checkbox, caption); $('level-minions').append(label); + } + for (const [id, key] of levelSettingsNumbers) $(id).value = d[key]; + $('level-template').textContent = '来源 ID:' + state.sourceLevel + ' · 模板来源:' + (state.templateSource ?? state.sourceLevel) + (state.level.levelSettings ? ' · 独立配置' : ' · 项目配置'); + const balance = state.result?.board?.combatBalance; + const values = balance ? [['Boss 血量', balance.bossHp], ['小怪基础血量', balance.minionHpUnit], ['小怪初始血量倍率', balance.initialMinionHpMultiplier], ['小怪初始血量', balance.initialMinionHp], ['小怪移动速度', d.monsterMoveSpeed], ['目标战斗时长', d.targetLeaderTime + ' 秒']] : []; + $('level-effective').replaceChildren(); + for (const [label, value] of values) { + const dt = document.createElement('dt'), dd = document.createElement('dd'); dt.textContent = label; dd.textContent = value ?? '-'; $('level-effective').append(dt, dd); + } + $('level-progression').textContent = JSON.stringify(state.level.progression || {}, null, 2); + $('level-settings-note').textContent = state.result?.issues?.length ? '配置未通过校验,请查看棋盘下方问题列表。' : balance ? '' : '等待校验生效数值'; + $('level-settings-form').querySelectorAll('input,select').forEach(input => { input.disabled = state.busy || state.view !== 'source' || input.dataset.unavailable === 'true'; }); +} +const levelSettingsNumbers = [['level-boss-hp', 'bossHp'], ['level-minion-hp', 'minionHpMultiplier'], ['level-speed', 'monsterMoveSpeed'], ['level-target-time', 'targetLeaderTime'], ['level-seed', 'minionGroupSeed']]; +function editLevelSettings(action) { + if (state.busy || state.mode === 'ghost-king' || state.view !== 'source') return; + try { + const settings = currentLevelSettings(); action(settings); + MainlineWorkspace.settings.resolve(settings, settings, state.settingsCatalog); + mutate(() => { state.level.levelSettings = settings; }); + } catch (error) { renderLevelProperties(); throw error; } +} +function initLevelProperties() { + document.querySelectorAll('[data-properties]').forEach(button => { button.onclick = () => { state.propertyView = button.dataset.properties; render(); }; }); + $('level-settings-form').onsubmit = event => event.preventDefault(); + $('level-scene').onchange = guarded(() => editLevelSettings(settings => { + const sceneId = Number($('level-scene').value), available = state.settingsCatalog.monsters.filter(item => item.resourceReady && item.sceneIds.includes(sceneId) && item.unlockLevel <= state.level.displayLevel); + const boss = available.find(item => item.type === 2); + const minions = available.filter(item => item.type === 1); + if (!boss || !minions.length) throw new Error('当前关卡尚无可用的该场景 Boss 或小怪'); + settings.encounter = { sceneId, bossId: available.some(item => item.id === settings.encounter.bossId) ? settings.encounter.bossId : boss.id, + monsterIds: settings.encounter.monsterIds.filter(id => minions.some(item => item.id === id)) }; + if (!settings.encounter.monsterIds.length) settings.encounter.monsterIds = minions.map(item => item.id); + })); + $('level-boss').onchange = guarded(() => editLevelSettings(settings => { settings.encounter.bossId = Number($('level-boss').value); })); + $('level-tier').onchange = guarded(() => editLevelSettings(settings => { settings.difficulty.effectiveDifficultyId = Number($('level-tier').value); })); + for (const [id, key] of levelSettingsNumbers) $(id).onchange = guarded(() => editLevelSettings(settings => { settings.difficulty[key] = Number($(id).value); })); +} diff --git a/level-settings.js b/level-settings.js new file mode 100644 index 0000000..43a8ec2 --- /dev/null +++ b/level-settings.js @@ -0,0 +1,34 @@ +(function (root) { + 'use strict'; + const copy = value => JSON.parse(JSON.stringify(value)); + const difficultyFields = ['effectiveDifficultyId', 'computedDifficultyId', 'bossHp', 'minionHpMultiplier', 'minionGroupSeed', 'targetLeaderTime', 'monsterMoveSpeed', 'twoStarDamageRatio', 'threeStarDamageRatio', 'minionHpUnit', 'minionHpStageOffsets']; + function resolve(input, baseline, options) { + if (!baseline) throw new Error('关卡配置模板不存在'); + const value = copy(input === undefined ? baseline : input); + if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).some(key => !['encounter', 'difficulty'].includes(key))) throw new Error('关卡属性格式无效'); + const e = value.encounter, d = value.difficulty; + if (!e || Object.keys(e).some(key => !['sceneId', 'bossId', 'monsterIds'].includes(key))) throw new Error('敌人配置格式无效'); + const scene = options.scenes.find(item => item.id === e.sceneId && item.resourceReady && item.editorReady !== false); + if (!scene) throw new Error('场景不存在或资源未就绪'); + const enemy = (id, type) => { + const found = options.monsters.find(item => item.id === id && item.type === type && item.resourceReady); + if (!found) throw new Error((type === 2 ? 'Boss' : '小怪') + '不存在或资源未就绪:' + id); + if (!found.sceneIds.includes(e.sceneId)) throw new Error(found.name + '不支持场景“' + scene.name + '”'); + }; + enemy(e.bossId, 2); + if (!Array.isArray(e.monsterIds) || !e.monsterIds.length || new Set(e.monsterIds).size !== e.monsterIds.length) throw new Error('至少选择一种小怪,且不能重复'); + e.monsterIds.forEach(id => enemy(id, 1)); + if (!d || Object.keys(d).some(key => !difficultyFields.includes(key))) throw new Error('难度配置字段无效'); + for (const key of ['effectiveDifficultyId', 'computedDifficultyId']) if (!Number.isInteger(d[key]) || !options.tiers[d[key]]) throw new Error('难度档位无效'); + for (const key of ['bossHp', 'minionHpMultiplier', 'targetLeaderTime', 'monsterMoveSpeed']) if (!Number.isFinite(d[key]) || d[key] <= 0) throw new Error('战斗参数必须大于零:' + key); + if (d.minionHpUnit !== undefined && (!Number.isFinite(d.minionHpUnit) || d.minionHpUnit <= 0)) throw new Error('小怪基础血量必须大于零'); + if (!Number.isSafeInteger(d.minionGroupSeed) || d.minionGroupSeed < 0) throw new Error('小怪编队种子必须是非负整数'); + for (const key of ['twoStarDamageRatio', 'threeStarDamageRatio']) if (!Number.isFinite(d[key]) || d[key] < 0 || d[key] > 1) throw new Error('星级伤害比例必须在 0 到 1 之间'); + if (d.twoStarDamageRatio > d.threeStarDamageRatio) throw new Error('二星伤害比例不能大于三星'); + if (d.minionHpStageOffsets !== undefined && (!Array.isArray(d.minionHpStageOffsets) || d.minionHpStageOffsets.length < 2 || d.minionHpStageOffsets[0] !== 0 || d.minionHpStageOffsets.some(v => !Number.isSafeInteger(v) || v < 0))) throw new Error('小怪血量阶段偏移无效'); + return value; + } + const api = { resolve }; + if (typeof module !== 'undefined' && module.exports) module.exports = api; + else root.LevelSettings = api; +})(globalThis); diff --git a/mainline.js b/mainline.js index d06b1a1..40f5fd9 100644 --- a/mainline.js +++ b/mainline.js @@ -28,6 +28,7 @@ '' + '' + + '
' + '
' + '' + '
' + @@ -47,6 +48,10 @@ requestAnimationFrame(() => { if (dialog.open) list.selectedOptions[0]?.scrollIntoView({ block: 'nearest' }); }); $('mainline-pending').textContent = modified ? '待应用' : '已同步'; $('mainline-target').max = draft.order.length; const index = draft.order.indexOf(selected); + if (index >= 0) { + const settings = draft.levels[index].levelSettings || state.settingsCatalog.records[draft.templates[selected]]; + $('mainline-config-summary').textContent = '配置模板:第 ' + (index + 1) + ' 关 · 来源 ' + selected + '\n' + levelSettingsSummary(settings); + } $('mainline-up').disabled = index <= 0; $('mainline-down').disabled = index < 0 || index === draft.order.length - 1; $('mainline-remove').disabled = index < 0 || draft.order.length <= 1; const importing = $('mainline-kind').value === 'json'; @@ -70,6 +75,7 @@ const index = draft.order.indexOf(selected); if (index < 0) throw new Error('请先选择模板关卡'); const id = Math.max(...MainlineWorkspace.sourceOrder(draft)) + 1; let level = clone(draft.levels[index]); + if (!confirm('新关卡将继承以下配置:\n' + $('mainline-config-summary').textContent + '\n\n是否继续新增?')) return; if ($('mainline-kind').value === 'json') { if (readingFile || !importedLayout) throw new Error('请先选择单关 JSON 文件'); level = { ...level, ...clone(importedLayout) }; diff --git a/offline.js b/offline.js index 20cd03c..bb9e81a 100644 --- a/offline.js +++ b/offline.js @@ -2,6 +2,7 @@ 'use strict'; const data = JSON.parse(document.getElementById('offline-data').textContent); const extraFields = window.LevelExtraFields; +const levelSettings = window.MainlineWorkspace.settings, settingsOptions = data.settingsCatalog; const factories = {"assets/Logic/Scripts/YnykContentConfig.ts":function(module,exports,load){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); @@ -2335,6 +2336,8 @@ const adapter = load("assets/Logic/Scripts/LevelAdapter.ts"), optimizer = load(" const byId = new Map(data.definitions.map(item=>[item.id,item])); const basePosition = new Map(data.sourceOrder.map((id,index)=>[id,index])); const sceneFor = number => data.sceneRoutes[data.routeByLevel[basePosition.get(templateOrder[number-1])]]; +const sceneForId = id => data.routesByScene[id]; +const settingsFor = number => settingsOptions.records[templateOrder[number-1]]; function configure(nextOrder, templates, archivedLevels = {}) { order = [...nextOrder,...Object.keys(archivedLevels).map(Number).sort((a,b)=>a-b)]; templateOrder = order.map(id=>templates[id]); const records = source => Object.fromEntries(templateOrder.map((id,index)=>[index+1,source[basePosition.get(id)+1]])); @@ -2342,9 +2345,10 @@ function configure(nextOrder, templates, archivedLevels = {}) { const sources = Object.fromEntries(order.map(id=>[id,data.sourceTemplates[templates[id]] ?? templates[id]])); const unlocks = entries => entries.map(entry=>({...entry,...(entry.unlockLevel ? {unlockLevel:load("assets/Framework/Scripts/MainlineLevelOrder.ts").mapMainlineUnlockLevel(entry.unlockLevel,nextOrder,sources)} : {})})); catalog = catalogFactory({...data.config,artifacts:unlocks(data.config.artifacts),mechanisms:unlocks(data.config.mechanisms)},{...data.monsters,monsters:unlocks(data.monsters.monsters)},data.scenes,{...data.encounters,levels:records(data.encounters.levels)}); + settingsOptions.monsters = catalog.monsters; } configure(data.order,Object.fromEntries(data.sourceOrder.map(id=>[id,id])),data.archivedLevels); -function validate(level, sourceOnly = false) { +function validate(level, sourceOnly = false, encounterContext) { const issues = []; const add = (message, collection, entryIndex) => issues.push({ message, collection, entryIndex }); if (!level || !Number.isInteger(level.displayLevel) || level.displayLevel < 1 || level.displayLevel > order.length) { @@ -2380,14 +2384,22 @@ function validate(level, sourceOnly = false) { } }); } - if (issues.length || sourceOnly) return { issues, board: null }; try { - const scene = sceneFor(level.displayLevel); - const adapted = adapter.adaptLevel(copy(level), catalog, { - routeData: scene.routeData, difficultyConfig: difficulty, boardRotationOffsetDeg: scene.rotation, + const effectiveSettings = levelSettings.resolve(level.levelSettings, settingsFor(level.displayLevel), settingsOptions); + if (level.levelSettings) for (const id of [effectiveSettings.encounter.bossId, ...effectiveSettings.encounter.monsterIds]) { + const enemy = catalog.getMonster(id); + const unlockLevel = encounterContext?.unlocks[id] ?? enemy.unlockLevel; + if (unlockLevel > (encounterContext?.displayLevel ?? level.displayLevel)) throw new Error(enemy.name + '尚未在当前关卡解锁(第 ' + unlockLevel + ' 关)'); + } + if (issues.length || sourceOnly) return { issues, board: null, effectiveSettings }; + const scene = sceneForId(effectiveSettings.encounter.sceneId); + const activeCatalog = Object.create(catalog); activeCatalog.getEncounter = () => effectiveSettings.encounter; + const activeDifficulty = { ...difficulty, levels: { ...difficulty.levels, [level.displayLevel]: effectiveSettings.difficulty } }; + const adapted = adapter.adaptLevel(copy(level), activeCatalog, { + routeData: scene.routeData, difficultyConfig: activeDifficulty, boardRotationOffsetDeg: scene.rotation, }); const board = optimizer.optimizeLevel(adapted, scene.routeData); - return { issues, board, scene: scene.name, boundary: scene.routeData.walkable_area.inner_boundary }; + return { issues, board, scene: scene.name, boundary: scene.routeData.walkable_area.inner_boundary, effectiveSettings }; } catch (error) { add('游戏布局适配失败:' + error.message); return { issues, board: null }; @@ -2400,7 +2412,7 @@ window.offlineEditor = { data, validate, copy, configure, adaptGhost: load("asse const { data, validate, copy, configure } = window.offlineEditor; const model = window.MainlineWorkspace; const key = 'offline-level-editor:' + data.rulesVersion + ':' + data.dataVersion; - const layout = level => JSON.stringify([level.width, level.height, level.characters, level.aoes]); + const layout = level => JSON.stringify([level.width, level.height, level.characters, level.aoes, level.levelSettings]); let workspace = model.create(data), revisions = {}, storedText, storageError = ''; const activate = value => configure(value.order, value.templates, value.archivedLevels); function ghostLevel(number, value = workspace) { @@ -2450,7 +2462,7 @@ window.offlineEditor = { data, validate, copy, configure, adaptGhost: load("asse } catch (error) { workspace = model.create(data); storageError = '未恢复本机工作区:' + error.message; } activate(workspace); window.offlineEditor.api = async (url, body) => { - if (url === '/api/bootstrap') return { project: '离线工作区-' + data.dataVersion, levelCount: workspace.order.length, ghostCount: data.ghostSources.length, definitions: data.definitions }; + if (url === '/api/bootstrap') return { project: '离线工作区-' + data.dataVersion, levelCount: workspace.order.length, ghostCount: data.ghostSources.length, definitions: data.definitions, settingsCatalog: data.settingsCatalog }; if (url === '/api/validate') return validate(body.level); if (url === '/api/ghost-validate') return validateGhost(body.level); const ghostMatch = /^\/api\/ghost-levels\/(\d+)$/.exec(url); @@ -2518,7 +2530,7 @@ window.offlineEditor = { data, validate, copy, configure, adaptGhost: load("asse revisions.mainline = (revisions.mainline || 0) + 1; } const level = copy(workspace.levels[number - 1]); - return { level, revision: String(revisions[id] || 0), sourceLevel: id, + return { level, revision: String(revisions[id] || 0), sourceLevel: id, templateSource: data.sourceTemplates[workspace.templates[id]] ?? workspace.templates[id], ...validate(level), backup: '本机浏览器工作区;交付请导出完整数据包' }; }; document.addEventListener('DOMContentLoaded', () => { diff --git a/project-files.js b/project-files.js index a381737..9d89973 100644 --- a/project-files.js +++ b/project-files.js @@ -20,7 +20,12 @@ }; const inventory = model.sourceOrder(bundle), count = inventory.length; if (index.chunkSize !== 50 || count > 20000) throw new Error('项目分块规格不受支持'); - const byId = new Map(inventory.map(id => [id, { ...model.sourceLevel(bundle, id), displayLevel: id }])); + 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); @@ -41,6 +46,11 @@ 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); diff --git a/style.css b/style.css index af67cc4..6abb353 100644 --- a/style.css +++ b/style.css @@ -65,3 +65,5 @@ header { flex-wrap: wrap; } @media (max-width: 600px) { dialog#mainline-dialog { padding: 14px; } #mainline-list { height: 240px; } .file-actions { flex-wrap: wrap; } } #selection-help{position:absolute;right:16px;bottom:12px;max-width:calc(100% - 32px);padding:6px 9px;border:1px solid #dce1e6;border-radius:4px;background:rgba(255,255,255,.94);color:#64727c;font-size:11px;line-height:1.7;pointer-events:none;overflow-wrap:anywhere}#selection-help span{display:block} #selection-help{white-space:pre-line} +#property-tabs{margin-bottom:18px}#level-properties h2{font-size:14px}#level-properties fieldset{border:0;padding:0;margin:16px 0}#level-minions{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}#level-minions label{display:flex;align-items:center;gap:6px;margin:0}#level-minions input{width:16px;height:16px;margin:0}#level-properties pre{white-space:pre-wrap;overflow-wrap:anywhere;font-size:12px}#level-properties details{margin:16px 0}.settings-muted{font-size:12px;color:#64727c;line-height:1.6}.settings-effective{border-top:1px solid #dce1e6;padding-top:14px}#mainline-config-summary{white-space:pre-line;font-size:13px;line-height:1.8;margin:12px 0} +#level-settings-form{display:flex;flex-direction:column;gap:12px;margin-top:12px}#level-minions label{flex-direction:row;justify-content:flex-start;overflow-wrap:anywhere;line-height:1.5}#level-minions input{flex-shrink:0}#level-minions .enemy-unavailable{color:#737b83;cursor:not-allowed}#level-minions label span{min-width:0}#level-effective{grid-template-columns:minmax(0,1.2fr) minmax(0,1fr);margin-top:10px;line-height:1.6}#level-settings-form details>label{margin-top:12px} diff --git a/workspace.js b/workspace.js index bff910f..bbe0dff 100644 --- a/workspace.js +++ b/workspace.js @@ -2,6 +2,7 @@ 'use strict'; const copy = value => JSON.parse(JSON.stringify(value)); const fields = ['width', 'height', 'characters', 'aoes']; + const settings = typeof module !== 'undefined' && module.exports ? require('./level-settings.cjs') : root.LevelSettings; function importLayout(input) { if (!input || typeof input !== 'object' || Array.isArray(input)) throw new Error('请选择有效的单关 JSON 对象'); if (input.formatVersion !== undefined || Array.isArray(input.levels)) throw new Error('请选择导出的单关 JSON,不是完整关卡数据包'); @@ -43,15 +44,16 @@ result.templates[id] = template; const original = base.get(template); if (!incoming || (active && incoming.displayLevel !== number) || fields.some(field => incoming[field] === undefined)) throw new Error('显示编号或布局字段无效:' + number); - // 只接收布局字段;来源、难度与玩法元数据不能由数据包任意覆盖。 - return { ...copy(original), ...(base.has(id) ? {} : { sourceId: 'editor_level_' + id, sourcePath: 'editor/level_' + id + '.json', sourceUuid: 'editor_level_' + id }), + // 布局与经过白名单校验的关卡属性可编辑,来源及特殊玩法继续继承模板。 + const levelSettings = incoming.levelSettings === undefined ? {} : { levelSettings: settings.resolve(incoming.levelSettings, data.settingsCatalog.records[template], data.settingsCatalog) }; + return { ...copy(original), ...levelSettings, ...(base.has(id) ? {} : { sourceId: 'editor_level_' + id, sourcePath: 'editor/level_' + id + '.json', sourceUuid: 'editor_level_' + id }), ...Object.fromEntries(fields.map(field => [field, copy(incoming[field])])), displayLevel: number }; } result.levels = order.map((id, index) => normalizeLevel(id, input.levels[index], index + 1, true)); result.archivedLevels = Object.fromEntries(Object.entries(archive).map(([id, level]) => [id, normalizeLevel(Number(id), level, Number(id), false)])); return result; } - const api = { create, normalize, sourceOrder, sourceLevel, importLayout }; + const api = { create, normalize, sourceOrder, sourceLevel, importLayout, settings }; if (typeof module !== 'undefined' && module.exports) module.exports = api; else root.MainlineWorkspace = api; })(globalThis); diff --git a/使用说明.md b/使用说明.md index 2560752..09fc248 100644 --- a/使用说明.md +++ b/使用说明.md @@ -2,6 +2,14 @@ 将整个文件夹解压到本机,双击 `编辑器.html`,使用 Chrome 或 Edge 打开。无需安装 Cocos、Node.js,也不需要网络或游戏项目。 +## 主线关卡属性 + +Boss 和小怪列表展示所有已配置的敌人。不符合当前关卡条件的条目置灰,不可选择,并标注解锁关数、适用场景或资源不可用等原因;调整关卡顺序或场景后会重新判断。 + +在右侧切换“关卡属性”,可修改场景、Boss、小怪组合、难度档位及展开后的战斗参数。至少保留一种小怪,敌人必须符合场景和解锁条件;校验失败不能保存或交付。仅显示资源与棋盘边界完整的场景。难度档位与战斗数值独立,切换档位不自动重算血量。面板下方显示游戏适配后的生效数值和只读特殊玩法配置,逐鹿不开放此项编辑。 + +新增主线关卡先确认模板配置摘要,再新增并按需修改属性。存本机、完整数据包及项目文件包均保留这些属性;单关 JSON 导入只读取棋盘,不会覆盖关卡属性。交付前导出项目文件包,程序应用后需重启游戏预览并验收,不会热更新运行中的游戏。 + ## 文件操作 - 上传箭头:导入单关 JSON,应用到当前关卡,仅替换布局。 diff --git a/编辑器.html b/编辑器.html index ef0b67b..d88bc63 100644 --- a/编辑器.html +++ b/编辑器.html @@ -1,6 +1,6 @@ -关卡编辑器 +关卡编辑器
关卡编辑器
@@ -10,6 +10,7 @@

关卡编辑器使用说明

+

主线关卡属性

右侧“关卡属性”可配置场景、Boss、小怪组合、难度档位和战斗数值,下方显示游戏适配后的生效数值及只读特殊玩法。场景和敌人需满足资源、场景匹配与解锁条件,至少保留一种小怪;校验失败不能保存或交付。难度档位与血量等数值独立保存,不会自动重算。

新增主线关卡先确认模板配置,创建后可再修改属性。存本机、完整数据包与项目文件包均保留这些修改;单关 JSON 导入仍只覆盖棋盘。逐鹿不开放这组属性编辑。

对象附加配置

右侧可配置移动速度、木栅栏初始升降、巡逻路径、炸弹后备倒计时与封印锁后备血量。数字留空恢复默认;路径可增删坐标点,至少两点,点击“应用路径”。木栅栏初始降下时,棋盘显示降下图片与半透明状态。

关卡级倒计时与血量优先于对象附加值;炸弹还可能受难度限制,面板会提示来源和实际值。高级 JSON 在折叠区,未识别字段会保留。预览展示初始布局,不模拟升降循环。

开始编辑

离线版请完整解压,再用 Chrome 或 Edge 打开“编辑器.html”。默认关卡已内置,首次使用无需导入,也不需要游戏项目或联网。

顶部选择“主线”或“群雄逐鹿”,输入关卡号并打开。选择左侧对象后点击棋盘放置;已有对象可选择、拖动、转向、复制或删除。完成后校验,并切换“局内预览”检查结果。校验通过不代表关卡一定可解。

保存与备份

离线版“存本机”只保存到当前浏览器,不会写回旁边的 JSON。换电脑、切换浏览器、移动目录或清理浏览器数据前,请先导出完整数据包备份。项目服务版“保存”会写入项目,并保留原文件备份。

@@ -46,6 +47,27 @@

布局校验

等待加载
正在加载项目数据
- + diff --git a/默认数据包.json b/默认数据包.json index 76c90e5..6a94abf 100644 --- a/默认数据包.json +++ b/默认数据包.json @@ -1,7 +1,7 @@ { "formatVersion": 2, - "rulesVersion": "bf69adbdd5ac6b324cee9e8cb6bf2e46880fca4d177fa9393eb60d8adfdc0475", - "dataVersion": "afc18028fffaa8aa75dafc5c935580e228964793ea3a4d082e5538406d742a73", + "rulesVersion": "54938f36765f8f65ea85d0f58c58e455dcf85e69a471a68c4c98ade174b8dd04", + "dataVersion": "f4bffe795ce0ccfb4104439bb21f743bce3bb7951e85ff23ce869e4d3beeb1e7", "order": [ 1, 2,