From eaf99e5e75a9ed9ebc7b5aff6dde46cc758604ec Mon Sep 17 00:00:00 2001 From: edo999 Date: Wed, 5 Jun 2024 18:37:33 +0100 Subject: [PATCH] =?UTF-8?q?Minor=20fixes=20to=20costumes=20parsing=20?= =?UTF-8?q?=F0=9F=91=97.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/parser/costumes/parseCostumes.js | 3 -- src/lib/parser/costumes/parseSprdata.js | 13 ++++----- src/lib/parser/parseRom.js | 36 ++++++++++++------------ 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/lib/parser/costumes/parseCostumes.js b/src/lib/parser/costumes/parseCostumes.js index d1aacc2..e755dd0 100644 --- a/src/lib/parser/costumes/parseCostumes.js +++ b/src/lib/parser/costumes/parseCostumes.js @@ -6,7 +6,6 @@ const parseCostumes = (arrayBuffer, i = 0, offset = 0) => { id: i, offset, size: arrayBuffer.byteLength, - decompressedSize: 0, }; const costumes = []; @@ -25,8 +24,6 @@ const parseCostumes = (arrayBuffer, i = 0, offset = 0) => { costumes.push(costume); } - metadata.decompressedSize = costumes.length; - const map = { type: 'costumes', from: offset, diff --git a/src/lib/parser/costumes/parseSprdata.js b/src/lib/parser/costumes/parseSprdata.js index 704c26a..156e624 100644 --- a/src/lib/parser/costumes/parseSprdata.js +++ b/src/lib/parser/costumes/parseSprdata.js @@ -15,18 +15,17 @@ const parseSprdata = (arrayBuffer, i = 0, offset = 0) => { const tile = parser.getUint8(); const sprdata2 = parser.getInt8(); - const mask = sprdata0 & 0x80 ? 0x01 : 0x80; - let y = (sprdata0 << 1) >> 1; - - const sprpal = (sprdata2 & 0x03) << 2; - let x = sprdata2 >> 2; + const x = sprdata2 >> 2; + const y = sprdata0 & 0x7f; + const flip = sprdata0 & 0x80 ? true : false; + const paletteId = (sprdata2 & 0x03) << 2; sprdata.push({ x, y, tile, - mask, - sprpal, + flip, + paletteId, }); } diff --git a/src/lib/parser/parseRom.js b/src/lib/parser/parseRom.js index 8432735..10cda01 100644 --- a/src/lib/parser/parseRom.js +++ b/src/lib/parser/parseRom.js @@ -21,8 +21,8 @@ const parseRom = (arrayBuffer, res) => { const costumes = []; const sprpals = []; const sprdesc = []; - const sprlens = []; const sproffs = []; + const sprlens = []; const sprdata = []; const preps = []; const titles = []; @@ -63,22 +63,22 @@ const parseRom = (arrayBuffer, res) => { scripts.push(item); } - for (let i = 0; i < res.costumes.length; i++) { - const [offset, length] = res.costumes[i]; + for (let i = 0; i < res.costumegfx.length; i++) { + const [offset, length] = res.costumegfx[i]; const buffer = arrayBuffer.slice(offset, offset + length); - const item = parseCostumes(buffer, i, offset); + const item = parseCostumeGfx(buffer, i, offset); item.buffer = buffer; - costumes.push(item); + costumegfx.push(item); } - for (let i = 0; i < res.costumegfx.length; i++) { - const [offset, length] = res.costumegfx[i]; + for (let i = 0; i < res.costumes.length; i++) { + const [offset, length] = res.costumes[i]; const buffer = arrayBuffer.slice(offset, offset + length); - const item = parseCostumeGfx(buffer, i, offset); + const item = parseCostumes(buffer, i, offset); item.buffer = buffer; - costumegfx.push(item); + costumes.push(item); } for (let i = 0; i < res.sprpals.length; i++) { @@ -99,22 +99,22 @@ const parseRom = (arrayBuffer, res) => { sprdesc.push(item); } - for (let i = 0; i < res.sprlens.length; i++) { - const [offset, length] = res.sprlens[i]; + for (let i = 0; i < res.sproffs.length; i++) { + const [offset, length] = res.sproffs[i]; const buffer = arrayBuffer.slice(offset, offset + length); - const item = parseSprlens(buffer, i, offset); + const item = parseSproffs(buffer, i, offset); item.buffer = buffer; - sprlens.push(item); + sproffs.push(item); } - for (let i = 0; i < res.sproffs.length; i++) { - const [offset, length] = res.sproffs[i]; + for (let i = 0; i < res.sprlens.length; i++) { + const [offset, length] = res.sprlens[i]; const buffer = arrayBuffer.slice(offset, offset + length); - const item = parseSproffs(buffer, i, offset); + const item = parseSprlens(buffer, i, offset); item.buffer = buffer; - sproffs.push(item); + sprlens.push(item); } // @todo Assert that the highest value of sprdesc is within sprlens and sproffs. @@ -160,8 +160,8 @@ const parseRom = (arrayBuffer, res) => { costumes, sprpals, sprdesc, - sprlens, sproffs, + sprlens, sprdata, preps, titles,