同步关卡属性编辑与Boss小怪置灰提示
This commit is contained in:
@@ -8,7 +8,7 @@ const state = { mode: 'mainline', level: null, revision: '', baseline: '', defin
|
|||||||
const images = new Map();
|
const images = new Map();
|
||||||
const canvas = $('board'), ctx = canvas.getContext('2d');
|
const canvas = $('board'), ctx = canvas.getContext('2d');
|
||||||
let transform = null, validateTimer;
|
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 dirty = () => state.level && layoutText(state.level) !== state.baseline;
|
||||||
const sameSelection = (a, b) => a?.collection === b?.collection && a?.index === b?.index;
|
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];
|
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 : '源布局') : '局内预览 · 只读';
|
$('view-state').textContent = state.view === 'source' ? (state.material ? '放置 · ' + state.material.name : '源布局') : '局内预览 · 只读';
|
||||||
$('zoom-label').textContent = Math.round(state.zoom * 100) + '%';
|
$('zoom-label').textContent = Math.round(state.zoom * 100) + '%';
|
||||||
$('draft-actions').hidden = !state.draft;
|
$('draft-actions').hidden = !state.draft;
|
||||||
renderInspector(); draw();
|
renderInspector(); renderLevelProperties(); draw();
|
||||||
}
|
}
|
||||||
function draftSave() {
|
function draftSave() {
|
||||||
try {
|
try {
|
||||||
@@ -212,6 +212,8 @@ async function openLevel(number) {
|
|||||||
try {
|
try {
|
||||||
const result = await api('/api/levels/' + number);
|
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.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.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;
|
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; } }
|
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 = '正在校验';
|
$('validation-status').textContent = '正在校验';
|
||||||
const result = await api('/api/validate', { level });
|
const result = await api('/api/validate', { level });
|
||||||
if (sequence !== state.sequence) return;
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
function scheduleValidation() { clearTimeout(validateTimer); $('validation-status').textContent = '待校验'; validateTimer = setTimeout(guarded(validate), 300); }
|
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);
|
const before = clone(state.level);
|
||||||
// 草稿保留原始版本号,磁盘已变化时仍由保存接口拦截覆盖。
|
// 草稿保留原始版本号,磁盘已变化时仍由保存接口拦截覆盖。
|
||||||
state.level = { ...state.level, width: draft.level.width, height: draft.level.height,
|
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('已恢复本地草稿');
|
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(); } };
|
$('discard-draft').onclick = () => { if (confirm('删除此关卡的本地草稿?')) { localStorage.removeItem(draftKey()); state.draft = null; render(); } };
|
||||||
@@ -802,6 +804,7 @@ new ResizeObserver(draw).observe($('viewport'));
|
|||||||
guarded(async () => {
|
guarded(async () => {
|
||||||
icons();
|
icons();
|
||||||
const bootstrap = await api('/api/bootstrap'); Object.assign(state, bootstrap);
|
const bootstrap = await api('/api/bootstrap'); Object.assign(state, bootstrap);
|
||||||
|
initLevelProperties();
|
||||||
$('project-path').textContent = bootstrap.project; $('project-path').title = bootstrap.project;
|
$('project-path').textContent = bootstrap.project; $('project-path').title = bootstrap.project;
|
||||||
$('level-total').textContent = '/ ' + bootstrap.levelCount; $('level-number').max = bootstrap.levelCount;
|
$('level-total').textContent = '/ ' + bootstrap.levelCount; $('level-number').max = bootstrap.levelCount;
|
||||||
await openLevel(Number(new URLSearchParams(location.search).get('level') || 1));
|
await openLevel(Number(new URLSearchParams(location.search).get('level') || 1));
|
||||||
|
|||||||
@@ -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); }));
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
'<button id="mainline-add"><i data-lucide="plus"></i>新增至末尾</button><button id="mainline-insert"><i data-lucide="list-plus"></i>插入选中关卡之后</button></div>' +
|
'<button id="mainline-add"><i data-lucide="plus"></i>新增至末尾</button><button id="mainline-insert"><i data-lucide="list-plus"></i>插入选中关卡之后</button></div>' +
|
||||||
'<div id="mainline-json-row" class="mainline-row" hidden><button id="mainline-json-choose" title="选择导出的单关 JSON 文件"><i data-lucide="file-up"></i>选择 JSON</button><span id="mainline-json-name"></span>' +
|
'<div id="mainline-json-row" class="mainline-row" hidden><button id="mainline-json-choose" title="选择导出的单关 JSON 文件"><i data-lucide="file-up"></i>选择 JSON</button><span id="mainline-json-name"></span>' +
|
||||||
'<span id="mainline-json-template" title="新关卡的场景、难度、敌人和玩法元数据继承所选模板,JSON 仅提供布局"></span><input id="mainline-json-file" type="file" accept=".json,application/json" aria-label="新增关卡 JSON 文件" hidden></div>' +
|
'<span id="mainline-json-template" title="新关卡的场景、难度、敌人和玩法元数据继承所选模板,JSON 仅提供布局"></span><input id="mainline-json-file" type="file" accept=".json,application/json" aria-label="新增关卡 JSON 文件" hidden></div>' +
|
||||||
|
'<div id="mainline-config-summary" aria-label="新增关卡配置摘要"></div>' +
|
||||||
'<div class="mainline-row"><button id="mainline-up" title="上移一关" aria-label="上移一关"><i data-lucide="arrow-up"></i></button><button id="mainline-down" title="下移一关" aria-label="下移一关"><i data-lucide="arrow-down"></i></button>' +
|
'<div class="mainline-row"><button id="mainline-up" title="上移一关" aria-label="上移一关"><i data-lucide="arrow-up"></i></button><button id="mainline-down" title="下移一关" aria-label="下移一关"><i data-lucide="arrow-down"></i></button>' +
|
||||||
'<label>移动到第 <input id="mainline-target" type="number" min="1" value="1" aria-label="目标关卡号"> 关</label><button id="mainline-move"><i data-lucide="arrow-right-to-line"></i>移动</button>' +
|
'<label>移动到第 <input id="mainline-target" type="number" min="1" value="1" aria-label="目标关卡号"> 关</label><button id="mainline-move"><i data-lucide="arrow-right-to-line"></i>移动</button>' +
|
||||||
'<button id="mainline-undo" title="撤销编排" aria-label="撤销编排"><i data-lucide="undo-2"></i></button><button id="mainline-remove"><i data-lucide="trash-2"></i>从主线移除</button></div>' +
|
'<button id="mainline-undo" title="撤销编排" aria-label="撤销编排"><i data-lucide="undo-2"></i></button><button id="mainline-remove"><i data-lucide="trash-2"></i>从主线移除</button></div>' +
|
||||||
@@ -47,6 +48,10 @@
|
|||||||
requestAnimationFrame(() => { if (dialog.open) list.selectedOptions[0]?.scrollIntoView({ block: 'nearest' }); });
|
requestAnimationFrame(() => { if (dialog.open) list.selectedOptions[0]?.scrollIntoView({ block: 'nearest' }); });
|
||||||
$('mainline-pending').textContent = modified ? '待应用' : '已同步'; $('mainline-target').max = draft.order.length;
|
$('mainline-pending').textContent = modified ? '待应用' : '已同步'; $('mainline-target').max = draft.order.length;
|
||||||
const index = draft.order.indexOf(selected);
|
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-up').disabled = index <= 0; $('mainline-down').disabled = index < 0 || index === draft.order.length - 1;
|
||||||
$('mainline-remove').disabled = index < 0 || draft.order.length <= 1;
|
$('mainline-remove').disabled = index < 0 || draft.order.length <= 1;
|
||||||
const importing = $('mainline-kind').value === 'json';
|
const importing = $('mainline-kind').value === 'json';
|
||||||
@@ -70,6 +75,7 @@
|
|||||||
const index = draft.order.indexOf(selected); if (index < 0) throw new Error('请先选择模板关卡');
|
const index = draft.order.indexOf(selected); if (index < 0) throw new Error('请先选择模板关卡');
|
||||||
const id = Math.max(...MainlineWorkspace.sourceOrder(draft)) + 1;
|
const id = Math.max(...MainlineWorkspace.sourceOrder(draft)) + 1;
|
||||||
let level = clone(draft.levels[index]);
|
let level = clone(draft.levels[index]);
|
||||||
|
if (!confirm('新关卡将继承以下配置:\n' + $('mainline-config-summary').textContent + '\n\n是否继续新增?')) return;
|
||||||
if ($('mainline-kind').value === 'json') {
|
if ($('mainline-kind').value === 'json') {
|
||||||
if (readingFile || !importedLayout) throw new Error('请先选择单关 JSON 文件');
|
if (readingFile || !importedLayout) throw new Error('请先选择单关 JSON 文件');
|
||||||
level = { ...level, ...clone(importedLayout) };
|
level = { ...level, ...clone(importedLayout) };
|
||||||
|
|||||||
+21
-9
@@ -2,6 +2,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
const data = JSON.parse(document.getElementById('offline-data').textContent);
|
const data = JSON.parse(document.getElementById('offline-data').textContent);
|
||||||
const extraFields = window.LevelExtraFields;
|
const extraFields = window.LevelExtraFields;
|
||||||
|
const levelSettings = window.MainlineWorkspace.settings, settingsOptions = data.settingsCatalog;
|
||||||
const factories = {"assets/Logic/Scripts/YnykContentConfig.ts":function(module,exports,load){
|
const factories = {"assets/Logic/Scripts/YnykContentConfig.ts":function(module,exports,load){
|
||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
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 byId = new Map(data.definitions.map(item=>[item.id,item]));
|
||||||
const basePosition = new Map(data.sourceOrder.map((id,index)=>[id,index]));
|
const basePosition = new Map(data.sourceOrder.map((id,index)=>[id,index]));
|
||||||
const sceneFor = number => data.sceneRoutes[data.routeByLevel[basePosition.get(templateOrder[number-1])]];
|
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 = {}) {
|
function configure(nextOrder, templates, archivedLevels = {}) {
|
||||||
order = [...nextOrder,...Object.keys(archivedLevels).map(Number).sort((a,b)=>a-b)]; templateOrder = order.map(id=>templates[id]);
|
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]]));
|
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 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)} : {})}));
|
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)});
|
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);
|
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 issues = [];
|
||||||
const add = (message, collection, entryIndex) => issues.push({ message, collection, entryIndex });
|
const add = (message, collection, entryIndex) => issues.push({ message, collection, entryIndex });
|
||||||
if (!level || !Number.isInteger(level.displayLevel) || level.displayLevel < 1 || level.displayLevel > order.length) {
|
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 {
|
try {
|
||||||
const scene = sceneFor(level.displayLevel);
|
const effectiveSettings = levelSettings.resolve(level.levelSettings, settingsFor(level.displayLevel), settingsOptions);
|
||||||
const adapted = adapter.adaptLevel(copy(level), catalog, {
|
if (level.levelSettings) for (const id of [effectiveSettings.encounter.bossId, ...effectiveSettings.encounter.monsterIds]) {
|
||||||
routeData: scene.routeData, difficultyConfig: difficulty, boardRotationOffsetDeg: scene.rotation,
|
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);
|
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) {
|
} catch (error) {
|
||||||
add('游戏布局适配失败:' + error.message);
|
add('游戏布局适配失败:' + error.message);
|
||||||
return { issues, board: null };
|
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 { data, validate, copy, configure } = window.offlineEditor;
|
||||||
const model = window.MainlineWorkspace;
|
const model = window.MainlineWorkspace;
|
||||||
const key = 'offline-level-editor:' + data.rulesVersion + ':' + data.dataVersion;
|
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 = '';
|
let workspace = model.create(data), revisions = {}, storedText, storageError = '';
|
||||||
const activate = value => configure(value.order, value.templates, value.archivedLevels);
|
const activate = value => configure(value.order, value.templates, value.archivedLevels);
|
||||||
function ghostLevel(number, value = workspace) {
|
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; }
|
} catch (error) { workspace = model.create(data); storageError = '未恢复本机工作区:' + error.message; }
|
||||||
activate(workspace);
|
activate(workspace);
|
||||||
window.offlineEditor.api = async (url, body) => {
|
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/validate') return validate(body.level);
|
||||||
if (url === '/api/ghost-validate') return validateGhost(body.level);
|
if (url === '/api/ghost-validate') return validateGhost(body.level);
|
||||||
const ghostMatch = /^\/api\/ghost-levels\/(\d+)$/.exec(url);
|
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;
|
revisions.mainline = (revisions.mainline || 0) + 1;
|
||||||
}
|
}
|
||||||
const level = copy(workspace.levels[number - 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: '本机浏览器工作区;交付请导出完整数据包' };
|
...validate(level), backup: '本机浏览器工作区;交付请导出完整数据包' };
|
||||||
};
|
};
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
|||||||
+11
-1
@@ -20,7 +20,12 @@
|
|||||||
};
|
};
|
||||||
const inventory = model.sourceOrder(bundle), count = inventory.length;
|
const inventory = model.sourceOrder(bundle), count = inventory.length;
|
||||||
if (index.chunkSize !== 50 || count > 20000) throw new Error('项目分块规格不受支持');
|
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 = [];
|
const chunks = [];
|
||||||
for (let first = 1; first <= count; first += index.chunkSize) {
|
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 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]));
|
encounters.levels[id] = JSON.parse(JSON.stringify(encounters.levels[template]));
|
||||||
templates[id] = data.sourceTemplates[template] ?? 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;
|
difficulty.levelCount = count;
|
||||||
scheduleJson(directory + 'MainlineDifficulty.json', difficulty);
|
scheduleJson(directory + 'MainlineDifficulty.json', difficulty);
|
||||||
scheduleJson(directory + 'MainlineEncounterConfig.json', encounters);
|
scheduleJson(directory + 'MainlineEncounterConfig.json', encounters);
|
||||||
|
|||||||
@@ -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; } }
|
@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{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}
|
#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}
|
||||||
|
|||||||
+5
-3
@@ -2,6 +2,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
const copy = value => JSON.parse(JSON.stringify(value));
|
const copy = value => JSON.parse(JSON.stringify(value));
|
||||||
const fields = ['width', 'height', 'characters', 'aoes'];
|
const fields = ['width', 'height', 'characters', 'aoes'];
|
||||||
|
const settings = typeof module !== 'undefined' && module.exports ? require('./level-settings.cjs') : root.LevelSettings;
|
||||||
function importLayout(input) {
|
function importLayout(input) {
|
||||||
if (!input || typeof input !== 'object' || Array.isArray(input)) throw new Error('请选择有效的单关 JSON 对象');
|
if (!input || typeof input !== 'object' || Array.isArray(input)) throw new Error('请选择有效的单关 JSON 对象');
|
||||||
if (input.formatVersion !== undefined || Array.isArray(input.levels)) throw new Error('请选择导出的单关 JSON,不是完整关卡数据包');
|
if (input.formatVersion !== undefined || Array.isArray(input.levels)) throw new Error('请选择导出的单关 JSON,不是完整关卡数据包');
|
||||||
@@ -43,15 +44,16 @@
|
|||||||
result.templates[id] = template;
|
result.templates[id] = template;
|
||||||
const original = base.get(template);
|
const original = base.get(template);
|
||||||
if (!incoming || (active && incoming.displayLevel !== number) || fields.some(field => incoming[field] === undefined)) throw new Error('显示编号或布局字段无效:' + number);
|
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 };
|
...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.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)]));
|
result.archivedLevels = Object.fromEntries(Object.entries(archive).map(([id, level]) => [id, normalizeLevel(Number(id), level, Number(id), false)]));
|
||||||
return result;
|
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;
|
if (typeof module !== 'undefined' && module.exports) module.exports = api;
|
||||||
else root.MainlineWorkspace = api;
|
else root.MainlineWorkspace = api;
|
||||||
})(globalThis);
|
})(globalThis);
|
||||||
|
|||||||
@@ -2,6 +2,14 @@
|
|||||||
|
|
||||||
将整个文件夹解压到本机,双击 `编辑器.html`,使用 Chrome 或 Edge 打开。无需安装 Cocos、Node.js,也不需要网络或游戏项目。
|
将整个文件夹解压到本机,双击 `编辑器.html`,使用 Chrome 或 Edge 打开。无需安装 Cocos、Node.js,也不需要网络或游戏项目。
|
||||||
|
|
||||||
|
## 主线关卡属性
|
||||||
|
|
||||||
|
Boss 和小怪列表展示所有已配置的敌人。不符合当前关卡条件的条目置灰,不可选择,并标注解锁关数、适用场景或资源不可用等原因;调整关卡顺序或场景后会重新判断。
|
||||||
|
|
||||||
|
在右侧切换“关卡属性”,可修改场景、Boss、小怪组合、难度档位及展开后的战斗参数。至少保留一种小怪,敌人必须符合场景和解锁条件;校验失败不能保存或交付。仅显示资源与棋盘边界完整的场景。难度档位与战斗数值独立,切换档位不自动重算血量。面板下方显示游戏适配后的生效数值和只读特殊玩法配置,逐鹿不开放此项编辑。
|
||||||
|
|
||||||
|
新增主线关卡先确认模板配置摘要,再新增并按需修改属性。存本机、完整数据包及项目文件包均保留这些属性;单关 JSON 导入只读取棋盘,不会覆盖关卡属性。交付前导出项目文件包,程序应用后需重启游戏预览并验收,不会热更新运行中的游戏。
|
||||||
|
|
||||||
## 文件操作
|
## 文件操作
|
||||||
|
|
||||||
- 上传箭头:导入单关 JSON,应用到当前关卡,仅替换布局。
|
- 上传箭头:导入单关 JSON,应用到当前关卡,仅替换布局。
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"formatVersion": 2,
|
"formatVersion": 2,
|
||||||
"rulesVersion": "bf69adbdd5ac6b324cee9e8cb6bf2e46880fca4d177fa9393eb60d8adfdc0475",
|
"rulesVersion": "54938f36765f8f65ea85d0f58c58e455dcf85e69a471a68c4c98ade174b8dd04",
|
||||||
"dataVersion": "afc18028fffaa8aa75dafc5c935580e228964793ea3a4d082e5538406d742a73",
|
"dataVersion": "f4bffe795ce0ccfb4104439bb21f743bce3bb7951e85ff23ce869e4d3beeb1e7",
|
||||||
"order": [
|
"order": [
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
|
|||||||
Reference in New Issue
Block a user