同步关卡属性编辑与Boss小怪置灰提示
This commit is contained in:
+21
-9
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user