Example #1
0
def main(level_header, out):
    out.write("%d %d\n" % (level_header.width, level_header.height))

    tilemap_data = decompress_data(chunk.read_chunk(level_header.tilemap_chunk))

    for row in take_n(tilemap_data, level_header.width * 2):
        out.write(' '.join(str(read_word(row, i)) for i in xrange(0, len(row), 2)))
        out.write('\n')
Example #2
0
def main(level_header, out):
    out.write("%d %d\n" % (level_header.width, level_header.height))

    tilemap_data = decompress_data(chunk.read_chunk(
        level_header.tilemap_chunk))

    for row in take_n(tilemap_data, level_header.width * 2):
        out.write(' '.join(
            str(read_word(row, i)) for i in xrange(0, len(row), 2)))
        out.write('\n')
Example #3
0
def extract_tiles(level_header):
    tileset_data = decompress_data(chunk.read_chunk(level_header.tileset_chunk + 1))

    expanded = array('B')
    for byte in tileset_data:
        for bit in xrange(8):
            expanded.append((byte & 0x80) and 1 or 0)
            byte <<= 1

    return graphics.interleave_tileset(expanded)
Example #4
0
def extract_frames(chunk_id, offset, count, size):
    frames = []
    frame_len = calc_frame_length(size)
    sprite_data = compression.decompress_data(chunk.read_chunk(chunk_id))
    if count == -1:
        count = len(sprite_data) / frame_len
    data_size = frame_len * count
    sprite_data = sprite_data[offset:offset + data_size]
    for offs in xrange(0, data_size, frame_len):
        frames.append(extract_frame(sprite_data[offs:offs + frame_len], size))
    return frames
def extract_tiles(level_header):
    tileset_data = decompress_data(
        chunk.read_chunk(level_header.tileset_chunk + 1))

    expanded = array('B')
    for byte in tileset_data:
        for bit in xrange(8):
            expanded.append((byte & 0x80) and 1 or 0)
            byte <<= 1

    return graphics.interleave_tileset(expanded)
Example #6
0
def extract_frames(chunk_id, offset, count, size):
    frames = []
    frame_len = calc_frame_length(size)
    sprite_data = compression.decompress_data(chunk.read_chunk(chunk_id))
    if count == -1:
        count = len(sprite_data) / frame_len
    data_size = frame_len * count
    sprite_data = sprite_data[offset:offset+data_size]
    for offs in xrange(0, data_size, frame_len):
        frames.append(extract_frame(sprite_data[offs:offs+frame_len], size))
    return frames
Example #7
0
def main(level_header, output_file, tiles_per_row):
    output_pal = palette.assemble_palette(level_header.load_list.palettes)
    tiles = tileset.extract_tiles(level_header)

    metatile_data = decompress_data(chunk.read_chunk(level_header.metatile_chunk))
    meta_info = parse_metatile_info(metatile_data)
    del metatile_data

    def assemble_metatile(info):
        flipped_tiles = [graphics.flip_image(tiles[i], 8, hf, vf) for i, hf, vf in info]
        return graphics.layout_tiles(flipped_tiles, 8, 8, [[0, 1], [2, 3]])[0]

    meta_imgs = [assemble_metatile(info) for info in meta_info]

    output_data, output_w, output_h = graphics.layout_tiles(meta_imgs, 16, 16, tileset.rows_of_tiles(len(meta_imgs), tiles_per_row))

    with open(output_file, 'wb') as f:
        w = png.Writer(output_w, output_h, palette=output_pal)
        w.write_array(f, output_data)
Example #8
0
def extract_tiles(level_header):
    tileset_data = decompress_data(chunk.read_chunk(level_header.tileset_chunk))
    return graphics.interleave_tileset(tileset_data)
Example #9
0
 def decomp(chunk_id):
     return decompress_data(chunk.read_chunk(chunk_id))
Example #10
0
 def decomp(chunk_id):
     return decompress_data(chunk.read_chunk(chunk_id))
Example #11
0
import sys

import lvtools.chunk as chunk
from lvtools.compression import decompress_data
from lvtools.level import LevelHeader

level_header_id = int(sys.argv[1], 0)

header_data = decompress_data(chunk.read_chunk(level_header_id))
header = LevelHeader()
header.load(header_data)
print header