Exemple #1
0
    def test_export_namespace(self):
        try:
            os.remove('/tmp/level.png')
        except:
            pass

        self.assertFileNotExists('/tmp/level.png')
        image.export_nametable(
            'fixtures/nerdynights/scrolling/SMBlevel.bin',
            'fixtures/nerdynights/scrolling/mario.chr',
            '/tmp/level.png')
        self.assertFileExists('/tmp/level.png')

        img = Image.open('/tmp/level.png')
        sprs, indexes = image.acquire_chr(img, optimize_repeated=False)
        sprite.length(sprs)
        self.assertEquals(1024, sprite.length(sprs))
        return  # TODO why?!
        nt_file = open('fixtures/nerdynights/scrolling/SMBlevel.bin')
        nt = nt_file.read()
        nt_file.close()
        nts = [ord(n) for n in nt]
        mario = sprite.load_sprites('fixtures/nerdynights/scrolling/mario.chr')
        for i in range(32):
            for j in range(32):
                self.assertSpriteEquals(
                    sprite.get_sprite(nts[i * j] + 256, mario),
                    sprite.get_sprite(i * j, sprs)
                )
        os.remove('/tmp/level.png')
Exemple #2
0
    def test_export_namespace(self):
        try:
            os.remove('/tmp/level.png')
        except:
            pass

        self.assertFileNotExists('/tmp/level.png')
        image.export_nametable(
            'fixtures/nerdynights/scrolling/SMBlevel.bin',
            'fixtures/nerdynights/scrolling/mario.chr',
            '/tmp/level.png')
        self.assertFileExists('/tmp/level.png')
        
        img = Image.open('/tmp/level.png')
        sprs, indexes = image.acquire_chr(img, optimize_repeated=False)
        sprite.length(sprs)
        self.assertEquals(1024,sprite.length(sprs))
        return #TODO why?!
        nt_file = open('fixtures/nerdynights/scrolling/SMBlevel.bin')
        nt = nt_file.read()
        nt_file.close()
        nts = [ord(n) for n in nt]
        mario = sprite.load_sprites('fixtures/nerdynights/scrolling/mario.chr')
        for i in range(32):
            for j in range(32):
                self.assertSpriteEquals(
                    sprite.get_sprite(nts[i*j] + 256, mario),
                    sprite.get_sprite(i*j, sprs)
                )
        os.remove('/tmp/level.png')
Exemple #3
0
 def test_convert_chr(self):
     img = Image.open('fixtures/mario.png')
     sprs = image.convert_chr(img)
     self.assertIsNotNone(sprs)
     self.assertEquals(8192, len(sprs))
     self.assertEquals(self.mario1, sprite.get_sprite(0, sprs))
     self.assertEquals(self.mario2, sprite.get_sprite(1, sprs))
Exemple #4
0
 def test_read_nametable(self): 
     level = Image.open('fixtures/level.png')
     sprs = sprite.load_sprites('fixtures/nerdynights/scrolling/mario.chr')
     nt = image.read_nametable(level, sprs)
     return
     expected = open('fixtures/nerdynights/scrolling/SMBlevel.bin', 'rb').read()
     actual = open('/tmp/level.bin', 'rb').read()
     size = len(actual)
     self.assertEquals(expected[:size], actual[:size])
     return
     sprs = image.convert_chr(img)
     self.assertEquals(8192, len(sprs))
     self.assertEquals(self.mario1, sprite.get_sprite(0, sprs))
     self.assertEquals(self.mario2, sprite.get_sprite(1, sprs))
Exemple #5
0
 def test_put_second_sprite(self):
     expected = [[0, 1, 2, 3, 0, 1, 2, 3], [1, 0, 1, 2, 3, 0, 1, 2],
                 [2, 1, 0, 1, 2, 3, 0, 1], [3, 2, 1, 0, 1, 2, 3, 0],
                 [0, 3, 2, 1, 0, 1, 2, 3], [1, 0, 3, 2, 1, 0, 1, 2],
                 [2, 1, 0, 3, 2, 1, 0, 1], [3, 2, 1, 0, 3, 2, 1, 0]]
     sprite.put_sprite(1, self.bin, expected)
     s1 = sprite.get_sprite(1, self.bin)
     self.assertEquals(expected, s1)
Exemple #6
0
    def test_export_chr(self):
        try:
            os.remove('/tmp/mario.png')
        except:
            pass
        self.assertFileNotExists('/tmp/mario.png')
        image.export_chr('fixtures/nerdynights/scrolling/mario.chr', '/tmp/mario.png')
        self.assertFileExists('/tmp/mario.png')
        self.assertPNGFileEquals('fixtures/mario.png', '/tmp/mario.png')

        img = Image.open('/tmp/mario.png')
        sprs, indexes = image.acquire_chr(img)
        self.assertIsNotNone(sprs)
        self.assertEquals(8192, len(sprs))
        self.assertSpriteEquals(self.mario1, sprite.get_sprite(0, sprs))
        self.assertSpriteEquals(self.mario2, sprite.get_sprite(1, sprs))

        os.remove('/tmp/mario.png')
Exemple #7
0
 def test_put_first_sprite(self):
     expected = [
         [0,1,2,3,0,1,2,3],
         [1,0,1,2,3,0,1,2],
         [2,1,0,1,2,3,0,1],
         [3,2,1,0,1,2,3,0],
         [0,3,2,1,0,1,2,3],
         [1,0,3,2,1,0,1,2],
         [2,1,0,3,2,1,0,1],
         [3,2,1,0,3,2,1,0]
     ]
     sprite.put_sprite(0, self.bin, expected)
     s1 = sprite.get_sprite(0, self.bin)
     self.assertEquals(expected, s1)
Exemple #8
0
def show_sprites(sprs):
    ENDC = '\033[0m'
    length = sprite.length(sprs)
    tiles = []
    for i in range(length):
        spr = get_printable_sprite(sprite.get_sprite(i, sprs))
        tiles.append(spr)
        if len(tiles) % 8 == 0:
            out = ''
            for t in tiles:
                for l in t:
                    out += l + ENDC
                out += '\n'
            tiles = []
            print out
Exemple #9
0
def show_sprites(sprs):
    ENDC = '\033[0m'
    length = sprite.length(sprs)
    tiles = []
    for i in range(length):
        spr = get_printable_sprite(sprite.get_sprite(i, sprs))
        tiles.append(spr)
        if len(tiles) % 8 == 0:
            out = ''
            for t in tiles:
                for l in t:
                    out += l + ENDC
                out += '\n'
            tiles = []
            print (out)
Exemple #10
0
 def test_acquire_chr(self):
     img = Image.open('fixtures/mario.png')
     sprs, indexes = image.acquire_chr(img)
     self.assertEquals(8192, len(sprs))
     self.assertSpriteEquals(self.mario1, sprite.get_sprite(0, sprs))
Exemple #11
0
 def test_get_second_sprite(self):
     s2 = sprite.get_sprite(1, self.bin)
     self.assertEquals(self.mario2, s2)
Exemple #12
0
 def test_get_first_sprite(self):
     s1 = sprite.get_sprite(0, self.bin)
     self.assertEquals(self.mario1, s1)
Exemple #13
0
 def test_acquire_chr(self):
     img = Image.open('fixtures/mario.png')
     sprs, indexes = image.acquire_chr(img)
     self.assertEquals(8192, len(sprs))
     self.assertSpriteEquals(self.mario1, sprite.get_sprite(0, sprs))