Exemplo n.º 1
0
def build_sheet(items):
    # No deduplication, since item ID corresponds directly to its position in
    # the sheet.
    num_pages, offsets = util.pack_boxes_uniform(SHEET_SIZE, len(items))
    assert num_pages == 1, 'too many item images to fit on one sheet'
    sheet, = util.build_sheets((i.image for i in items), offsets, 1, SHEET_SIZE, TILE_SIZE)
    return sheet
Exemplo n.º 2
0
def build_sheet(items):
    # No deduplication, since item ID corresponds directly to its position in
    # the sheet.
    num_pages, offsets = util.pack_boxes_uniform(SHEET_SIZE, len(items))
    assert num_pages == 1, 'too many item images to fit on one sheet'
    sheet, = util.build_sheets((i.image for i in items), offsets, 1,
                               SHEET_SIZE, TILE_SIZE)
    return sheet
Exemplo n.º 3
0
def build_sheet(blocks):
    """Build a sprite sheet containing all the tile images for the provided
    blocks.  This also updates each block's `tile_ids` field with its index in
    the generated sheet."""

    # Assign an index to each tile image.  Force a blank tile at index 0.
    blank_tile = Image.new('RGBA', (TILE_SIZE, TILE_SIZE))
    block_gen = (i for b in blocks for i in b.tiles.values() if i is not None)
    img_list, idx_map = util.dedupe_images(itertools.chain((blank_tile,), block_gen))

    # Compute `tile_ids`.
    for b in blocks:
        b.tile_ids = dict((k, idx_map[id(v)]) for k,v in b.tiles.items() if v is not None)

    # Construct the sheet image.
    num_pages, offsets = util.pack_boxes_uniform(SHEET_SIZE, len(img_list))
    assert num_pages == 1, 'too many tile images to fit on one sheet'
    sheet, = util.build_sheets(img_list, offsets, 1, SHEET_SIZE, TILE_SIZE)

    return sheet
Exemplo n.º 4
0
def build_sheet(blocks):
    """Build a sprite sheet containing all the tile images for the provided
    blocks.  This also updates each block's `tile_ids` field with its index in
    the generated sheet."""

    # Assign an index to each tile image.  Force a blank tile at index 0.
    blank_tile = Image.new('RGBA', (TILE_SIZE, TILE_SIZE))
    block_gen = (i for b in blocks for i in b.tiles.values() if i is not None)
    img_list, idx_map = util.dedupe_images(
        itertools.chain((blank_tile, ), block_gen))

    # Compute `tile_ids`.
    for b in blocks:
        b.tile_ids = dict(
            (k, idx_map[id(v)]) for k, v in b.tiles.items() if v is not None)

    # Construct the sheet image.
    num_pages, offsets = util.pack_boxes_uniform(SHEET_SIZE, len(img_list))
    assert num_pages == 1, 'too many tile images to fit on one sheet'
    sheet, = util.build_sheets(img_list, offsets, 1, SHEET_SIZE, TILE_SIZE)

    return sheet