"""Crit puck flame trail (trail.s)."""
ORIGIN = 0x2E4000
TILES = 0x2E4200


def tile(rows):
    return bytes.fromhex(''.join(rows))


def tiles():
    # palette 1: A crit red, C orange, 6 yellow-orange (flame core)
    big = ['00AAAA00', '0ACCCCA0', 'AC6666CA', 'AC6666CA', 'AC6666CA', 'AC6666CA', '0ACCCCA0', '00AAAA00']
    mid = ['00000000', '00AAAA00', '0ACCCCA0', '0AC66CA0', '0AC66CA0', '0ACCCCA0', '00AAAA00', '00000000']
    small = ['00000000', '00000000', '000AA000', '00ACCA00', '00ACCA00', '000AA000', '00000000', '00000000']
    return tile(big) + tile(mid) + tile(small)


def install(data, assemble, patch):
    code = assemble('trail', ORIGIN)
    assert ORIGIN + len(code) <= TILES
    patch(ORIGIN, b'\xFF' * len(code), code)
    art = tiles()
    patch(TILES, b'\xFF' * len(art), art)
    patch(0x15F06, bytes.fromhex('bcfcc01866000006'), bytes.fromhex('4eb9002e40006604'))
