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')
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')
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)
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)
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 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)
def extract_tiles(level_header): tileset_data = decompress_data(chunk.read_chunk(level_header.tileset_chunk)) return graphics.interleave_tileset(tileset_data)
def decomp(chunk_id): return decompress_data(chunk.read_chunk(chunk_id))
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