Aeva / nw-converter

Parser and converter for the .nw level file format
GNU General Public License v3.0
8 stars 4 forks source link

support parsing data from .graal files #12

Open Aeva opened 7 years ago

Aeva commented 7 years ago

From poking around with a hex editor, the following is immediately apparent:

  1. the first 8 characters are always GR-V1.03
  2. tile data starts immediately after the version field
  3. the byte size of the entire level file can change if you change a singular tile, so it looks like there is some kind of compression scheme. A completely blank level is 226 bytes. If each tile in the level is different, the level is about ~6.7kb in size.
  4. chr(10) seems to maybe be used as a delimiter.
  5. the last ten bytes or so seem to be garbage (or maybe they're a checksum or section offsets, or something else)?

I found this page, which has some code that claims to be able to decode the level data, but in reading through it, it doesn't seem like it should work at all - only 3 bits are left over in each "code", which is very much not enough space for the actual sprite index. edit they're being clever with loops.

Perhaps the useful take-aways from that link are this:

  1. the format uses some form of run-length encoding scheme
  2. there is an alternating repeat mode
  3. the left-most bit activates repeating, some other bits determine count and how many
  4. the 1.0 version of the file format allotted 12 bits instead of 13bits per "code"

To take a wild guess, I think a plausible version of this is:

  1. read the first packet (12 or 13 bits depending on version)
  2. if the left-most bit is 0, then the remaining bytes describe a tile
  3. otherwise, the remaining bits describe the repeating behavior, and the packet or two are the tiles to be repeated.
Aeva commented 7 years ago

I started refactoring the project so that the .nw and .graal parsers all use a common base class (see issue #5).

I'm going to be continuing development on this in the "refactor" branch now, until it's mature enough to merge back into master. changes have been merged into master.

Aeva commented 7 years ago

The first 32 tiles parsed from the test map looks like this... seems... wrong :| 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 512, 513, 514, 3, 516, 517, 518, 519, 520, 521, 522, 11, 524, 525, 526, 527