-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [WIP] Parse the costumes. * Parse costume gfx. * Rename folder to costumes. * Remove debugs.
- Loading branch information
Showing
10 changed files
with
347 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import Parser from '../Parser.js'; | ||
|
||
const assert = console.assert; | ||
|
||
const parseCostumeGfx = (arrayBuffer, i = 0, offset = 0) => { | ||
const parser = new Parser(arrayBuffer); | ||
const metadata = { | ||
id: i, | ||
offset, | ||
size: arrayBuffer.byteLength, | ||
decompressedSize: 0, | ||
}; | ||
|
||
const numberOfTiles = parser.getUint8(); | ||
|
||
const gfx = []; | ||
while (parser.pointer < arrayBuffer.byteLength) { | ||
const loop = parser.getUint8(); | ||
if (loop & 0x80) { | ||
for (let j = 0; j < (loop & 0x7f); j++) { | ||
gfx.push(parser.getUint8()); | ||
} | ||
} else { | ||
const data = parser.getUint8(); | ||
for (let j = 0; j < (loop & 0x7f); j++) { | ||
gfx.push(data); | ||
} | ||
} | ||
} | ||
|
||
assert( | ||
numberOfTiles === gfx.length / 8 / 2, | ||
'Number of tiles byte does not match number of tiles decoded.', | ||
); | ||
|
||
metadata.decompressedSize = gfx.length; | ||
|
||
return { | ||
metadata, | ||
numberOfTiles, | ||
gfx, | ||
}; | ||
}; | ||
|
||
export default parseCostumeGfx; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import Parser from '../Parser.js'; | ||
|
||
const parseCostumes = (arrayBuffer, i = 0, offset = 0) => { | ||
const parser = new Parser(arrayBuffer); | ||
const metadata = { | ||
id: i, | ||
offset, | ||
size: arrayBuffer.byteLength, | ||
decompressedSize: 0, | ||
}; | ||
|
||
const costumes = []; | ||
let to = 0; | ||
for (let i = 0; i < 24; i++) { | ||
const offset = parser.getUint8(); | ||
const length = parser.getUint8(); | ||
const costumeParser = new Parser( | ||
arrayBuffer.slice(offset, offset + length), | ||
); | ||
to = Math.max(to, offset + length); | ||
const costume = []; | ||
for (let j = 0; j < length; j++) { | ||
costume.push(costumeParser.getUint8()); | ||
} | ||
costumes.push(costume); | ||
} | ||
|
||
metadata.decompressedSize = costumes.length; | ||
|
||
const map = { | ||
type: 'costumes', | ||
from: offset, | ||
to: offset + to, | ||
}; | ||
|
||
return { | ||
metadata, | ||
costumes, | ||
map, | ||
}; | ||
}; | ||
|
||
export default parseCostumes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Parser from '../Parser.js'; | ||
|
||
const parseSprdata = (arrayBuffer, i = 0, offset = 0) => { | ||
const parser = new Parser(arrayBuffer); | ||
const metadata = { | ||
id: i, | ||
offset, | ||
size: arrayBuffer.byteLength, | ||
decompressedSize: 0, | ||
}; | ||
|
||
const sprdata = []; | ||
for (let i = 0; i < arrayBuffer.byteLength; i += 3) { | ||
const sprdata0 = parser.getInt8(); | ||
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; | ||
|
||
sprdata.push({ | ||
x, | ||
y, | ||
tile, | ||
mask, | ||
sprpal, | ||
}); | ||
} | ||
|
||
metadata.decompressedSize = sprdata.length; | ||
|
||
const map = { | ||
type: 'sprdata', | ||
from: offset, | ||
to: offset + parser.pointer, | ||
}; | ||
|
||
return { | ||
metadata, | ||
sprdata, | ||
map, | ||
}; | ||
}; | ||
|
||
export default parseSprdata; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import Parser from '../Parser.js'; | ||
|
||
const parseSprdesc = (arrayBuffer, i = 0, offset = 0) => { | ||
const parser = new Parser(arrayBuffer); | ||
const metadata = { | ||
id: i, | ||
offset, | ||
size: arrayBuffer.byteLength, | ||
}; | ||
|
||
const sprdesc = []; | ||
for (let i = 0; i < arrayBuffer.byteLength - 1; i += 2) { | ||
sprdesc.push(parser.getUint16()); | ||
} | ||
|
||
// For some reason, the last element is a Uint8, probably unused. | ||
sprdesc.push(parser.getUint8()); | ||
|
||
const map = { | ||
type: 'sprdesc', | ||
from: offset, | ||
to: offset + parser.pointer, | ||
}; | ||
|
||
return { | ||
metadata, | ||
sprdesc, | ||
map, | ||
}; | ||
}; | ||
|
||
export default parseSprdesc; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Parser from '../Parser.js'; | ||
|
||
const parseSprlens = (arrayBuffer, i = 0, offset = 0) => { | ||
const parser = new Parser(arrayBuffer); | ||
const metadata = { | ||
id: i, | ||
offset, | ||
size: arrayBuffer.byteLength, | ||
}; | ||
|
||
const sprlens = []; | ||
for (let i = 0; i < arrayBuffer.byteLength; i++) { | ||
sprlens.push(parser.getUint8() + 1); | ||
} | ||
|
||
const map = { | ||
type: 'sprlens', | ||
from: offset, | ||
to: offset + parser.pointer, | ||
}; | ||
|
||
return { | ||
metadata, | ||
sprlens, | ||
map, | ||
}; | ||
}; | ||
|
||
export default parseSprlens; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Parser from '../Parser.js'; | ||
|
||
const parseSproffs = (arrayBuffer, i = 0, offset = 0) => { | ||
const parser = new Parser(arrayBuffer); | ||
const metadata = { | ||
id: i, | ||
offset, | ||
size: arrayBuffer.byteLength, | ||
}; | ||
|
||
const sproffs = []; | ||
for (let i = 0; i < arrayBuffer.byteLength; i += 2) { | ||
sproffs.push(parser.getUint16()); | ||
} | ||
|
||
const map = { | ||
type: 'sproffs', | ||
from: offset, | ||
to: offset + parser.pointer, | ||
}; | ||
|
||
return { | ||
metadata, | ||
sproffs, | ||
map, | ||
}; | ||
}; | ||
|
||
export default parseSproffs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import parsePalette from '../parsePalette.js'; | ||
|
||
const parseSprpals = (arrayBuffer, i = 0, offset = 0) => { | ||
const metadata = { | ||
id: i, | ||
offset, | ||
size: arrayBuffer.byteLength, | ||
}; | ||
const map = []; | ||
|
||
const { palette, paletteMap } = parsePalette(arrayBuffer, offset); | ||
|
||
map.push(paletteMap); | ||
|
||
return { | ||
metadata, | ||
palette, | ||
map, | ||
}; | ||
}; | ||
|
||
export default parseSprpals; |
Oops, something went wrong.