Skip to content

Commit

Permalink
Minor fixes to costumes parsing 👗.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmarty committed Jun 5, 2024
1 parent 384c8fb commit 714f5cb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
3 changes: 0 additions & 3 deletions src/lib/parser/costumes/parseCostumes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const parseCostumes = (arrayBuffer, i = 0, offset = 0) => {
id: i,
offset,
size: arrayBuffer.byteLength,
decompressedSize: 0,
};

const costumes = [];
Expand All @@ -25,8 +24,6 @@ const parseCostumes = (arrayBuffer, i = 0, offset = 0) => {
costumes.push(costume);
}

metadata.decompressedSize = costumes.length;

const map = {
type: 'costumes',
from: offset,
Expand Down
10 changes: 5 additions & 5 deletions src/lib/parser/costumes/parseSprdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ 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 flip = sprdata0 & 0x80 ? true : false;
let y = sprdata0 & 0x7f;

const sprpal = (sprdata2 & 0x03) << 2;
const paletteId = (sprdata2 & 0x03) << 2;
let x = sprdata2 >> 2;

sprdata.push({
x,
y,
tile,
mask,
sprpal,
flip,
paletteId,
});
}

Expand Down
36 changes: 18 additions & 18 deletions src/lib/parser/parseRom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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++) {
Expand All @@ -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.
Expand Down Expand Up @@ -160,8 +160,8 @@ const parseRom = (arrayBuffer, res) => {
costumes,
sprpals,
sprdesc,
sprlens,
sproffs,
sprlens,
sprdata,
preps,
titles,
Expand Down

0 comments on commit 714f5cb

Please sign in to comment.