diff --git a/抓猪关卡转换/piggy-converter/convert.mjs b/抓猪关卡转换/piggy-converter/convert.mjs index b2690ed..1b69993 100644 --- a/抓猪关卡转换/piggy-converter/convert.mjs +++ b/抓猪关卡转换/piggy-converter/convert.mjs @@ -1,6 +1,5 @@ import fs from 'node:fs'; import path from 'node:path'; -import { fileURLToPath } from 'node:url'; import converter from './converter.cjs'; const [input, output, mappingFile, zero = 'north'] = process.argv.slice(2); @@ -15,15 +14,18 @@ const mapping = mappingFile ? JSON.parse(fs.readFileSync(mappingFile, 'utf8')) : const files = fs.statSync(source).isDirectory() ? fs.readdirSync(source).filter(name => /^level\d+\.json$/i.test(name)).sort((a, b) => a.localeCompare(b, undefined, { numeric: true })).map(name => path.join(source, name)) : [source]; if (!files.length) throw new Error('输入目录没有 level数字.json 文件'); fs.mkdirSync(target, { recursive: true }); -const report = { source, mapping: mappingFile || '默认:普通动物转箭矢', angleZero: zero, success: 0, failed: 0, files: [] }; +const report = { source, mapping: mappingFile || '默认对象映射', angleZero: zero, success: 0, failed: 0, files: [] }; for (const file of files) { - let result; - try { result = converter.convert(JSON.parse(fs.readFileSync(file, 'utf8').replace(/^\uFEFF/, '')), mapping, zero); } - catch (error) { result = { ok: false, errors: ['读取或解析失败:' + error.message], warnings: [] }; } + let results; + try { results = converter.convertDocument(JSON.parse(fs.readFileSync(file, 'utf8').replace(/^\uFEFF/, '')), mapping, zero); } + catch (error) { results = [{ ok: false, errors: ['读取或解析失败:' + error.message], warnings: [] }]; } + for (const result of results) { const { layout, ...summary } = result; - report.files.push({ file: path.basename(file), ...summary }); - if (result.ok) { fs.writeFileSync(path.join(target, path.basename(file)), JSON.stringify(layout, null, 2)); report.success++; } + const output = converter.outputName(path.basename(file), result); + report.files.push({ file: path.basename(file), output, ...summary }); + if (result.ok) { fs.writeFileSync(path.join(target, output), JSON.stringify(layout, null, 2), { flag: 'wx' }); report.success++; } else report.failed++; + } } fs.writeFileSync(path.join(target, '转换报告.json'), JSON.stringify(report, null, 2)); console.log('转换完成:成功 ' + report.success + ',未转换 ' + report.failed + ';输出:' + target); diff --git a/抓猪关卡转换/piggy-converter/converter.cjs b/抓猪关卡转换/piggy-converter/converter.cjs index 5cac929..e33ee7a 100644 --- a/抓猪关卡转换/piggy-converter/converter.cjs +++ b/抓猪关卡转换/piggy-converter/converter.cjs @@ -1,8 +1,92 @@ (function (root) { 'use strict'; - const defaults = { animalGroup: { 1: { id: 1, collection: 'characters', length: 2, width: 1 } }, obstacleGroup: {} }; + const defaults = { + animalGroup: { + 1: { id: 1, collection: 'characters', length: 2, width: 1 }, + 100: { id: 2, collection: 'characters', length: 2, width: 1 } + }, obstacleGroup: {}, + animals: { + pig: { id: 1, collection: 'characters', length: 2, width: 1 }, + pigBomb: { id: 2, collection: 'characters', length: 2, width: 1, parameter: 'collisionBomb' }, + pigClock: { id: 4, collection: 'characters', length: 2, width: 1, parameter: 'countdownBomb' }, + duck: { id: 3, collection: 'characters', length: 1, width: 1 }, + bear: { id: 5, collection: 'characters', length: 3, width: 2 } + } + }; + const own = (object, key) => Object.prototype.hasOwnProperty.call(object, key); + function convertCells(source, mapping = defaults) { + const unsupportedTypes = []; + const errors = [], warnings = ['按当前 animals/cells 转换,不读取 editor.sourceLevel 备份;每 2×2 源格合为 1 个目标格。', + '朝向按 d=0上/1右/2下/3左、行号保持递增转换;源文件标记 runtimeVerified=false 时仍需核对原工具画面。', + '跨项目对象采用近似玩法映射:pig→箭、pigBomb→爆破箭矢、pigClock→计时箭矢、duck→滚石、bear→张飞;须验收玩法。', + '计时参数写入对象冷却效果,但游戏仍会应用模板的 boomTime 及难度上限,最终时长可能不同。']; + const width = source?.cols / 2, height = source?.rows / 2; + const layout = { width, height, characters: [], aoes: [] }, occupied = new Set(); + if (![width, height].every(n => Number.isInteger(n) && n > 0 && n <= 64)) errors.push('棋盘列数和行数必须是 2 到 128 的偶数'); + if (source?.placement !== 'explicit_cells') errors.push('仅支持 placement=explicit_cells 的当前布局'); + if (source?.levelMode) errors.push('非默认 levelMode 暂不支持'); + if (!Array.isArray(source?.animals) || source.animals.length > 2048) errors.push('animals 必须是最多 2048 个对象的数组'); + for (const key of Object.keys(source || {})) if (!['id', 'sourceImgid', 'cols', 'rows', 'cellSize', 'pigScale', 'levelMode', 'placement', 'levelUiName', 'animals', 'editor'].includes(key)) errors.push('尚未支持的关卡字段:' + key); + for (const [index, animal] of (Array.isArray(source?.animals) ? source.animals : []).entries()) { + try { + const rule = own(mapping?.animals || {}, animal?.type) ? mapping.animals[animal.type] : null; + if (!rule) { + if (!unsupportedTypes.some(item => item.type === animal?.type)) unsupportedTypes.push({ collection: 'animals', type: animal?.type }); + throw new Error('类型 ' + animal?.type + ' 未适配,未配置当前布局映射'); + } + if (!['characters', 'aoes'].includes(rule.collection) || !Number.isSafeInteger(rule.id) || rule.id < 1 || ![rule.length, rule.width].every(n => Number.isInteger(n) && n > 0 && n <= 64)) throw new Error('映射规则无效'); + if (!Number.isInteger(animal.d) || animal.d < 0 || animal.d > 3) throw new Error('方向 d 必须是 0 到 3'); + const col = animal.c / 2, row = animal.r / 2; + const sx = animal.d % 2 ? rule.length : rule.width, sy = animal.d % 2 ? rule.width : rule.length; + if (![col, row].every(Number.isInteger) || col < 0 || row < 0 || col + sx > width || row + sy > height) throw new Error('坐标无法对齐目标格或超出棋盘'); + if (!Array.isArray(animal.cells) || animal.cells.length !== sx * sy * 4) throw new Error('实际占格不匹配目标对象;不能缩小或丢弃占格'); + const cells = new Set(); + for (const cell of animal.cells) { + if (!Number.isInteger(cell?.c) || !Number.isInteger(cell?.r) || cell.c < animal.c || cell.c >= animal.c + sx * 2 || cell.r < animal.r || cell.r >= animal.r + sy * 2) throw new Error('cells 不是映射对象所需的完整矩形'); + cells.add(cell.c + ',' + cell.r); + } + if (cells.size !== animal.cells.length) throw new Error('cells 存在重复格'); + const allowed = ['id', 'type', 'c', 'r', 'd', 'k', 'cells', 'sourceType', 'sourceId', 'sourceSkinIndex', 'sourceAnimalIndex', 'sourcePartIndex', 'sourceParts', 'sourceObstacleIndex']; + if (rule.parameter === 'collisionBomb') allowed.push('bombNum'); + if (rule.parameter === 'countdownBomb') allowed.push('timerNum'); + const unsupported = Object.keys(animal).filter(key => !allowed.includes(key)); + if (unsupported.length) throw new Error('未支持的对象参数:' + unsupported.join('、')); + if (rule.parameter === 'collisionBomb' && animal.bombNum !== 3) throw new Error('本项目爆破箭矢固定为 3 次碰撞,不能保留 bombNum=' + animal.bombNum); + const entry = [rule.id, col, row, [3, 2, 1, 4][animal.d]]; + let extra = rule.extra ? JSON.parse(JSON.stringify(rule.extra)) : null; + if (rule.parameter === 'countdownBomb') { + if (!Number.isFinite(animal.timerNum) || animal.timerNum < 0) throw new Error('timerNum 必须是非负数'); + extra ||= {}; extra.addBuff ||= []; + if (!Array.isArray(extra.addBuff) || extra.addBuff.some(item => item?.buffId === 'cool-down')) throw new Error('映射附加参数中的倒计时与源参数冲突'); + extra.addBuff.push({ addStack: 1, buffId: 'cool-down', duration: 0, durationSetTo: true, permanent: true, buffParam: { duration: animal.timerNum } }); + } + if (extra) entry.push(extra); + if (rule.collection === 'characters') for (let y = row; y < row + sy; y++) for (let x = col; x < col + sx; x++) { + const key = x + ',' + y; + if (occupied.has(key)) throw new Error('军械占格重叠:' + key); + occupied.add(key); + } + layout[rule.collection].push(entry); + } catch (error) { errors.push('animals[' + index + ']:' + error.message); } + } + return { ok: errors.length === 0, layout: errors.length ? null : layout, errors, warnings, unsupportedTypes }; + } + function convertDocument(source, mapping = defaults, zero = 'north') { + if (source?.format !== 'zhuazhu-level-arrangement') return [{ name: '单关', ...convert(source, mapping, zero) }]; + if (source.version !== 1 || !Array.isArray(source.slots) || !source.slots.length || source.slots.length > 20000 || !source.levels || typeof source.levels !== 'object' || Array.isArray(source.levels)) throw new Error('关卡编排合集版本或结构无效'); + const slotIds = new Set(); + return source.slots.map((slot, index) => { + const number = index + 1, name = '第' + String(number).padStart(3, '0') + '关'; + if (!slot || typeof slot.slotId !== 'string' || !slot.slotId || slotIds.has(slot.slotId) || !own(source.levels, slot.slotId)) return { number, name, ok: false, layout: null, errors: ['编排位置缺少布局或 slotId 重复'], warnings: [] }; + slotIds.add(slot.slotId); + return { number, name, sourceKey: slot.key, slotId: slot.slotId, ...convertCells(source.levels[slot.slotId], mapping) }; + }); + } function convert(source, mapping = defaults, zero = 'north') { + if (source?.format === 'zhuazhu-level-arrangement') throw new Error('这是多关编排合集,请使用 convertDocument 按编排顺序转换'); + if (source?.placement === 'explicit_cells') return convertCells(source, mapping); const errors = [], warnings = ['转换假设:size 为格数,position 为居中棋盘中的占格左下角,角度按顺时针递增。尚未核对原游戏代码或画面,导入后须检查朝向和占格。']; + const unsupportedTypes = []; const fail = message => errors.push(message); const width = source?.size?.x, height = source?.size?.y; const layout = { width, height, characters: [], aoes: [] }; @@ -14,8 +98,11 @@ if (!Array.isArray(source?.[group])) { fail(group + ' 必须是数组'); continue; } source[group].forEach((object, index) => { const name = group + '[' + index + ']'; - const rule = mapping?.[group]?.[object?.type]; - if (!rule) { fail(name + ':类型 ' + object?.type + ' 未配置映射'); return; } + const rule = own(mapping?.[group] || {}, object?.type) ? mapping[group][object.type] : null; + if (!rule) { + if (!unsupportedTypes.some(item => item.collection === group && item.type === object?.type)) unsupportedTypes.push({ collection: group, type: object?.type }); + fail(name + ':类型 ' + object?.type + ' 未适配,未配置映射'); return; + } if (!['characters', 'aoes'].includes(rule.collection) || !Number.isSafeInteger(rule.id) || rule.id < 1 || ![rule.length, rule.width].every(n => Number.isInteger(n) && n > 0 && n <= 64)) { fail(name + ':映射规则无效'); return; } if (!Number.isFinite(object.angle) || object.angle % 90 !== 0 || !Number.isFinite(object.position?.x) || !Number.isFinite(object.position?.y)) { fail(name + ':坐标或角度无效,角度必须为 90 的倍数'); return; } const angle = ((object.angle % 360) + 360) % 360; @@ -45,9 +132,20 @@ if (source?.openMole) fail('存在地鼠玩法 openMole,暂不支持转换'); if (source?.levelMode) fail('非默认 levelMode,暂不支持转换'); warnings.push('相机参数、皮肤编号、难度、奖励不导入;目标关卡级配置由编辑器所选模板继承。'); - return { ok: errors.length === 0, layout: errors.length ? null : layout, errors: [...new Set(errors)], warnings }; + if (source?.animalGroup?.some(object => object?.type === 100)) warnings.push('源类型 100 按编排合集中的爆破猪对应为爆破箭矢;目标固定 3 次碰撞,跨项目玩法仍需验收。'); + return { ok: errors.length === 0, layout: errors.length ? null : layout, errors: [...new Set(errors)], warnings, unsupportedTypes }; } - const api = { convert, defaults }; + function outputName(file, result) { + const stem = file.replace(/\.json$/i, '').replace(/[<>:"/\\|?*\x00-\x1f]/g, '_').slice(0, 80); + return stem + (result.number ? '-' + result.name : '') + '.json'; + } + const targetTypes = [ + [1, '箭', 2, 1], [2, '爆破箭矢', 2, 1], [3, '滚石', 1, 1], [4, '计时炸弹箭矢', 2, 1], + [5, '张飞', 3, 2], [6, '舞女', 2, 1], [7, '张角', 2, 1], [8, '黄忠', 2, 1], + [9, '赵云', 2, 1], [10, '攻城车', 2, 1], [11, '羽扇', 2, 1], [12, '木栅栏', 1, 1], + [13, '将旗', 1, 1], [14, '火船', 1, 1], [101, '拒马', 1, 1], [102, '铁索1×2', 2, 1], [103, '铁索2×2', 2, 2] + ].map(([id, name, length, width]) => ({ id, name, length, width, collection: id >= 100 ? 'aoes' : 'characters' })); + const api = { convert, convertDocument, outputName, defaults, targetTypes }; if (typeof module !== 'undefined' && module.exports) module.exports = api; else root.PiggyConverter = api; })(globalThis); diff --git a/抓猪关卡转换/piggy-converter/fflate.js b/抓猪关卡转换/piggy-converter/fflate.js new file mode 100644 index 0000000..6b81793 --- /dev/null +++ b/抓猪关卡转换/piggy-converter/fflate.js @@ -0,0 +1 @@ +!function(f){typeof module!='undefined'&&typeof exports=='object'?module.exports=f():typeof define!='undefined'&&define.amd?define(f):(typeof self!='undefined'?self:this).fflate=f()}(function(){var _e={};"use strict";var t=(typeof module!='undefined'&&typeof exports=='object'?function(_f){"use strict";var e,t=";var __w=require('worker_threads');__w.parentPort.on('message',function(m){onmessage({data:m})}),postMessage=function(m,t){__w.parentPort.postMessage(m,t)},close=process.exit;self=global";try{e=require("worker_threads").Worker}catch(e){}exports.default=e?function(r,n,o,a,s){var u=!1,i=new e(r+t,{eval:!0}).on("error",(function(e){return s(e,null)})).on("message",(function(e){return s(null,e)})).on("exit",(function(e){e&&!u&&s(Error("exited with code "+e),null)}));return i.postMessage(o,a),i.terminate=function(){return u=!0,e.prototype.terminate.call(i)},i}:function(e,t,r,n,o){setImmediate((function(){return o(Error("async operations unsupported - update to Node 12+ (or Node 10-11 with the --experimental-worker CLI flag)"),null)}));var a=function(){};return{terminate:a,postMessage:a}};return _f}:function(_f){"use strict";var e={};_f.default=function(r,t,s,a,n){var o=new Worker(e[t]||(e[t]=URL.createObjectURL(new Blob([r+';addEventListener("error",function(e){e=e.error;postMessage({$e$:[e.message,e.code,e.stack]})})'],{type:"text/javascript"}))));return o.onmessage=function(e){var r=e.data,t=r.$e$;if(t){var s=Error(t[0]);s.code=t[1],s.stack=t[2],n(s,null)}else n(null,r)},o.postMessage(s,a),o};return _f})({}),n=Uint8Array,r=Uint16Array,e=Int32Array,i=new n([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),o=new n([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),s=new n([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),a=function(t,n){for(var i=new r(31),o=0;o<31;++o)i[o]=n+=1<>1|(21845&d)<<1;v[d]=((65280&(g=(61680&(g=(52428&g)>>2|(13107&g)<<2))>>4|(3855&g)<<4))>>8|(255&g)<<8)>>1}var y=function(t,n,e){for(var i=t.length,o=0,s=new r(n);o>h]=f}else for(a=new r(i),o=0;o>15-t[o]);return a},m=new n(288);for(d=0;d<144;++d)m[d]=8;for(d=144;d<256;++d)m[d]=9;for(d=256;d<280;++d)m[d]=7;for(d=280;d<288;++d)m[d]=8;var b=new n(32);for(d=0;d<32;++d)b[d]=5;var w=y(m,9,0),x=y(m,9,1),z=y(b,5,0),k=y(b,5,1),M=function(t){for(var n=t[0],r=1;rn&&(n=t[r]);return n},S=function(t,n,r){var e=n/8|0;return(t[e]|t[e+1]<<8)>>(7&n)&r},A=function(t,n){var r=n/8|0;return(t[r]|t[r+1]<<8|t[r+2]<<16)>>(7&n)},T=function(t){return(t+7)/8|0},D=function(t,r,e){return(null==r||r<0)&&(r=0),(null==e||e>t.length)&&(e=t.length),new n(t.subarray(r,e))};_e.FlateErrorCode={UnexpectedEOF:0,InvalidBlockType:1,InvalidLengthLiteral:2,InvalidDistance:3,StreamFinished:4,NoStreamHandler:5,InvalidHeader:6,NoCallback:7,InvalidUTF8:8,ExtraFieldTooLong:9,InvalidDate:10,FilenameTooLong:11,StreamFinishing:12,InvalidZipData:13,UnknownCompressionMethod:14};var C=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],I=function(t,n,r){var e=Error(n||C[t]);if(e.code=t,Error.captureStackTrace&&Error.captureStackTrace(e,I),!r)throw e;return e},U=function(t,r,e,a){var u=t.length,f=a?a.length:0;if(!u||r.f&&!r.l)return e||new n(0);var l=!e,p=l||2!=r.i,v=r.i;l&&(e=new n(3*u));var d=function(t){var r=e.length;if(t>r){var i=new n(Math.max(2*r,t));i.set(e),e=i}},g=r.f||0,m=r.p||0,b=r.b||0,w=r.l,z=r.d,C=r.m,U=r.n,F=8*u;do{if(!w){g=S(t,m,1);var E=S(t,m+1,3);if(m+=3,!E){var Z=t[(J=T(m)+4)-4]|t[J-3]<<8,q=J+Z;if(q>u){v&&I(0);break}p&&d(b+Z),e.set(t.subarray(J,q),b),r.b=b+=Z,r.p=m=8*q,r.f=g;continue}if(1==E)w=x,z=k,C=9,U=5;else if(2==E){var O=S(t,m,31)+257,G=S(t,m+10,15)+4,L=O+S(t,m+5,31)+1;m+=14;for(var H=new n(L),j=new n(19),N=0;N>4)<16)H[N++]=J;else{var Q=0,R=0;for(16==J?(R=3+S(t,m,3),m+=2,Q=H[N-1]):17==J?(R=3+S(t,m,7),m+=3):18==J&&(R=11+S(t,m,127),m+=7);R--;)H[N++]=Q}}var V=H.subarray(0,O),W=H.subarray(O);C=M(V),U=M(W),w=y(V,C,1),z=y(W,U,1)}else I(1);if(m>F){v&&I(0);break}}p&&d(b+131072);for(var X=(1<>4;if((m+=15&Q)>F){v&&I(0);break}if(Q||I(2),tt<256)e[b++]=tt;else{if(256==tt){_=m,w=null;break}var nt=tt-254;tt>264&&(nt=S(t,m,(1<<(it=i[N=tt-257]))-1)+h[N],m+=it);var rt=z[A(t,m)&$],et=rt>>4;if(rt||I(3),m+=15&rt,W=c[et],et>3){var it=o[et];W+=A(t,m)&(1<F){v&&I(0);break}p&&d(b+131072);var ot=b+nt;if(b>8},E=function(t,n,r){var e=n/8|0;t[e]|=r<<=7&n,t[e+1]|=r>>8,t[e+2]|=r>>16},Z=function(t,e){for(var i=[],o=0;ov&&(v=a[o].s);var d=new r(v+1),g=q(i[c-1],d,0);if(g>e){o=0;var y=0,m=g-e,b=1<e))break;y+=b-(1<>=m;y>0;){var x=a[o].s;d[x]=0&&y;--o){var z=a[o].s;d[z]==e&&(--d[z],++y)}g=e}return{t:new n(d),l:g}},q=function(t,n,r){return-1==t.s?Math.max(q(t.l,n,r+1),q(t.r,n,r+1)):n[t.s]=r},O=function(t){for(var n=t.length;n&&!t[--n];);for(var e=new r(++n),i=0,o=t[0],s=1,a=function(t){e[i++]=t},u=1;u<=n;++u)if(t[u]==o&&u!=n)++s;else{if(!o&&s>2){for(;s>138;s-=138)a(32754);s>2&&(a(s>10?s-11<<5|28690:s-3<<5|12305),s=0)}else if(s>3){for(a(o),--s;s>6;s-=6)a(8304);s>2&&(a(s-3<<5|8208),s=0)}for(;s--;)a(o);s=1,o=t[u]}return{c:e.subarray(0,i),n:n}},G=function(t,n){for(var r=0,e=0;e>8,t[i+2]=255^t[i],t[i+3]=255^t[i+1];for(var o=0;o4&&!N[s[B-1]];--B);var Y,J,K,Q,R=p+5<<3,V=G(u,m)+G(h,b)+f,W=G(u,g)+G(h,M)+f+14+3*B+G(q,N)+2*q[16]+3*q[17]+7*q[18];if(c>=0&&R<=V&&R<=W)return L(n,v,t.subarray(c,c+p));if(F(n,v,1+(W15&&(F(n,v,tt[H]>>5&127),v+=tt[H]>>12)}}else Y=w,J=m,K=z,Q=b;for(H=0;H255){var rt;E(n,v,Y[257+(rt=nt>>18&31)]),v+=J[rt+257],rt>7&&(F(n,v,nt>>23&31),v+=i[rt]);var et=31&nt;E(n,v,K[et]),v+=Q[et],et>3&&(E(n,v,nt>>5&8191),v+=o[et])}else E(n,v,Y[nt]),v+=J[nt]}return E(n,v,Y[256]),v+J[256]},j=new e([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),N=new n(0),P=function(t,s,a,u,h,l){var c=l.z||t.length,v=new n(u+c+5*(1+Math.ceil(c/7e3))+h),d=v.subarray(u,v.length-h),g=l.l,y=7&(l.r||0);if(s){y&&(d[0]=l.r>>3);for(var m=j[s-1],b=m>>13,w=8191&m,x=(1<7e3||q>24576)&&(Y>423||!g)){y=H(t,d,0,C,I,U,E,q,G,Z-G,y),q=F=E=0,G=Z;for(var J=0;J<286;++J)I[J]=0;for(J=0;J<30;++J)U[J]=0}var K=2,Q=0,R=w,V=P-B&32767;if(Y>2&&N==A(Z-V))for(var W=Math.min(b,Y)-1,X=Math.min(32767,Z),$=Math.min(258,Y);V<=X&&--R&&P!=B;){if(t[Z+K]==t[Z+K-V]){for(var _=0;_<$&&t[Z+_]==t[Z+_-V];++_);if(_>K){if(K=_,Q=V,_>W)break;var tt=Math.min(V,_-2),nt=0;for(J=0;Jnt&&(nt=et,B=rt)}}}V+=(P=B)-(B=z[P])&32767}if(Q){C[q++]=268435456|f[K]<<18|p[Q];var it=31&f[K],ot=31&p[Q];E+=i[it]+o[ot],++I[257+it],++U[ot],O=Z+K,++F}else C[q++]=t[Z],++I[t[Z]]}}for(Z=Math.max(Z,O);Z=c&&(d[y/8|0]=g,st=c),y=L(d,y+1,t.subarray(Z,st))}l.i=c}return D(v,0,u+T(y)+h)},B=function(){for(var t=new Int32Array(256),n=0;n<256;++n){for(var r=n,e=9;--e;)r=(1&r&&-306674912)^r>>>1;t[n]=r}return t}(),Y=function(){var t=-1;return{p:function(n){for(var r=t,e=0;e>>8;t=r},d:function(){return~t}}},J=function(){var t=1,n=0;return{p:function(r){for(var e=t,i=n,o=0|r.length,s=0;s!=o;){for(var a=Math.min(s+2655,o);s>16),i=(65535&i)+15*(i>>16)}t=e,n=i},d:function(){return(255&(t%=65521))<<24|(65280&t)<<8|(255&(n%=65521))<<8|n>>8}}},K=function(t,r,e,i,o){if(!o&&(o={l:1},r.dictionary)){var s=r.dictionary.subarray(-32768),a=new n(s.length+t.length);a.set(s),a.set(t,s.length),t=a,o.w=s.length}return P(t,null==r.level?6:r.level,null==r.mem?o.l?Math.ceil(1.5*Math.max(8,Math.min(13,Math.log(t.length)))):20:12+r.mem,e,i,o)},Q=function(t,n){var r={};for(var e in t)r[e]=t[e];for(var e in n)r[e]=n[e];return r},R=function(t,n,r){for(var e=t(),i=""+t,o=i.slice(i.indexOf("[")+1,i.lastIndexOf("]")).replace(/\s+/g,"").split(","),s=0;s>>0},lt=function(t,n){return ft(t,n)+4294967296*ft(t,n+4)},ct=function(t,n,r){for(;r;++n)t[n]=r,r>>>=8},pt=function(t,n){var r=n.filename;if(t[0]=31,t[1]=139,t[2]=8,t[8]=n.level<2?4:9==n.level?2:0,t[9]=3,0!=n.mtime&&ct(t,4,Math.floor(new Date(n.mtime||Date.now())/1e3)),r){t[3]=8;for(var e=0;e<=r.length;++e)t[e+10]=r.charCodeAt(e)}},vt=function(t){31==t[0]&&139==t[1]&&8==t[2]||I(6,"invalid gzip data");var n=t[3],r=10;4&n&&(r+=2+(t[10]|t[11]<<8));for(var e=(n>>3&1)+(n>>4&1);e>0;e-=!t[r++]);return r+(2&n)},dt=function(t){var n=t.length;return(t[n-4]|t[n-3]<<8|t[n-2]<<16|t[n-1]<<24)>>>0},gt=function(t){return 10+(t.filename?t.filename.length+1:0)},yt=function(t,n){var r=n.level,e=0==r?0:r<6?1:9==r?3:2;if(t[0]=120,t[1]=e<<6|(n.dictionary&&32),t[1]|=31-(t[0]<<8|t[1])%31,n.dictionary){var i=J();i.p(n.dictionary),ct(t,2,i.d())}},mt=function(t,n){return(8!=(15&t[0])||t[0]>>4>7||(t[0]<<8|t[1])%31)&&I(6,"invalid zlib data"),(t[1]>>5&1)==+!n&&I(6,"invalid zlib data: "+(32&t[1]?"need":"unexpected")+" dictionary"),2+(t[1]>>3&4)};function bt(t,n){return"function"==typeof t&&(n=t,t={}),this.ondata=n,t}var wt=function(){function t(t,r){if("function"==typeof t&&(r=t,t={}),this.ondata=r,this.o=t||{},this.s={l:0,i:32768,w:32768,z:32768},this.b=new n(98304),this.o.dictionary){var e=this.o.dictionary.subarray(-32768);this.b.set(e,32768-e.length),this.s.i=32768-e.length}}return t.prototype.p=function(t,n){this.ondata(K(t,this.o,0,0,this.s),n)},t.prototype.push=function(t,r){this.ondata||I(5),this.s.l&&I(4);var e=t.length+this.s.z;if(e>this.b.length){if(e>2*this.b.length-32768){var i=new n(-32768&e);i.set(this.b.subarray(0,this.s.z)),this.b=i}var o=this.b.length-this.s.z;this.b.set(t.subarray(0,o),this.s.z),this.s.z=this.b.length,this.p(this.b,!1),this.b.set(this.b.subarray(-32768)),this.b.set(t.subarray(o),32768),this.s.z=t.length-o+32768,this.s.i=32766,this.s.w=32768}else this.b.set(t,this.s.z),this.s.z+=t.length;this.s.l=1&r,(this.s.z>this.s.w+8191||r)&&(this.p(this.b,r||!1),this.s.w=this.s.i,this.s.i-=2)},t.prototype.flush=function(){this.ondata||I(5),this.s.l&&I(4),this.p(this.b,!1),this.s.w=this.s.i,this.s.i-=2},t}();_e.Deflate=wt;var xt=function(){return function(t,n){ut([_,function(){return[at,wt]}],this,bt.call(this,t,n),(function(t){var n=new wt(t.data);onmessage=at(n)}),6,1)}}();function zt(t,n,r){return r||(r=n,n={}),"function"!=typeof r&&I(7),st(t,n,[_],(function(t){return it(kt(t.data[0],t.data[1]))}),0,r)}function kt(t,n){return K(t,n||{},0,0)}_e.AsyncDeflate=xt,_e.deflate=zt,_e.deflateSync=kt;var Mt=function(){function t(t,r){"function"==typeof t&&(r=t,t={}),this.ondata=r;var e=t&&t.dictionary&&t.dictionary.subarray(-32768);this.s={i:0,b:e?e.length:0},this.o=new n(32768),this.p=new n(0),e&&this.o.set(e)}return t.prototype.e=function(t){if(this.ondata||I(5),this.d&&I(4),this.p.length){if(t.length){var r=new n(this.p.length+t.length);r.set(this.p),r.set(t,this.p.length),this.p=r}}else this.p=t},t.prototype.c=function(t){this.s.i=+(this.d=t||!1);var n=this.s.b,r=U(this.p,this.s,this.o);this.ondata(D(r,n,this.s.b),this.d),this.o=D(r,this.s.b-32768),this.s.b=this.o.length,this.p=D(this.p,this.s.p/8|0),this.s.p&=7},t.prototype.push=function(t,n){this.e(t),this.c(n)},t}();_e.Inflate=Mt;var St=function(){return function(t,n){ut([$,function(){return[at,Mt]}],this,bt.call(this,t,n),(function(t){var n=new Mt(t.data);onmessage=at(n)}),7,0)}}();function At(t,n,r){return r||(r=n,n={}),"function"!=typeof r&&I(7),st(t,n,[$],(function(t){return it(Tt(t.data[0],ot(t.data[1])))}),1,r)}function Tt(t,n){return U(t,{i:2},n&&n.out,n&&n.dictionary)}_e.AsyncInflate=St,_e.inflate=At,_e.inflateSync=Tt;var Dt=function(){function t(t,n){this.c=Y(),this.l=0,this.v=1,wt.call(this,t,n)}return t.prototype.push=function(t,n){this.c.p(t),this.l+=t.length,wt.prototype.push.call(this,t,n)},t.prototype.p=function(t,n){var r=K(t,this.o,this.v&>(this.o),n&&8,this.s);this.v&&(pt(r,this.o),this.v=0),n&&(ct(r,r.length-8,this.c.d()),ct(r,r.length-4,this.l)),this.ondata(r,n)},t.prototype.flush=function(){wt.prototype.flush.call(this)},t}();_e.Gzip=Dt,_e.Compress=Dt;var Ct=function(){return function(t,n){ut([_,tt,function(){return[at,wt,Dt]}],this,bt.call(this,t,n),(function(t){var n=new Dt(t.data);onmessage=at(n)}),8,1)}}();function It(t,n,r){return r||(r=n,n={}),"function"!=typeof r&&I(7),st(t,n,[_,tt,function(){return[Ut]}],(function(t){return it(Ut(t.data[0],t.data[1]))}),2,r)}function Ut(t,n){n||(n={});var r=Y(),e=t.length;r.p(t);var i=K(t,n,gt(n),8),o=i.length;return pt(i,n),ct(i,o-8,r.d()),ct(i,o-4,e),i}_e.AsyncGzip=Ct,_e.AsyncCompress=Ct,_e.gzip=It,_e.compress=It,_e.gzipSync=Ut,_e.compressSync=Ut;var Ft=function(){function t(t,n){this.v=1,this.r=0,Mt.call(this,t,n)}return t.prototype.push=function(t,r){if(Mt.prototype.e.call(this,t),this.r+=t.length,this.v){var e=this.p.subarray(this.v-1),i=e.length>3?vt(e):4;if(i>e.length){if(!r)return}else this.v>1&&this.onmember&&this.onmember(this.r-e.length);this.p=e.subarray(i),this.v=0}Mt.prototype.c.call(this,r),!this.s.f||this.s.l||r||(this.v=T(this.s.p)+9,this.s={i:0},this.o=new n(0),this.push(new n(0),r))},t}();_e.Gunzip=Ft;var Et=function(){return function(t,n){var r=this;ut([$,nt,function(){return[at,Mt,Ft]}],this,bt.call(this,t,n),(function(t){var n=new Ft(t.data);n.onmember=function(t){return postMessage(t)},onmessage=at(n)}),9,0,(function(t){return r.onmember&&r.onmember(t)}))}}();function Zt(t,n,r){return r||(r=n,n={}),"function"!=typeof r&&I(7),st(t,n,[$,nt,function(){return[qt]}],(function(t){return it(qt(t.data[0],t.data[1]))}),3,r)}function qt(t,r){var e=vt(t);return e+8>t.length&&I(6,"invalid gzip data"),U(t.subarray(e,-8),{i:2},r&&r.out||new n(dt(t)),r&&r.dictionary)}_e.AsyncGunzip=Et,_e.gunzip=Zt,_e.gunzipSync=qt;var Ot=function(){function t(t,n){this.c=J(),this.v=1,wt.call(this,t,n)}return t.prototype.push=function(t,n){this.c.p(t),wt.prototype.push.call(this,t,n)},t.prototype.p=function(t,n){var r=K(t,this.o,this.v&&(this.o.dictionary?6:2),n&&4,this.s);this.v&&(yt(r,this.o),this.v=0),n&&ct(r,r.length-4,this.c.d()),this.ondata(r,n)},t.prototype.flush=function(){wt.prototype.flush.call(this)},t}();_e.Zlib=Ot;var Gt=function(){return function(t,n){ut([_,rt,function(){return[at,wt,Ot]}],this,bt.call(this,t,n),(function(t){var n=new Ot(t.data);onmessage=at(n)}),10,1)}}();function Lt(t,n,r){return r||(r=n,n={}),"function"!=typeof r&&I(7),st(t,n,[_,rt,function(){return[Ht]}],(function(t){return it(Ht(t.data[0],t.data[1]))}),4,r)}function Ht(t,n){n||(n={});var r=J();r.p(t);var e=K(t,n,n.dictionary?6:2,4);return yt(e,n),ct(e,e.length-4,r.d()),e}_e.AsyncZlib=Gt,_e.zlib=Lt,_e.zlibSync=Ht;var jt=function(){function t(t,n){Mt.call(this,t,n),this.v=t&&t.dictionary?2:1}return t.prototype.push=function(t,n){if(Mt.prototype.e.call(this,t),this.v){if(this.p.length<6&&!n)return;this.p=this.p.subarray(mt(this.p,this.v-1)),this.v=0}n&&(this.p.length<4&&I(6,"invalid zlib data"),this.p=this.p.subarray(0,-4)),Mt.prototype.c.call(this,n)},t}();_e.Unzlib=jt;var Nt=function(){return function(t,n){ut([$,et,function(){return[at,Mt,jt]}],this,bt.call(this,t,n),(function(t){var n=new jt(t.data);onmessage=at(n)}),11,0)}}();function Pt(t,n,r){return r||(r=n,n={}),"function"!=typeof r&&I(7),st(t,n,[$,et,function(){return[Bt]}],(function(t){return it(Bt(t.data[0],ot(t.data[1])))}),5,r)}function Bt(t,n){return U(t.subarray(mt(t,n&&n.dictionary),-4),{i:2},n&&n.out,n&&n.dictionary)}_e.AsyncUnzlib=Nt,_e.unzlib=Pt,_e.unzlibSync=Bt;var Yt=function(){function t(t,n){this.o=bt.call(this,t,n)||{},this.G=Ft,this.I=Mt,this.Z=jt}return t.prototype.i=function(){var t=this;this.s.ondata=function(n,r){t.ondata(n,r)}},t.prototype.push=function(t,r){if(this.ondata||I(5),this.s)this.s.push(t,r);else{if(this.p&&this.p.length){var e=new n(this.p.length+t.length);e.set(this.p),e.set(t,this.p.length)}else this.p=t;this.p.length>2&&(this.s=31==this.p[0]&&139==this.p[1]&&8==this.p[2]?new this.G(this.o):8!=(15&this.p[0])||this.p[0]>>4>7||(this.p[0]<<8|this.p[1])%31?new this.I(this.o):new this.Z(this.o),this.i(),this.s.push(this.p,r),this.p=null)}},t}();_e.Decompress=Yt;var Jt=function(){function t(t,n){Yt.call(this,t,n),this.queuedSize=0,this.G=Et,this.I=St,this.Z=Nt}return t.prototype.i=function(){var t=this;this.s.ondata=function(n,r,e){t.ondata(n,r,e)},this.s.ondrain=function(n){t.queuedSize-=n,t.ondrain&&t.ondrain(n)}},t.prototype.push=function(t,n){this.queuedSize+=t.length,Yt.prototype.push.call(this,t,n)},t}();function Kt(t,n,r){return r||(r=n,n={}),"function"!=typeof r&&I(7),31==t[0]&&139==t[1]&&8==t[2]?Zt(t,n,r):8!=(15&t[0])||t[0]>>4>7||(t[0]<<8|t[1])%31?At(t,n,r):Pt(t,n,r)}function Qt(t,n){return 31==t[0]&&139==t[1]&&8==t[2]?qt(t,n):8!=(15&t[0])||t[0]>>4>7||(t[0]<<8|t[1])%31?Tt(t,n):Bt(t,n)}_e.AsyncDecompress=Jt,_e.decompress=Kt,_e.decompressSync=Qt;var Rt=function(t,r,e,i){for(var o in t){var s=t[o],a=r+o,u=i;Array.isArray(s)&&(u=Q(i,s[1]),s=s[0]),s instanceof n?e[a]=[s,u]:(e[a+="/"]=[new n(0),u],Rt(s,a,e,i))}},Vt="undefined"!=typeof TextEncoder&&new TextEncoder,Wt="undefined"!=typeof TextDecoder&&new TextDecoder,Xt=0;try{Wt.decode(N,{stream:!0}),Xt=1}catch(t){}var $t=function(t){for(var n="",r=0;;){var e=t[r++],i=(e>127)+(e>223)+(e>239);if(r+i>t.length)return{s:n,r:D(t,r-1)};i?3==i?(e=((15&e)<<18|(63&t[r++])<<12|(63&t[r++])<<6|63&t[r++])-65536,n+=String.fromCharCode(55296|e>>10,56320|1023&e)):n+=String.fromCharCode(1&i?(31&e)<<6|63&t[r++]:(15&e)<<12|(63&t[r++])<<6|63&t[r++]):n+=String.fromCharCode(e)}},_t=function(){function t(t){this.ondata=t,Xt?this.t=new TextDecoder:this.p=N}return t.prototype.push=function(t,r){if(this.ondata||I(5),r=!!r,this.t)return this.ondata(this.t.decode(t,{stream:!0}),r),void(r&&(this.t.decode().length&&I(8),this.t=null));this.p||I(4);var e=new n(this.p.length+t.length);e.set(this.p),e.set(t,this.p.length);var i=$t(e),o=i.s,s=i.r;r?(s.length&&I(8),this.p=null):this.p=s,this.ondata(o,r)},t}();_e.DecodeUTF8=_t;var tn=function(){function t(t){this.ondata=t}return t.prototype.push=function(t,n){this.ondata||I(5),this.d&&I(4),this.ondata(nn(t),this.d=n||!1)},t}();function nn(t,r){if(r){for(var e=new n(t.length),i=0;i>1)),a=0,u=function(t){s[a++]=t};for(i=0;is.length){var h=new n(a+8+(o-i<<1));h.set(s),s=h}var f=t.charCodeAt(i);f<128||r?u(f):f<2048?(u(192|f>>6),u(128|63&f)):f>55295&&f<57344?(u(240|(f=65536+(1047552&f)|1023&t.charCodeAt(++i))>>18),u(128|f>>12&63),u(128|f>>6&63),u(128|63&f)):(u(224|f>>12),u(128|f>>6&63),u(128|63&f))}return D(s,0,a)}function rn(t,n){if(n){for(var r="",e=0;e65535&&I(9),n+=e+4}return n},hn=function(t,n,r,e,i,o,s,a){var u=e.length,h=r.extra,f=a&&a.length,l=un(h);ct(t,n,null!=s?33639248:67324752),n+=4,null!=s&&(t[n++]=20,t[n++]=r.os),t[n]=20,n+=2,t[n++]=r.flag<<1|(o<0&&8),t[n++]=i&&8,t[n++]=255&r.compression,t[n++]=r.compression>>8;var c=new Date(null==r.mtime?Date.now():r.mtime),p=c.getFullYear()-1980;if((p<0||p>119)&&I(10),ct(t,n,p<<25|c.getMonth()+1<<21|c.getDate()<<16|c.getHours()<<11|c.getMinutes()<<5|c.getSeconds()>>1),n+=4,-1!=o&&(ct(t,n,r.crc),ct(t,n+4,o<0?-o-2:o),ct(t,n+8,r.size)),ct(t,n+12,u),ct(t,n+14,l),n+=16,null!=s&&(ct(t,n,f),ct(t,n+6,r.attrs),ct(t,n+10,s),n+=14),t.set(e,n),n+=u,l)for(var v in h){var d=h[v],g=d.length;ct(t,n,+v),ct(t,n+2,g),t.set(d,n+4),n+=4+g}return f&&(t.set(a,n),n+=f),n},fn=function(t,n,r,e,i){ct(t,n,101010256),ct(t,n+8,r),ct(t,n+10,r),ct(t,n+12,e),ct(t,n+16,i)},ln=function(){function t(t){this.filename=t,this.c=Y(),this.size=0,this.compression=0}return t.prototype.process=function(t,n){this.ondata(null,t,n)},t.prototype.push=function(t,n){this.ondata||I(5),this.c.p(t),this.size+=t.length,n&&(this.crc=this.c.d()),this.process(t,n||!1)},t}();_e.ZipPassThrough=ln;var cn=function(){function t(t,n){var r=this;n||(n={}),ln.call(this,t),this.d=new wt(n,(function(t,n){r.ondata(null,t,n)})),this.compression=8,this.flag=en(n.level)}return t.prototype.process=function(t,n){try{this.d.push(t,n)}catch(t){this.ondata(t,null,n)}},t.prototype.push=function(t,n){ln.prototype.push.call(this,t,n)},t}();_e.ZipDeflate=cn;var pn=function(){function t(t,n){var r=this;n||(n={}),ln.call(this,t),this.d=new xt(n,(function(t,n,e){r.ondata(t,n,e)})),this.compression=8,this.flag=en(n.level),this.terminate=this.d.terminate}return t.prototype.process=function(t,n){this.d.push(t,n)},t.prototype.push=function(t,n){ln.prototype.push.call(this,t,n)},t}();_e.AsyncZipDeflate=pn;var vn=function(){function t(t){this.ondata=t,this.u=[],this.d=1}return t.prototype.add=function(t){var r=this;if(this.ondata||I(5),2&this.d)this.ondata(I(4+8*(1&this.d),0,1),null,!1);else{var e=nn(t.filename),i=e.length,o=t.comment,s=o&&nn(o),a=i!=t.filename.length||s&&o.length!=s.length,u=i+un(t.extra)+30;i>65535&&this.ondata(I(11,0,1),null,!1);var h=new n(u);hn(h,0,t,e,a,-1);var f=[h],l=function(){for(var t=0,n=f;t65535&&M(I(11,0,1),null),k)if(g<16e4)try{M(null,kt(e,h))}catch(t){M(t,null)}else l.push(zt(e,h,M));else M(null,e)},g=0;g65535&&I(11);var y=l?kt(h,f):h,m=y.length,b=Y();b.p(h),i.push(Q(f,{size:h.length,crc:b.d(),c:y,f:M,m:v,u:c!=a.length||v&&p.length!=d,o:o,compression:l})),o+=30+c+g+m,s+=76+2*(c+g)+(d||0)+m}for(var w=new n(s+22),x=o,z=s-o,k=0;k0){var i=Math.min(this.c,t.length),o=t.subarray(0,i);if(this.c-=i,this.d?this.d.push(o,!this.c):this.k[0].push(o),(t=t.subarray(i)).length)return this.push(t,r)}else{var s=0,a=0,u=void 0,h=void 0;this.p.length?t.length?((h=new n(this.p.length+t.length)).set(this.p),h.set(t,this.p.length)):h=this.p:h=t;for(var f=h.length,l=this.c,c=l&&this.d,p=function(){var t,n=ft(h,a);if(67324752==n){s=1,u=a,v.d=null,v.c=0;var r=ht(h,a+6),i=ht(h,a+8),o=2048&r,c=8&r,p=ht(h,a+26),d=ht(h,a+28);if(f>a+30+p+d){var g=[];v.k.unshift(g),s=2;var y,m=ft(h,a+18),b=ft(h,a+22),w=rn(h.subarray(a+30,a+=30+p),!o);4294967295==m?(t=c?[-2]:an(h,a),m=t[0],b=t[1]):c&&(m=-1),a+=d,v.c=m;var x={name:w,compression:i,start:function(){if(x.ondata||I(5),m){var t=e.o[i];t||x.ondata(I(14,"unknown compression type "+i,1),null,!1),(y=m<0?new t(w):new t(w,m,b)).ondata=function(t,n,r){x.ondata(t,n,r)};for(var n=0,r=g;n=0&&(x.size=m,x.originalSize=b),v.onfile(x)}return"break"}if(l){if(134695760==n)return u=a+=12+(-2==l&&8),s=3,v.c=0,"break";if(33639248==n)return u=a-=4,s=3,v.c=0,"break"}},v=this;a65558)return a(I(13,0,1),null),o;var h=ht(t,u+8);if(h){var f=h,l=ft(t,u+16),c=4294967295==l||65535==f;if(c){var p=ft(t,u-12);(c=101075792==ft(t,p))&&(f=h=ft(t,p+32),l=ft(t,p+48))}for(var v=r&&r.filter,d=function(r){var e=sn(t,l,c),u=e[0],f=e[1],p=e[2],d=e[3],g=e[4],y=on(t,e[5]);l=g;var m=function(t,n){t?(o(),a(t,null)):(n&&(s[d]=n),--h||a(null,s))};if(!v||v({name:d,size:f,originalSize:p,compression:u}))if(u)if(8==u){var b=t.subarray(y,y+f);if(p<524288||f>.8*p)try{m(null,Tt(b,{out:new n(p)}))}catch(t){m(t,null)}else i.push(At(b,{size:p},m))}else m(I(14,"unknown compression type "+u,1),null);else m(null,D(t,y,y+f));else m(null,null)},g=0;g65558)&&I(13);var o=ht(t,i+8);if(!o)return{};var s=ft(t,i+16),a=4294967295==s||65535==o;if(a){var u=ft(t,i-12);(a=101075792==ft(t,u))&&(o=ft(t,u+32),s=ft(t,u+48))}for(var h=r&&r.filter,f=0;f({...item,type:112}))}); +assert.deepEqual(unknown.unsupportedTypes,[{collection:'animalGroup',type:112}]); +assert(unknown.errors.every(message=>message.includes('类型 112 未适配'))); for (const value of [null, {}, { ...source, size: { x: 65, y: 16 } }, { ...source, animalGroup: [{ ...source.animalGroup[0], type: 999 }] }, { ...source, animalGroup: [source.animalGroup[0], source.animalGroup[0]] }, { ...source, openMole: true }, { ...source, levelMode: 1 }, { ...source, cloudContainer: [1] }, { ...source, animalGroup: [{ ...source.animalGroup[0], boomTime: 3 }] }, { ...source, animalGroup: [{ ...source.animalGroup[0], angle: 12 }] }, { ...source, animalGroup: [{ ...source.animalGroup[0], position: { x: 100, y: 0 } }] }]) { const invalid = converter.convert(value); assert(!invalid.ok); assert.equal(invalid.layout, null); assert(invalid.errors.length); } console.log('转换测试通过:四方向、坐标、源数据不变、字段白名单、未知类型、重叠、越界、特殊玩法及附加参数拦截。'); +function animal(type = 'pig', d = 0) { + const sx = d % 2 ? 4 : 2, sy = d % 2 ? 2 : 4; + return { type, c: 2, r: 2, d, cells: Array.from({length:sx*sy}, (_,i)=>({c:2+i%sx,r:2+Math.floor(i/sx)})) }; +} +const cells = {cols:16,rows:16,placement:'explicit_cells',animals:[animal()],editor:{sourceLevel:{invalid:true}}}; +const snapshot = JSON.stringify(cells); +assert.deepEqual(converter.convert({...cells,animals:[animal('wolf')]}).unsupportedTypes,[{collection:'animals',type:'wolf'}]); +for(let d=0;d<4;d++) assert.deepEqual(converter.convert({...cells,animals:[animal('pig',d)]}).layout.characters[0],[1,1,1,[3,2,1,4][d]]); +assert.equal(JSON.stringify(cells),snapshot); +assert(converter.convert({...cells,animals:[{...animal('pigBomb'),bombNum:3}]}).ok); +assert(!converter.convert({...cells,animals:[{...animal('pigBomb'),bombNum:2}]}).ok); +const clock=converter.convert({...cells,animals:[{...animal('pigClock'),timerNum:60}]}); +assert(clock.ok);assert.equal(clock.layout.characters[0][4].addBuff[0].buffParam.duration,60); +for(const value of [{...cells,cols:15},{...cells,animals:[{...animal(),c:3}]},{...cells,animals:[animal('wolf')]},{...cells,animals:[{...animal(),patrolEndWorld:{x:1,z:2}}]},{...cells,animals:[{...animal(),cells:Array(8).fill({c:2,r:2})}]},{...cells,animals:[{...animal('pigClock'),timerNum:-1}]}]) assert(!converter.convert(value).ok); +const bundle={format:'zhuazhu-level-arrangement',version:1,slots:[{slotId:'b',key:'B:3'},{slotId:'a',key:'A:1'}],levels:{a:{...cells,animals:[]},b:cells}}; +const batch=converter.convertDocument(bundle); +assert.equal(batch.length,2);assert.equal(batch[0].sourceKey,'B:3');assert.equal(batch[0].layout.characters.length,1);assert.equal(batch[1].layout.characters.length,0); +assert.equal(converter.outputName('合集.json',batch[0]),'合集-第001关.json'); +assert(!converter.convertDocument({...bundle,slots:[{slotId:'missing'}]})[0].ok); +assert(!converter.convertDocument({...bundle,slots:[{slotId:'a'},{slotId:'a'}]})[1].ok); +assert.throws(()=>converter.convertDocument({...bundle,version:99})); +console.log('合集测试通过:当前布局优先、顺序、二倍格换算、炸弹参数、重复编排、缺失布局和未知类型拦截。'); diff --git a/抓猪关卡转换/piggy-converter/使用说明.md b/抓猪关卡转换/piggy-converter/使用说明.md index b1bea63..cafcb21 100644 --- a/抓猪关卡转换/piggy-converter/使用说明.md +++ b/抓猪关卡转换/piggy-converter/使用说明.md @@ -4,13 +4,32 @@ ## 网页使用 -双击 `转换工具.html`,选择一个或多个 Piggy Jam 关卡 JSON,点击“转换”。选择查看通过的文件,再下载当前单关 JSON;报告可以单独下载。原文件不会修改。 +双击 `转换工具.html`,选择一个或多个 Piggy Jam 单关 JSON,或抓猪编辑器导出的编排合集 JSON(例如“文字挪车——前20关.json”),点击“转换”。单文件上限为 32MB。选择查看通过的关卡,再下载当前单关 JSON;也可下载批量结果 ZIP。原文件不会修改。 + +ZIP 解压后包含通过的单关 JSON 和转换报告。失败关卡不会导出,也不会压缩后续关卡编号。请在本项目“主线编排 → 从单关 JSON 导入”中逐关插入;此 ZIP 不是项目配置包,不能直接覆盖项目目录或作为完整编辑器数据包导入。 + +## 选择文件夹批量转换 + +在“源关卡文件夹”选择 `D:\Downloads\piggy-jam-config\levels\A`,点击“转换”,完成后下载批量结果 ZIP。需要支持目录选择的浏览器,建议使用 Chrome 或 Edge。 + +文件夹模式递归读取 JSON,跳过非 JSON 文件及 `LevelInfoConfig.json`,按文件名中的数字排序。也可选择上一级 `levels`:ZIP 中保留 A、B 等子目录,避免同名关卡覆盖。单个 JSON 的选择入口仍然保留,两种选择以最后一次选择为准。 + +页面显示通过和未转换数量;未适配类型仍然会阻止对应关卡导出,详细原因见转换报告。选择文件夹不会修改源文件,也不会增加对特殊玩法的支持。 + +## 合集转换规则 + +- 支持 `format=zhuazhu-level-arrangement`、`version=1`,严格按 `slots` 顺序读取 `levels` 中的当前 `animals/cells`,不读取 `editor.sourceLevel` 的旧备份。 +- 每 2×2 源格合为 1 个目标格;坐标必须对齐,对象占格必须是完整矩形,不裁剪、不取整。`d=0/1/2/3` 暂按上/右/下/左解释,须与原工具画面对照验收。 +- 默认近似映射:`pig` → 普通箭、`pigBomb` → 爆破箭、`pigClock` → 计时箭、`duck` → 滚石、`bear` → 张飞。跨项目行为不保证等价。 +- 爆破次数只接受本项目支持的 3 次。计时时间写入对象附加参数,但模板中的 `boomTime` 和游戏难度上限仍可能覆盖最终时长。 +- 巡逻狼 `wolf` 及未识别的附加参数会阻止整关导出,不会静默删除或改成普通箭。真实游戏表现需导入后验证。 +- “源角度 0° 朝向”仅用于原始 Piggy Jam 数据;合集使用对象自身的 `d`。 得到的文件在本项目编辑器中可用于“导入布局 JSON”替换当前布局,也可在“主线编排 → 新增方式 → 从单关 JSON 导入”新增关卡。模板提供场景、难度、敌人和关卡级配置。 -## 转换边界 +## 原始 Piggy Jam 转换边界 -- 默认仅将 `animalGroup.type=1` 转换为普通箭矢,不擅自推断其他类型。未知类型会阻止整关导出,不跳过对象,不降级为普通箭。 +- 默认将 `animalGroup.type=1` 转换为普通箭矢,`type=100` 转换为爆破箭矢(参考编排合集对同一源类型的爆破猪映射;目标固定 3 次碰撞,需验收玩法)。其他未知类型会阻止整关导出,不跳过对象,不降级为普通箭。 - 当前坐标假设:`size` 是棋盘格数,`position` 是居中棋盘中的对象占格左下角,源坐标 Y 向上。坐标加半个棋盘尺寸得到目标锚点;不做取整、压缩或裁剪。此假设不是已确认的源游戏实现。 - 默认 0° 向上,90° 向右;可以调整零度朝向。此规则尚未从原游戏代码或运行画面确认,必须先对照原游戏检查一个上下左右均有对象的关卡,不能将批量通过理解为玩法等价。 - 映射规则中的 `length` 为沿朝向占格长度,`width` 为侧向宽度,必须与目标对象实际占格一致。工具不自带本项目完整对象目录,不能代替编辑器最终校验。 @@ -20,6 +39,14 @@ ## 自定义映射 +页面“源类型与目标对象”列出已知近似关系,每种源类型下面可通过下拉框选择本项目的军械或机关,或设为“未适配 / 不转换”。选择后同步更新映射 JSON,必须重新转换,旧下载结果会失效。转换中发现的未知类型也会加入列表,不会自动分配替代对象。 + +通过“新增映射”选择源分类、填写源类型、选择目标对象。原始单关源类型填写数字(如 `112`),合集源类型填写名称(如 `wolf`);同一分类内不允许重复新增。每条关系可删除,删除前会确认。删除的只是转换规则,不会修改原文件或跳过源对象;再次遇到该类型会提示未适配,并重新列入待适配列表。映射仅保留在当前页面,重新打开会恢复默认;需保留自定义规则时保存映射 JSON,后续粘贴到高级编辑框。 + +下拉框自动使用目标对象的分类及占格,不会自动迁移源对象的炸弹、路径等特殊参数。选择替代类型不是玩法等价承诺;参数或占格不兼容时仍然失败。页面同时保留高级 JSON 编辑入口。 + +失败时结果上方单独提示“112 类型未适配”或“wolf 类型未适配”;报告的 `unsupportedTypes` 记录去重后的源分类和类型,完整错误仍保留在 `errors` 中。 + 网页映射框可编辑,命令行可指定相同格式的 JSON 文件。键是源类型编号,`id` 是目标对象编号,`collection` 为 `characters` 或 `aoes`;可用 `extra` 配置固定目标附加参数。仅在确认源对象行为、大小和方向一致后添加映射。 ## 批量输出 @@ -32,6 +59,12 @@ node .\convert.mjs "D:\Downloads\piggy-jam-config\levels\A" "D:\Downloads\piggy- 输出目录必须尚不存在。目录模式只处理 `level数字.json`,自动跳过 `LevelInfoConfig.json`。成功文件逐个输出,失败文件不输出;详细原因写入 `转换报告.json`。部分失败时退出码为 2。 +也可直接将编排合集文件作为输入,自动按编排拆分: + +```powershell +node .\convert.mjs "D:\Downloads\文字挪车——前20关.json" "D:\Downloads\文字挪车-转换结果" +``` + ```powershell node .\convert.mjs "输入目录" "新建输出目录" "自定义映射.json" north ``` diff --git a/抓猪关卡转换/piggy-converter/压缩库许可证.txt b/抓猪关卡转换/piggy-converter/压缩库许可证.txt new file mode 100644 index 0000000..e84f0d6 --- /dev/null +++ b/抓猪关卡转换/piggy-converter/压缩库许可证.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Arjun Barrett + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/抓猪关卡转换/piggy-converter/转换工具.html b/抓猪关卡转换/piggy-converter/转换工具.html index 4b11d6a..8386f16 100644 --- a/抓猪关卡转换/piggy-converter/转换工具.html +++ b/抓猪关卡转换/piggy-converter/转换工具.html @@ -3,35 +3,147 @@ +

关卡 JSON 转换

+ +

未选择文件

+

源类型与目标对象

+
+ + + + +
+

+
+

默认近似对应:pig → 箭、pigBomb → 爆破箭矢、pigClock → 计时炸弹箭矢、duck → 滚石、bear → 张飞。原始单关仅默认支持 1 → 箭、100 → 爆破箭矢;不能与合集类型混用。跨项目行为不保证等价。爆破箭矢固定 3 次碰撞,计时时长可能受模板和难度上限影响。选择替换类型不会自动适配源对象的特殊参数;占格或参数不兼容时仍会失败。

- -

转换结果

未选择文件
-