def test_read_1bpp_graphic_from_block_rectangular_tall(): source = Block() source.from_list([ 42, 11, 99, 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010, 0b11001000, 0b01110001, 0b00000001, 0b00100000, 0b00110000, 0b00101000, 0b00101000, 0b01100000, 0b11100000, 0b11000000, 0b00000001, 12, 21 ]) target = [[0 for x in range(8)] for y in range(16)] assert_equal( 16, read_1bpp_graphic_from_block(source, target, 3, x=0, y=0, height=16)) assert_list_equal(target, [[0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 0, 0], [0, 1, 1, 1, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0], [0, 1, 1, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1]])
def test_from_block(self): block = Block() block.from_list([0x5f, 0x0a]) self.color.from_block(block, 0) assert_equal(self.color.r, 248) assert_equal(self.color.g, 144) assert_equal(self.color.b, 16)
def test_from_block(self): block = Block() block.from_list([0, 0, 37, 36, 106, 25, 31, 0, 234, 20, 34, 70]) self.palette.from_block(block) assert_list_equal(self.palette.list(), [ 0, 0, 0, 40, 8, 72, 80, 88, 48, 248, 0, 0, 80, 56, 40, 16, 136, 136 ])
def test_standard_text_to_block_with_brackets_not_two_digits(): b = Block() b.from_list([0] * 10) standard_text_to_block(block=b, offset=0, text="[1 02 03 04]", max_length=10)
def test_standard_text_to_block_too_long(): b = Block() b.from_list([0] * 10) standard_text_to_block(block=b, offset=0, text="12345678901", max_length=10)
def test_from_block_1bpp_out_of_bounds(self): block = Block() block.from_list([ 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010, 0b11001000, 0b01110001, 0b00000001, 0b00100000, 0b00110000, 0b00101000, 0b00101000, 0b01100000, 0b11100000, 0b11000000, 0b00000001 ]) tileset = EbGraphicTileset(num_tiles=3, tile_width=8, tile_height=8) tileset.from_block(block, offset=0, bpp=1) assert_list_equal(tileset[0], [[0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 0, 0], [0, 1, 1, 1, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1]]) assert_list_equal(tileset[1], [[0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0], [0, 1, 1, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1]]) assert_list_equal(tileset[2], [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]])
def test_standard_text_to_block_with_brackets_too_long2(): b = Block() b.from_list([0] * 10) standard_text_to_block(block=b, offset=0, text="abcd[01 02 03 04 05 06 07]", max_length=10)
def test_write_2bpp_graphic_to_block(): source = [[2, 1, 2, 3, 2, 1, 2, 1], [2, 3, 1, 0, 2, 3, 2, 2], [3, 0, 3, 2, 2, 2, 0, 2], [1, 3, 3, 0, 2, 0, 2, 3], [1, 0, 1, 1, 0, 3, 3, 3], [1, 3, 3, 3, 3, 2, 1, 2], [2, 2, 3, 1, 2, 2, 1, 0], [2, 0, 3, 3, 2, 3, 1, 0]] target = Block() target.from_list([0] * 16) assert_equal(16, write_2bpp_graphic_to_block(source=source, target=target, offset=0, x=0, y=0, bit_offset=0)) assert_list_equal(target.to_list(), [0b01010101, 0b10111010, 0b01100100, 0b11001111, 0b10100000, 0b10111101, 0b11100001, 0b01101011, 0b10110111, 0b00000111, 0b11111010, 0b01111101, 0b00110010, 0b11101100, 0b00110110, 0b10111100])
def test_read_2bpp_graphic_from_block_offset_xy(): source = Block() source.from_list([0b01010101, 0b10111010, 0b01100100, 0b11001111, 0b10100000, 0b10111101, 0b11100001, 0b01101011, 0b10110111, 0b00000111, 0b11111010, 0b01111101, 0b00110010, 0b11101100, 0b00110110, 0b10111100, 5]) target = [[0 for x in range(10)] for y in range(10)] assert_equal(16, read_2bpp_graphic_from_block(target=target, source=source, offset=0, x=2, y=1, bit_offset=0)) assert_list_equal(target, [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 1, 2, 3, 2, 1, 2, 1], [0, 0, 2, 3, 1, 0, 2, 3, 2, 2], [0, 0, 3, 0, 3, 2, 2, 2, 0, 2], [0, 0, 1, 3, 3, 0, 2, 0, 2, 3], [0, 0, 1, 0, 1, 1, 0, 3, 3, 3], [0, 0, 1, 3, 3, 3, 3, 2, 1, 2], [0, 0, 2, 2, 3, 1, 2, 2, 1, 0], [0, 0, 2, 0, 3, 3, 2, 3, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
def test_to_block(self): block = Block() block.from_list(range(1, 6)) self.pointer.address = 0xabcdef self.pointer.to_block(block, 1) assert_list_equal(block[0:5].to_list(), [1, 0xef, 0xcd, 0xab, 5])
def test_write_2bpp_graphic_to_block_offset_xy(): source = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 1, 2, 3, 2, 1, 2, 1], [0, 0, 2, 3, 1, 0, 2, 3, 2, 2], [0, 0, 3, 0, 3, 2, 2, 2, 0, 2], [0, 0, 1, 3, 3, 0, 2, 0, 2, 3], [0, 0, 1, 0, 1, 1, 0, 3, 3, 3], [0, 0, 1, 3, 3, 3, 3, 2, 1, 2], [0, 0, 2, 2, 3, 1, 2, 2, 1, 0], [0, 0, 2, 0, 3, 3, 2, 3, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] target = Block() target.from_list([0xff] * 18) assert_equal(16, write_2bpp_graphic_to_block(source=source, target=target, offset=1, x=2, y=1, bit_offset=0)) assert_list_equal(target.to_list(), [0xff, 0b01010101, 0b10111010, 0b01100100, 0b11001111, 0b10100000, 0b10111101, 0b11100001, 0b01101011, 0b10110111, 0b00000111, 0b11111010, 0b01111101, 0b00110010, 0b11101100, 0b00110110, 0b10111100, 0xff])
def test_read_4bpp_graphic_from_block(): source = Block() source.from_list([0b01010110, 0b00001011, 0b11001110, 0b10010110, 0b01110001, 0b00111011, 0b00001011, 0b10011110, 0b00011000, 0b00000011, 0b10000001, 0b11101011, 0b00000100, 0b01000101, 0b01010110, 0b10001111, 0b00101100, 0b10110000, 0b01010110, 0b10110010, 0b01010000, 0b11000000, 0b00111000, 0b10010111, 0b00101101, 0b11111100, 0b01111101, 0b11101010, 0b10101111, 0b10110111, 0b01100000, 0b11101110]) target = [[0 for x in range(8)] for y in range(8)] assert_equal(32, read_4bpp_graphic_from_block(target=target, source=source, offset=0, x=0, y=0, bit_offset=0)) assert_list_equal(target, [[8, 1, 12, 9, 6, 5, 3, 2], [11, 5, 8, 14, 1, 7, 15, 0], [8, 13, 3, 7, 2, 0, 2, 3], [10, 0, 4, 14, 7, 10, 11, 9], [8, 8, 12, 9, 13, 12, 2, 6], [11, 14, 14, 4, 14, 4, 10, 7], [12, 2, 12, 8, 4, 15, 12, 14], [10, 13, 12, 1, 10, 11, 11, 2]])
def test_read_4bpp_graphic_from_block(): source = Block() source.from_list([ 0b01010110, 0b00001011, 0b11001110, 0b10010110, 0b01110001, 0b00111011, 0b00001011, 0b10011110, 0b00011000, 0b00000011, 0b10000001, 0b11101011, 0b00000100, 0b01000101, 0b01010110, 0b10001111, 0b00101100, 0b10110000, 0b01010110, 0b10110010, 0b01010000, 0b11000000, 0b00111000, 0b10010111, 0b00101101, 0b11111100, 0b01111101, 0b11101010, 0b10101111, 0b10110111, 0b01100000, 0b11101110 ]) target = [[0 for x in range(8)] for y in range(8)] assert_equal( 32, read_4bpp_graphic_from_block(target=target, source=source, offset=0, x=0, y=0, bit_offset=0)) assert_list_equal( target, [[8, 1, 12, 9, 6, 5, 3, 2], [11, 5, 8, 14, 1, 7, 15, 0], [8, 13, 3, 7, 2, 0, 2, 3], [10, 0, 4, 14, 7, 10, 11, 9], [8, 8, 12, 9, 13, 12, 2, 6], [11, 14, 14, 4, 14, 4, 10, 7], [12, 2, 12, 8, 4, 15, 12, 14], [10, 13, 12, 1, 10, 11, 11, 2]])
def test_to_block(self): block = Block() block.from_list([0] * 2) self.color.r = 248 self.color.g = 144 self.color.b = 16 self.color.to_block(block, 0) assert_list_equal(block.to_list(), [0x5f, 0x0a])
def test_from_block(self): table = Table(num_rows=len(self.TABLE_VALUES), schema=self.TABLE_SCHEMA) block = Block() block.from_list(self.BLOCK_DATA) table.from_block(block, 0) assert_list_equal(table.values, self.TABLE_VALUES)
def test_to_block(self): for test_case in TEST_CASES: block_size = MapEnemyGroupTableEntry.to_block_size(test_case["value_rep"]) assert_equal(len(test_case["block_rep"]), block_size) block = Block(size=block_size) MapEnemyGroupTableEntry.to_block(block, 0, test_case["value_rep"]) assert_list_equal(test_case["block_rep"], block.to_list())
def test_to_block(self): block = Block() block.from_list([0] * len(self.BLOCK_DATA)) table = Table(num_rows=len(self.TABLE_VALUES), schema=self.TABLE_SCHEMA) table.values = self.TABLE_VALUES table.to_block(block, 0) assert_list_equal(block.to_list(), self.BLOCK_DATA)
def test_to_block(self): for test_case in TEST_CASES: block_size = MapEnemyGroupTableEntry.to_block_size( test_case["value_rep"]) assert_equal(len(test_case["block_rep"]), block_size) block = Block(size=block_size) MapEnemyGroupTableEntry.to_block(block, 0, test_case["value_rep"]) assert_list_equal(test_case["block_rep"], block.to_list())
def test_to_block(self): self.palette.from_list([ 0, 0, 0, 40, 8, 72, 80, 88, 48, 248, 0, 0, 80, 56, 40, 16, 136, 136 ]) block = Block() block.from_list([0xff] * 50) self.palette.to_block(block, offset=1) assert_list_equal(block[0:14].to_list(), [0xff, 0, 0, 37, 36, 106, 25, 31, 0, 234, 20, 34, 70, 0xff])
def test_from_block(self): block = Block() block.from_list([1, 2, 4, 5, 6]) s = SwirlFrameRow() s.from_block(block, 0, False) assert_equal(SwirlFrameRow(x1=1, x2=2, x3=4, x4=5), s) s.from_block(block, 3, True) assert_equal(SwirlFrameRow(x1=5, x2=6, x3=0xff, x4=0), s)
def test_to_block(self): self.palette.from_list([ 0, 0, 0, 40, 8, 72, 80, 88, 48, 248, 0, 0, 80, 56, 40, 16, 136, 136 ]) block = Block() block.from_list([0xff] * 50) self.palette.to_block(block, offset=1) assert_list_equal( block[0:14].to_list(), [0xff, 0, 0, 37, 36, 106, 25, 31, 0, 234, 20, 34, 70, 0xff])
def test_from_block(self): block = Block() block.from_list(range(0, 0x100)) self.pointer.from_block(block, 0) assert_equal(self.pointer.address, 0x020100) self.pointer.from_block(block, 5) assert_equal(self.pointer.address, 0x070605) self.pointer.from_block(block, 0xfd) assert_equal(self.pointer.address, 0xfffefd)
def test_from_block_repeating_not_mode_01(self): s = SwirlFrame() block = Block() block.from_list([0, 0x7e, 0, 50, 120, 126, 98, 0, 0xff, 0xff, 0, 0]) s.from_block(block, 0) assert_equal(len(s.rows), 224) for row in s.rows[0:0x7e]: assert_equal(SwirlFrameRow(x1=0, x2=50, x3=120, x4=126), row) for row in s.rows[0x7e:]: assert_equal(SwirlFrameRow(x1=0, x2=0xff, x3=0xff, x4=0), row)
def test_from_block_repeating_mode_01(self): s = SwirlFrame() block = Block() block.from_list([1, 0x7f, 1, 2, 97, 3, 4, 0]) s.from_block(block, 0) assert_equal(len(s.rows), 224) for row in s.rows[0:0x7f]: assert_equal(SwirlFrameRow(x1=1, x2=2, x3=0xff, x4=0), row) for row in s.rows[0x7f:]: assert_equal(SwirlFrameRow(x1=3, x2=4, x3=0xff, x4=0), row)
def test_to_block_4bpp(self): tileset = EbGraphicTileset(num_tiles=1, tile_width=8, tile_height=8) tileset.tiles = [None] tileset.tiles[0] = [ [8, 1, 12, 9, 6, 5, 3, 2], [11, 5, 8, 14, 1, 7, 15, 0], [8, 13, 3, 7, 2, 0, 2, 3], [10, 0, 4, 14, 7, 10, 11, 9], [8, 8, 12, 9, 13, 12, 2, 6], [11, 14, 14, 4, 14, 4, 10, 7], [12, 2, 12, 8, 4, 15, 12, 14], [10, 13, 12, 1, 10, 11, 11, 2], ] block = Block() block.from_list([0] * 32) tileset.to_block(block, 0, 4) assert_list_equal( block.to_list(), [ 0b01010110, 0b00001011, 0b11001110, 0b10010110, 0b01110001, 0b00111011, 0b00001011, 0b10011110, 0b00011000, 0b00000011, 0b10000001, 0b11101011, 0b00000100, 0b01000101, 0b01010110, 0b10001111, 0b00101100, 0b10110000, 0b01010110, 0b10110010, 0b01010000, 0b11000000, 0b00111000, 0b10010111, 0b00101101, 0b11111100, 0b01111101, 0b11101010, 0b10101111, 0b10110111, 0b01100000, 0b11101110, ], )
def test_from_block_4bpp(self): block = Block() block.from_list( [ 0b01010110, 0b00001011, 0b11001110, 0b10010110, 0b01110001, 0b00111011, 0b00001011, 0b10011110, 0b00011000, 0b00000011, 0b10000001, 0b11101011, 0b00000100, 0b01000101, 0b01010110, 0b10001111, 0b00101100, 0b10110000, 0b01010110, 0b10110010, 0b01010000, 0b11000000, 0b00111000, 0b10010111, 0b00101101, 0b11111100, 0b01111101, 0b11101010, 0b10101111, 0b10110111, 0b01100000, 0b11101110, ] ) tileset = EbGraphicTileset(num_tiles=1, tile_width=8, tile_height=8) tileset.from_block(block, offset=0, bpp=4) assert_list_equal( tileset[0], [ [8, 1, 12, 9, 6, 5, 3, 2], [11, 5, 8, 14, 1, 7, 15, 0], [8, 13, 3, 7, 2, 0, 2, 3], [10, 0, 4, 14, 7, 10, 11, 9], [8, 8, 12, 9, 13, 12, 2, 6], [11, 14, 14, 4, 14, 4, 10, 7], [12, 2, 12, 8, 4, 15, 12, 14], [10, 13, 12, 1, 10, 11, 11, 2], ], )
def test_from_block_continuous_mode_01(self): s = SwirlFrame() block = Block() block.from_list([1, 0x7f, 1, 2, 0x82, 50, 51, 52, 53, 95, 3, 4, 0]) s.from_block(block, 0) assert_equal(len(s.rows), 224) for row in s.rows[0:0x7f]: assert_equal(SwirlFrameRow(x1=1, x2=2, x3=0xff, x4=0), row) assert_equal(SwirlFrameRow(x1=50, x2=51, x3=0xff, x4=0), s.rows[0x7f]) assert_equal(SwirlFrameRow(x1=52, x2=53, x3=0xff, x4=0), s.rows[0x80]) for row in s.rows[0x81:]: assert_equal(SwirlFrameRow(x1=3, x2=4, x3=0xff, x4=0), row)
def test_write_1bpp_graphic_to_block(): source = [[0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 0, 0], [0, 1, 1, 1, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1]] target = Block() target.from_list([32] * 10) assert_equal( 8, write_1bpp_graphic_to_block(source, target, 1, x=0, y=0, height=8)) assert_list_equal(target.to_list(), [ 32, 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010, 0b11001000, 0b01110001, 0b00000001, 32 ])
def test_write_1bpp_graphic_to_block_rectangular_short(): source = [[0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 0, 0]] target = Block() target.from_list([0xeb] * 8) target[0] = 42 assert_equal( 6, write_1bpp_graphic_to_block(source, target, 2, x=0, y=0, height=6)) assert_list_equal(target.to_list(), [ 42, 0xeb, 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010, 0b11001000 ])
def test_standard_text_to_block_with_brackets(): b = Block() b.from_list([0] * 10) standard_text_to_block(block=b, offset=0, text="[01 02 03 04]", max_length=10) assert_list_equal(b.to_list(), [0x01, 0x02, 0x03, 0x04, 0, 0, 0, 0, 0, 0]) b.from_list([0] * 10) standard_text_to_block(block=b, offset=0, text="[]", max_length=10) assert_list_equal(b.to_list(), [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) b.from_list([0] * 10) standard_text_to_block(block=b, offset=0, text="Te[ab cd ef]st", max_length=10) assert_list_equal(b.to_list(), [132, 149, 0xab, 0xcd, 0xef, 163, 164, 0, 0, 0])
def test_read_1bpp_graphic_from_block_rectangular_short(): source = Block() source.from_list([ 42, 0xeb, 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010, 0b11001000 ]) target = [[0 for x in range(8)] for y in range(6)] assert_equal( 6, read_1bpp_graphic_from_block(source, target, 2, x=0, y=0, height=6)) assert_list_equal(target, [[0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 0, 0]])
def test_from_block_1bpp(self): block = Block() block.from_list( [ 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010, 0b11001000, 0b01110001, 0b00000001, 0b00100000, 0b00110000, 0b00101000, 0b00101000, 0b01100000, 0b11100000, 0b11000000, 0b00000001, ] ) tileset = EbGraphicTileset(num_tiles=2, tile_width=8, tile_height=8) tileset.from_block(block, offset=0, bpp=1) assert_list_equal( tileset[0], [ [0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 0, 0], [0, 1, 1, 1, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1], ], ) assert_list_equal( tileset[1], [ [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0], [0, 1, 1, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1], ], )
def test_from_block(self): block = Block() block.from_list([1] * 5) block.write_multi(1, 0x8000 | 0x2000 | (7 << 10) | 0x120, 2) block.write_multi(3, 0x4000 | (2 << 10) | 0x3f5, 2) arrangement = EbTileArrangement(2, 1) arrangement.from_block(block, 1) assert_true(arrangement[0, 0].is_vertically_flipped) assert_false(arrangement[0, 0].is_horizontally_flipped) assert_true(arrangement[0, 0].is_priority, True) assert_equal(arrangement[0, 0].subpalette, 7) assert_equal(arrangement[0, 0].tile, 0x120) assert_false(arrangement[1, 0].is_vertically_flipped) assert_true(arrangement[1, 0].is_horizontally_flipped) assert_false(arrangement[1, 0].is_priority) assert_equal(arrangement[1, 0].subpalette, 2) assert_equal(arrangement[1, 0].tile, 0x3f5) arrangement = EbTileArrangement(1, 2) arrangement.from_block(block, 1) assert_true(arrangement[0, 0].is_vertically_flipped) assert_false(arrangement[0, 0].is_horizontally_flipped) assert_true(arrangement[0, 0].is_priority, True) assert_equal(arrangement[0, 0].subpalette, 7) assert_equal(arrangement[0, 0].tile, 0x120) assert_false(arrangement[0, 1].is_vertically_flipped) assert_true(arrangement[0, 1].is_horizontally_flipped) assert_false(arrangement[0, 1].is_priority) assert_equal(arrangement[0, 1].subpalette, 2) assert_equal(arrangement[0, 1].tile, 0x3f5)
def test_from_block(self): block = Block() block.from_list([0xc0, 0xc1, 0xc2, 0x00, 0xff, 0xff, 0xff, 0x00, 0xef, 0xfe, 0x02, 0x00, 0x01, 0x02, 0x03, 0x01]) self.pointer.from_block(block, 0) assert_equal(self.pointer.address, 0xc2c1c0) self.pointer.from_block(block, 4) assert_equal(self.pointer.address, 0xffffff) assert_raises(InvalidEbTextPointerError, self.pointer.from_block, block, 8) assert_raises(InvalidEbTextPointerError, self.pointer.from_block, block, 12)
def test_write_1bpp_graphic_to_block_offset_source(): source = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 1], [0, 0, 0, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0, 0, 1], [0, 0, 1, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0, 1, 0], [0, 0, 1, 1, 0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] target = Block() target.from_list([0] * 8) assert_equal( 8, write_1bpp_graphic_to_block(source, target, 0, x=2, y=1, height=8)) assert_list_equal(target.to_list(), [ 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010, 0b11001000, 0b01110001, 0b00000001 ])
def test_to_block_2bpp(self): tileset = EbGraphicTileset(num_tiles=2, tile_width=8, tile_height=8) tileset.tiles = [None, None] tileset.tiles[0] = [[2, 1, 2, 3, 2, 1, 2, 1], [2, 3, 1, 0, 2, 3, 2, 2], [3, 0, 3, 2, 2, 2, 0, 2], [1, 3, 3, 0, 2, 0, 2, 3], [1, 0, 1, 1, 0, 3, 3, 3], [1, 3, 3, 3, 3, 2, 1, 2], [2, 2, 3, 1, 2, 2, 1, 0], [2, 0, 3, 3, 2, 3, 1, 0]] tileset.tiles[1] = [[1, 3, 3, 1, 3, 0, 2, 1], [3, 2, 2, 3, 3, 2, 2, 2], [1, 1, 2, 2, 3, 0, 1, 1], [0, 3, 2, 2, 0, 0, 0, 3], [3, 3, 0, 0, 1, 0, 1, 0], [2, 3, 1, 3, 3, 2, 1, 2], [0, 0, 0, 1, 3, 2, 3, 3], [2, 2, 3, 2, 0, 0, 0, 1]] block = Block() block.from_list([0] * 32) tileset.to_block(block, 0, 2) assert_list_equal( block.to_list(), [ 0b01010101, # Tile 1 0b10111010, 0b01100100, 0b11001111, 0b10100000, 0b10111101, 0b11100001, 0b01101011, 0b10110111, 0b00000111, 0b11111010, 0b01111101, 0b00110010, 0b11101100, 0b00110110, 0b10111100, 0b11111001, # Tile 2 0b01101010, 0b10011000, 0b11111111, 0b11001011, 0b00111000, 0b01000001, 0b01110001, 0b11001010, 0b11000000, 0b01111010, 0b11011101, 0b00011011, 0b00001111, 0b00100001, 0b11110000 ])
def test_read_1bpp_graphic_from_block(): source = Block() source.from_list([ 42, 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010, 0b11001000, 0b01110001, 0b00000001 ]) target = [[0 for x in range(8)] for y in range(8)] assert_equal( 8, read_1bpp_graphic_from_block(source, target, 1, x=0, y=0, height=8)) assert_list_equal(target, [[0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 0, 0], [0, 1, 1, 1, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1]])
def test_from_block_2bpp(self): block = Block() block.from_list([ 0b01010101, # Tile 1 0b10111010, 0b01100100, 0b11001111, 0b10100000, 0b10111101, 0b11100001, 0b01101011, 0b10110111, 0b00000111, 0b11111010, 0b01111101, 0b00110010, 0b11101100, 0b00110110, 0b10111100, 0b11111001, # Tile 2 0b01101010, 0b10011000, 0b11111111, 0b11001011, 0b00111000, 0b01000001, 0b01110001, 0b11001010, 0b11000000, 0b01111010, 0b11011101, 0b00011011, 0b00001111, 0b00100001, 0b11110000 ]) tileset = EbGraphicTileset(num_tiles=2, tile_width=8, tile_height=8) tileset.from_block(block, offset=0, bpp=2) assert_list_equal(tileset[0], [[2, 1, 2, 3, 2, 1, 2, 1], [2, 3, 1, 0, 2, 3, 2, 2], [3, 0, 3, 2, 2, 2, 0, 2], [1, 3, 3, 0, 2, 0, 2, 3], [1, 0, 1, 1, 0, 3, 3, 3], [1, 3, 3, 3, 3, 2, 1, 2], [2, 2, 3, 1, 2, 2, 1, 0], [2, 0, 3, 3, 2, 3, 1, 0]]) assert_list_equal(tileset[1], [[1, 3, 3, 1, 3, 0, 2, 1], [3, 2, 2, 3, 3, 2, 2, 2], [1, 1, 2, 2, 3, 0, 1, 1], [0, 3, 2, 2, 0, 0, 0, 3], [3, 3, 0, 0, 1, 0, 1, 0], [2, 3, 1, 3, 3, 2, 1, 2], [0, 0, 0, 1, 3, 2, 3, 3], [2, 2, 3, 2, 0, 0, 0, 1]])
def test_from_block_continuous_not_mode_01(self): s = SwirlFrame() block = Block() block.from_list([ 0, 0x7f, 0, 50, 120, 126, 0x82, 50, 51, 52, 53, 54, 55, 0xff, 0, 95, 0, 0xff, 0xff, 0, 0 ]) s.from_block(block, 0) assert_equal(len(s.rows), 224) for row in s.rows[0:0x7f]: assert_equal(SwirlFrameRow(x1=0, x2=50, x3=120, x4=126), row) assert_equal(SwirlFrameRow(x1=50, x2=51, x3=52, x4=53), s.rows[0x7f]) assert_equal(SwirlFrameRow(x1=54, x2=55, x3=0xff, x4=0), s.rows[0x80]) for row in s.rows[0x81:]: assert_equal(SwirlFrameRow(x1=0, x2=0xff, x3=0xff, x4=0), row)
def test_to_block_1bpp(self): tileset = EbGraphicTileset(num_tiles=2, tile_width=8, tile_height=8) tileset.tiles = [None, None] tileset.tiles[0] = [ [0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 0, 0], [0, 1, 1, 1, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1], ] tileset.tiles[1] = [ [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0], [0, 1, 1, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1], ] block = Block() block.from_list([0] * 16) tileset.to_block(block, 0, 1) assert_list_equal( block.to_list(), [ 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010, 0b11001000, 0b01110001, 0b00000001, 0b00100000, 0b00110000, 0b00101000, 0b00101000, 0b01100000, 0b11100000, 0b11000000, 0b00000001, ], )
def test_read_1bpp_graphic_from_block_offset_target(): source = Block() source.from_list([ 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010, 0b11001000, 0b01110001, 0b00000001 ]) target = [[0 for x in range(10)] for y in range(10)] assert_equal( 8, read_1bpp_graphic_from_block(source, target, 0, x=2, y=1, height=8)) assert_list_equal( target, [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 1], [0, 0, 0, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0, 0, 1], [0, 0, 1, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0, 1, 0], [0, 0, 1, 1, 0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
def test_from_block_continuous_not_mode_01(self): s = SwirlFrame() block = Block() block.from_list([0, 0x7f, 0, 50, 120, 126, 0x82, 50, 51, 52, 53, 54, 55, 0xff, 0, 95, 0, 0xff, 0xff, 0, 0]) s.from_block(block, 0) assert_equal(len(s.rows), 224) for row in s.rows[0:0x7f]: assert_equal(SwirlFrameRow(x1=0, x2=50, x3=120, x4=126), row) assert_equal(SwirlFrameRow(x1=50, x2=51, x3=52, x4=53), s.rows[0x7f]) assert_equal(SwirlFrameRow(x1=54, x2=55, x3=0xff, x4=0), s.rows[0x80]) for row in s.rows[0x81:]: assert_equal(SwirlFrameRow(x1=0, x2=0xff, x3=0xff, x4=0), row)
def test_from_block(self): block = Block() block.from_list([1] * 5) block.write_multi(1, 0x8000 | 0x2000 | (7 << 10) | 0x120, 2) block.write_multi(3, 0x4000 | (2 << 10) | 0x3F5, 2) arrangement = EbTileArrangement(2, 1) arrangement.from_block(block, 1) assert_true(arrangement[0, 0].is_vertically_flipped) assert_false(arrangement[0, 0].is_horizontally_flipped) assert_true(arrangement[0, 0].is_priority, True) assert_equal(arrangement[0, 0].subpalette, 7) assert_equal(arrangement[0, 0].tile, 0x120) assert_false(arrangement[1, 0].is_vertically_flipped) assert_true(arrangement[1, 0].is_horizontally_flipped) assert_false(arrangement[1, 0].is_priority) assert_equal(arrangement[1, 0].subpalette, 2) assert_equal(arrangement[1, 0].tile, 0x3F5) arrangement = EbTileArrangement(1, 2) arrangement.from_block(block, 1) assert_true(arrangement[0, 0].is_vertically_flipped) assert_false(arrangement[0, 0].is_horizontally_flipped) assert_true(arrangement[0, 0].is_priority, True) assert_equal(arrangement[0, 0].subpalette, 7) assert_equal(arrangement[0, 0].tile, 0x120) assert_false(arrangement[0, 1].is_vertically_flipped) assert_true(arrangement[0, 1].is_horizontally_flipped) assert_false(arrangement[0, 1].is_priority) assert_equal(arrangement[0, 1].subpalette, 2) assert_equal(arrangement[0, 1].tile, 0x3F5)
def test_write_1bpp_graphic_to_block_rectangular_short(): source = [[0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 0, 0]] target = Block() target.from_list([0xeb] * 8) target[0] = 42 assert_equal(6, write_1bpp_graphic_to_block(source, target, 2, x=0, y=0, height=6)) assert_list_equal(target.to_list(), [42, 0xeb, 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010, 0b11001000])
def test_read_1bpp_graphic_from_block_rectangular_short(): source = Block() source.from_list([42, 0xeb, 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010, 0b11001000]) target = [[0 for x in range(8)] for y in range(6)] assert_equal(6, read_1bpp_graphic_from_block(source, target, 2, x=0, y=0, height=6)) assert_list_equal(target, [ [0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 0, 0]])
def test_to_block(self): arrangement_item = EbTileArrangementItem() block = Block() block.from_list([4] * 3) arrangement_item.is_vertically_flipped = True arrangement_item.is_horizontally_flipped = False arrangement_item.is_priority = True arrangement_item.subpalette = 7 arrangement_item.tile = 0x120 arrangement_item.to_block(block, 0) assert_equal(block.read_multi(0, 2), 0x8000 | 0x2000 | (7 << 10) | 0x120) arrangement_item.is_vertically_flipped = False arrangement_item.is_horizontally_flipped = True arrangement_item.is_priority = False arrangement_item.subpalette = 2 arrangement_item.tile = 0x3F5 arrangement_item.to_block(block, 1) assert_equal(block.read_multi(1, 2), 0x4000 | (2 << 10) | 0x3F5)
def test_standard_text_to_block(): b = Block() b.from_list([0] * 10) standard_text_to_block(block=b, offset=0, text="Test", max_length=10) assert_list_equal(b.to_list(), [132, 149, 163, 164, 0, 0, 0, 0, 0, 0]) b.from_list([0x66] * 10) standard_text_to_block(block=b, offset=0, text="Test", max_length=10) assert_list_equal(b.to_list(), [132, 149, 163, 164, 0, 0x66, 0x66, 0x66, 0x66, 0x66])
def test_read_1bpp_graphic_from_block_rectangular_tall(): source = Block() source.from_list([42, 11, 99, 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010, 0b11001000, 0b01110001, 0b00000001, 0b00100000, 0b00110000, 0b00101000, 0b00101000, 0b01100000, 0b11100000, 0b11000000, 0b00000001, 12, 21]) target = [[0 for x in range(8)] for y in range(16)] assert_equal(16, read_1bpp_graphic_from_block(source, target, 3, x=0, y=0, height=16)) assert_list_equal(target, [ [0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 0, 0], [0, 1, 1, 1, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0], [0, 1, 1, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1]])