更新离线关卡编辑器,加入单关导入和抓猪关卡转换工具
This commit is contained in:
+9
-1
@@ -2,6 +2,14 @@
|
||||
'use strict';
|
||||
const copy = value => JSON.parse(JSON.stringify(value));
|
||||
const fields = ['width', 'height', 'characters', 'aoes'];
|
||||
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,不是完整关卡数据包');
|
||||
if (!Number.isInteger(input.width) || !Number.isInteger(input.height) || input.width < 1 || input.height < 1 || input.width > 64 || input.height > 64) throw new Error('单关 JSON 的棋盘列数和行数必须是 1 到 64 的整数');
|
||||
if (!Array.isArray(input.characters) || !Array.isArray(input.aoes)) throw new Error('单关 JSON 缺少军械或机关列表');
|
||||
// 关卡编号、来源及玩法元数据由目标关卡或所选模板决定,文件只提供布局。
|
||||
return Object.fromEntries(fields.map(field => [field, copy(input[field])]));
|
||||
}
|
||||
function create(data) {
|
||||
return { formatVersion: 2, rulesVersion: data.rulesVersion, dataVersion: data.dataVersion,
|
||||
order: [...data.order], templates: Object.fromEntries((data.sourceOrder || data.order).map(id => [id, id])), levels: copy(data.levels), archivedLevels: copy(data.archivedLevels || {}), ghostLayouts: copy(data.ghostLayouts || {}) };
|
||||
@@ -43,7 +51,7 @@
|
||||
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 };
|
||||
const api = { create, normalize, sourceOrder, sourceLevel, importLayout };
|
||||
if (typeof module !== 'undefined' && module.exports) module.exports = api;
|
||||
else root.MainlineWorkspace = api;
|
||||
})(globalThis);
|
||||
|
||||
Reference in New Issue
Block a user