コード例 #1
0
ファイル: test_skoolmacro.py プロジェクト: skoolkid/skoolkit
    def test_parse_image_macro_with_frame(self):
        # Implicit frame name
        end, crop_rect, fname, frame, alt, values = parse_image_macro('1(logo*)', names=('a',))
        self.assertEqual(end, 8)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, 'logo')
        self.assertEqual(frame, fname)
        self.assertIsNone(alt)
        self.assertEqual([1], values)

        # Explicit frame name
        end, crop_rect, fname, frame, alt, values = parse_image_macro('1(logo*frame1)', names=('a',))
        self.assertEqual(end, 14)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, 'logo')
        self.assertEqual(frame, 'frame1')
        self.assertIsNone(alt)
        self.assertEqual([1], values)

        # Explicit frame name, no filename
        end, crop_rect, fname, frame, alt, values = parse_image_macro('1(*frame1)', names=('a',))
        self.assertEqual(end, 10)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, '')
        self.assertEqual(frame, 'frame1')
        self.assertIsNone(alt)
        self.assertEqual([1], values)
コード例 #2
0
ファイル: test_skoolmacro.py プロジェクト: skoolkid/skoolkit
    def test_parse_image_macro_with_alt_text(self):
        # Alt text
        end, crop_rect, fname, frame, alt, values = parse_image_macro('1(logo|Logo)', names=('a',))
        self.assertEqual(end, 12)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, 'logo')
        self.assertIsNone(frame)
        self.assertEqual(alt, 'Logo')
        self.assertEqual([1], values)

        # Filename, implicit frame name, alt text
        end, crop_rect, fname, frame, alt, values = parse_image_macro('1(logo*|Logo)', names=('a',))
        self.assertEqual(end, 13)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, 'logo')
        self.assertEqual(frame, fname)
        self.assertEqual(alt, 'Logo')
        self.assertEqual([1], values)

        # Filename, explicit frame name, alt text
        end, crop_rect, fname, frame, alt, values = parse_image_macro('1(logo*frame1|Logo)', names=('a',))
        self.assertEqual(end, 19)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, 'logo')
        self.assertEqual(frame, 'frame1')
        self.assertEqual(alt, 'Logo')
        self.assertEqual([1], values)
コード例 #3
0
ファイル: test_skoolmacro.py プロジェクト: skoolkid/skoolkit
    def test_parse_image_macro_with_no_parameters_expected(self):
        # No parameters, no cropping spec, no filename
        end, crop_rect, fname, frame, alt, values = parse_image_macro('xxx')
        self.assertEqual(end, 0)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, '')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([], values)

        # No parameters, no cropping spec, filename
        end, crop_rect, fname, frame, alt, values = parse_image_macro('#FOO(image)', 4)
        self.assertEqual(end, 11)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, 'image')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([], values)

        # No parameters, cropping spec, no filename
        end, crop_rect, fname, frame, alt, values = parse_image_macro('{1,2,3,4}')
        self.assertEqual(end, 9)
        self.assertEqual(crop_rect, (1, 2, 3, 4))
        self.assertEqual(fname, '')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([], values)
コード例 #4
0
    def test_parse_image_macro_with_frame(self):
        # Implicit frame name
        end, crop_rect, fname, frame, alt, values = parse_image_macro(
            '1(logo*)', names=('a', ))
        self.assertEqual(end, 8)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, 'logo')
        self.assertEqual(frame, fname)
        self.assertIsNone(alt)
        self.assertEqual([1], values)

        # Explicit frame name
        end, crop_rect, fname, frame, alt, values = parse_image_macro(
            '1(logo*frame1)', names=('a', ))
        self.assertEqual(end, 14)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, 'logo')
        self.assertEqual(frame, 'frame1')
        self.assertIsNone(alt)
        self.assertEqual([1], values)

        # Explicit frame name, no filename
        end, crop_rect, fname, frame, alt, values = parse_image_macro(
            '1(*frame1)', names=('a', ))
        self.assertEqual(end, 10)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, '')
        self.assertEqual(frame, 'frame1')
        self.assertIsNone(alt)
        self.assertEqual([1], values)
コード例 #5
0
    def test_parse_image_macro_with_no_parameters_expected(self):
        # No parameters, no cropping spec, no filename
        end, crop_rect, fname, frame, alt, values = parse_image_macro('xxx')
        self.assertEqual(end, 0)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, '')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([], values)

        # No parameters, no cropping spec, filename
        end, crop_rect, fname, frame, alt, values = parse_image_macro(
            '#FOO(image)', 4)
        self.assertEqual(end, 11)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, 'image')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([], values)

        # No parameters, cropping spec, no filename
        end, crop_rect, fname, frame, alt, values = parse_image_macro(
            '{1,2,3,4}')
        self.assertEqual(end, 9)
        self.assertEqual(crop_rect, (1, 2, 3, 4))
        self.assertEqual(fname, '')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([], values)
コード例 #6
0
    def test_parse_image_macro_with_alt_text(self):
        # Alt text
        end, crop_rect, fname, frame, alt, values = parse_image_macro(
            '1(logo|Logo)', names=('a', ))
        self.assertEqual(end, 12)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, 'logo')
        self.assertIsNone(frame)
        self.assertEqual(alt, 'Logo')
        self.assertEqual([1], values)

        # Filename, implicit frame name, alt text
        end, crop_rect, fname, frame, alt, values = parse_image_macro(
            '1(logo*|Logo)', names=('a', ))
        self.assertEqual(end, 13)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, 'logo')
        self.assertEqual(frame, fname)
        self.assertEqual(alt, 'Logo')
        self.assertEqual([1], values)

        # Filename, explicit frame name, alt text
        end, crop_rect, fname, frame, alt, values = parse_image_macro(
            '1(logo*frame1|Logo)', names=('a', ))
        self.assertEqual(end, 19)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, 'logo')
        self.assertEqual(frame, 'frame1')
        self.assertEqual(alt, 'Logo')
        self.assertEqual([1], values)
コード例 #7
0
    def test_parse_image_macro_with_parameters(self):
        # One required parameter
        end, crop_rect, fname, frame, alt, values = parse_image_macro(
            '#BAR1', 4, names=('arg', ))
        self.assertEqual(end, 5)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, '')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1], values)

        # Two required parameters
        end, crop_rect, fname, frame, alt, values = parse_image_macro(
            '1,2', names=('arga', 'argb'))
        self.assertEqual(end, 3)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, '')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1, 2], values)

        # One required parameter, one optional and omitted
        end, crop_rect, fname, frame, alt, values = parse_image_macro(
            '1', defaults=(2, ), names=('arga', 'argb'))
        self.assertEqual(end, 1)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, '')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1, 2], values)

        # One required parameter, two optional, second omitted
        end, crop_rect, fname, frame, alt, values = parse_image_macro(
            '1,,3', defaults=(2, 3), names=('arga', 'argb', 'argc'))
        self.assertEqual(end, 4)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, '')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1, 2, 3], values)

        # One required parameter, two optional, second omitted, third named
        end, crop_rect, fname, frame, alt, values = parse_image_macro(
            '1,argc=3', defaults=(2, 3), names=('arga', 'argb', 'argc'))
        self.assertEqual(end, 8)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, '')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1, 2, 3], values)

        # Two optional parameters omitted, filename
        end, crop_rect, fname, frame, alt, values = parse_image_macro(
            '(logo)', defaults=(1, 2), names=('arga', 'argb'))
        self.assertEqual(end, 6)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, 'logo')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1, 2], values)
コード例 #8
0
    def test_parse_image_macro_with_cropping_spec(self):
        # Cropping spec with all parameters omitted
        end, crop_rect, fname, frame, alt, values = parse_image_macro(
            '1{}', names=('a', ))
        self.assertEqual(end, 3)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, '')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1], values)

        # Cropping spec with some parameters omitted
        end, crop_rect, fname, frame, alt, values = parse_image_macro(
            '#BAZ1{1,2}', 4, names=('a', ))
        self.assertEqual(end, 10)
        self.assertEqual(crop_rect, (1, 2, None, None))
        self.assertEqual(fname, '')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1], values)

        # Cropping spec with some parameters omitted, one named
        end, crop_rect, fname, frame, alt, values = parse_image_macro(
            '1{1,width=5}', names=('a', ))
        self.assertEqual(end, 12)
        self.assertEqual(crop_rect, (1, 0, 5, None))
        self.assertEqual(fname, '')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1], values)

        # Cropping spec with all parameters named
        end, crop_rect, fname, frame, alt, values = parse_image_macro(
            '1{width=5,height=6,x=1,y=2}', names=('a', ))
        self.assertEqual(end, 27)
        self.assertEqual(crop_rect, (1, 2, 5, 6))
        self.assertEqual(fname, '')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1], values)
コード例 #9
0
    def test_parse_image_macro_with_filename(self):
        # No default filename, no filename specified
        end, crop_rect, fname, frame, alt, values = parse_image_macro(
            '1', names=('a', ))
        self.assertEqual(end, 1)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, '')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1], values)

        # No default filename, filename specified
        end, crop_rect, fname, frame, alt, values = parse_image_macro(
            '1(image)', names=('a', ))
        self.assertEqual(end, 8)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, 'image')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1], values)

        # Default filename, no filename specified
        end, crop_rect, fname, frame, alt, values = parse_image_macro(
            '1', names=('a', ), fname='image')
        self.assertEqual(end, 1)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, 'image')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1], values)

        # Default filename, filename specified
        end, crop_rect, fname, frame, alt, values = parse_image_macro(
            '1(logo)', names=('a', ), fname='image')
        self.assertEqual(end, 7)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, 'logo')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1], values)
コード例 #10
0
 def expand_willy(self, text, index, cwd):
     # #WILLYroom,x,y,sprite[,left,top,width,height,scale](fname)
     names = ('room', 'x', 'y', 'sprite', 'left', 'top', 'width', 'height', 'scale')
     defaults = (0, 0, 32, 17, 2)
     end, crop_rect, fname, frame, alt, params = parse_image_macro(text, index, defaults, names)
     room, x, pixel_y, sprite, left, top, width, height, scale = params
     room_addr = 49152 + 256 * room
     room_udgs = self._get_room_udgs(room_addr, 1)
     willy = self._get_graphic(40192 + 32 * sprite, 7)
     room_bg = self.snapshot[room_addr + 160]
     self._place_graphic(room_udgs, willy, x, pixel_y, room_bg)
     img_udgs = [room_udgs[i][left:left + width] for i in range(top, top + min(height, 17 - top))]
     frames = [Frame(img_udgs, scale, 0, *crop_rect, name=frame)]
     return end, self.handle_image(frames, fname, cwd, alt, 'ScreenshotImagePath')
コード例 #11
0
 def expand_willy(self, text, index, cwd):
     # #WILLYcavern,x,y,sprite[,left,top,width,height,scale](fname)
     names = ('cavern', 'x', 'y', 'sprite', 'left', 'top', 'width', 'height', 'scale')
     defaults = (0, 0, 32, 17, 2)
     end, crop_rect, fname, frame, alt, params = parse_image_macro(text, index, defaults, names)
     cavern, x, pixel_y, sprite, left, top, width, height, scale = params
     cavern_addr = 45056 + 1024 * cavern
     cavern_udgs = self._get_cavern_udgs(cavern_addr, 0)
     willy = self._get_graphic(33280 + 32 * sprite, 7)
     cavern_bg = self.snapshot[cavern_addr + 544]
     self._place_graphic(cavern_udgs, willy, x, pixel_y, cavern_bg)
     img_udgs = [cavern_udgs[i][left:left + width] for i in range(top, top + min(height, 17 - top))]
     frames = [Frame(img_udgs, scale, 0, *crop_rect, name=frame)]
     return end, self.handle_image(frames, fname, cwd, alt, 'ScreenshotImagePath')
コード例 #12
0
ファイル: manicminer.py プロジェクト: bestm80eva/manicminer
 def expand_willy(self, text, index, cwd):
     # #WILLYcavern,x,y,sprite[,left,top,width,height,scale](fname)
     names = ('cavern', 'x', 'y', 'sprite', 'left', 'top', 'width', 'height', 'scale')
     defaults = (0, 0, 32, 17, 2)
     end, crop_rect, fname, frame, alt, params = parse_image_macro(text, index, defaults, names)
     cavern, x, pixel_y, sprite, left, top, width, height, scale = params
     cavern_addr = 45056 + 1024 * cavern
     cavern_udgs = self._get_cavern_udgs(cavern_addr, 0)
     willy = self._get_graphic(33280 + 32 * sprite, 7)
     cavern_bg = self.snapshot[cavern_addr + 544]
     self._place_graphic(cavern_udgs, willy, x, pixel_y, cavern_bg)
     img_udgs = [cavern_udgs[i][left:left + width] for i in range(top, top + min(height, 17 - top))]
     frames = [Frame(img_udgs, scale, 0, *crop_rect, name=frame)]
     return end, self.handle_image(frames, fname, cwd, alt, 'ScreenshotImagePath')
コード例 #13
0
ファイル: test_skoolmacro.py プロジェクト: skoolkid/skoolkit
    def test_parse_image_macro_with_filename(self):
        # No default filename, no filename specified
        end, crop_rect, fname, frame, alt, values = parse_image_macro('1', names=('a',))
        self.assertEqual(end, 1)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, '')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1], values)

        # No default filename, filename specified
        end, crop_rect, fname, frame, alt, values = parse_image_macro('1(image)', names=('a',))
        self.assertEqual(end, 8)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, 'image')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1], values)

        # Default filename, no filename specified
        end, crop_rect, fname, frame, alt, values = parse_image_macro('1', names=('a',), fname='image')
        self.assertEqual(end, 1)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, 'image')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1], values)

        # Default filename, filename specified
        end, crop_rect, fname, frame, alt, values = parse_image_macro('1(logo)', names=('a',), fname='image')
        self.assertEqual(end, 7)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, 'logo')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1], values)
コード例 #14
0
ファイル: test_skoolmacro.py プロジェクト: skoolkid/skoolkit
    def test_parse_image_macro_with_cropping_spec(self):
        # Cropping spec with all parameters omitted
        end, crop_rect, fname, frame, alt, values = parse_image_macro('1{}', names=('a',))
        self.assertEqual(end, 3)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, '')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1], values)

        # Cropping spec with some parameters omitted
        end, crop_rect, fname, frame, alt, values = parse_image_macro('#BAZ1{1,2}', 4, names=('a',))
        self.assertEqual(end, 10)
        self.assertEqual(crop_rect, (1, 2, None, None))
        self.assertEqual(fname, '')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1], values)

        # Cropping spec with some parameters omitted, one named
        end, crop_rect, fname, frame, alt, values = parse_image_macro('1{1,width=5}', names=('a',))
        self.assertEqual(end, 12)
        self.assertEqual(crop_rect, (1, 0, 5, None))
        self.assertEqual(fname, '')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1], values)

        # Cropping spec with all parameters named
        end, crop_rect, fname, frame, alt, values = parse_image_macro('1{width=5,height=6,x=1,y=2}', names=('a',))
        self.assertEqual(end, 27)
        self.assertEqual(crop_rect, (1, 2, 5, 6))
        self.assertEqual(fname, '')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1], values)
コード例 #15
0
ファイル: test_skoolmacro.py プロジェクト: skoolkid/skoolkit
    def test_parse_image_macro_with_parameters(self):
        # One required parameter
        end, crop_rect, fname, frame, alt, values = parse_image_macro('#BAR1', 4, names=('arg',))
        self.assertEqual(end, 5)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, '')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1], values)

        # Two required parameters
        end, crop_rect, fname, frame, alt, values = parse_image_macro('1,2', names=('arga', 'argb'))
        self.assertEqual(end, 3)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, '')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1, 2], values)

        # One required parameter, one optional and omitted
        end, crop_rect, fname, frame, alt, values = parse_image_macro('1', defaults=(2,), names=('arga', 'argb'))
        self.assertEqual(end, 1)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, '')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1, 2], values)

        # One required parameter, two optional, second omitted
        end, crop_rect, fname, frame, alt, values = parse_image_macro('1,,3', defaults=(2, 3), names=('arga', 'argb', 'argc'))
        self.assertEqual(end, 4)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, '')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1, 2, 3], values)

        # One required parameter, two optional, second omitted, third named
        end, crop_rect, fname, frame, alt, values = parse_image_macro('1,argc=3', defaults=(2, 3), names=('arga', 'argb', 'argc'))
        self.assertEqual(end, 8)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, '')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1, 2, 3], values)

        # Two optional parameters omitted, filename
        end, crop_rect, fname, frame, alt, values = parse_image_macro('(logo)', defaults=(1, 2), names=('arga', 'argb'))
        self.assertEqual(end, 6)
        self.assertEqual(crop_rect, (0, 0, None, None))
        self.assertEqual(fname, 'logo')
        self.assertIsNone(frame)
        self.assertIsNone(alt)
        self.assertEqual([1, 2], values)
コード例 #16
0
 def expand_room(self, text, index, cwd):
     # #ROOMaddr[,scale,x,y,w,h,empty,fix,anim][{x,y,width,height}][(fname)]
     names = ('addr', 'scale', 'x', 'y', 'w', 'h', 'empty', 'fix', 'anim')
     defaults = (2, 0, 0, 32, 17, 0, 0, 0)
     end, crop_rect, fname, frame, alt, params = parse_image_macro(text, index, defaults, names)
     address, scale, x, y, w, h, empty, fix, anim = params
     if not fname:
         room_name = self.room_names[address // 256 - 192]
         fname = room_name.lower().replace(' ', '_')
     room_udgs = self._get_room_udgs(address, empty, fix)
     img_udgs = [room_udgs[i][x:x + w] for i in range(y, y + min(h, 17 - y))]
     if anim:
         attr = self.snapshot[address + 205]
         direction = self.snapshot[address + 214]
         frames = self._animate_conveyor(img_udgs, attr, direction, crop_rect, scale)
     else:
         frames = [Frame(img_udgs, scale, 0, *crop_rect, name=frame)]
     return end, self.handle_image(frames, fname, cwd, alt, 'ScreenshotImagePath')
コード例 #17
0
 def expand_logo(self, text, index, cwd):
     # #LOGO[{x,y,width,height}](fname)
     end, crop_rect, fname, frame, alt, params = parse_image_macro(text, index)
     udgs = lambda: self._build_logo()
     frames = [Frame(udgs, 1, 0, *crop_rect, name=frame)]
     return end, self.handle_image(frames, fname, cwd, alt)