Example #1
0
    def test_capture_single(self):
        maps = self.dm_majncraft.worlds['world'].maps
        tm = time_machine.TimeMachine(self.dm_majncraft)

        m_loc = projection.MinecraftLocation(-5000, 65, 8000, maps['surface'].worldtomap)
        self._test_downloaded_image(maps['surface'], tm, m_loc, 1)

        # check border missing tiles
        m_loc = projection.MinecraftLocation(-5100, 65, 8100, maps['surface'].worldtomap)
        self._test_downloaded_image(maps['surface'], tm, m_loc, 0)
Example #2
0
    def test_minecraft_location(self):
        # test iso 30 perspective
        # test wtm on majncraft.cz
        worldtomap = [
            5.65685424949238, 0, -5.656854249492381, -2.8284271247461907,
            6.928203230275509, -2.8284271247461903, 0, 0.9999999999999997, 0
        ]
        m_loc = projection.MinecraftLocation(7600, 65, 100, worldtomap)

        t_loc = m_loc.to_tile_location(0)
        self.assertIsInstance(t_loc, projection.TileLocation)
        self.assertEqual(t_loc.x, 332)
        self.assertEqual(t_loc.y, -167)

        # test zoomlevel = 1
        t_loc = m_loc.to_tile_location(1)
        self.assertEqual(t_loc.x, 332)
        self.assertEqual(t_loc.y, -166)

        # test wtm on majnuj.cz
        worldtomap = [
            11.31370849898, 0.0, -11.313708498984, -5.656854249492,
            13.85640646055, -5.656854249492, 5.551115123125, 0.99999999999,
            5.55111512312578
        ]
        t_loc = projection.MinecraftLocation(-1013, 65, 702,
                                             worldtomap).to_tile_location(0)
        self.assertEqual(t_loc.x, -151)
        self.assertEqual(t_loc.y, 20)

        t_loc = projection.MinecraftLocation(1280, 65, -370,
                                             worldtomap).to_tile_location(0)
        self.assertEqual(t_loc.x, 146)
        self.assertEqual(t_loc.y, -34)

        # test flat map on majnuj.cz
        worldtomap = [4.0, 0.0, 0.0, 0.0, 0.0, -4.0, 0.0, 1.0, 0.0]
        t_loc = projection.MinecraftLocation(1280, 65, -370,
                                             worldtomap).to_tile_location(0)
        self.assertEqual(t_loc.x, 40)
        self.assertEqual(t_loc.y, 11)
    def test_map_image_url(self):
        dm_map = self.dm_majncraft.worlds['world'].maps['surface']
        m_loc = projection.MinecraftLocation(3020, 65, 700, dm_map.worldtomap)
        t_loc = m_loc.to_tile_location(0)

        print()
        print(dm_map.image_url(t_loc))

        t_loc = m_loc.to_tile_location(1)
        print(dm_map.image_url(t_loc))

        t_loc = m_loc.to_tile_location(2)
        print(dm_map.image_url(t_loc))

        dm_map = self.dm_majncraft.worlds['world'].maps['flat']
        m_loc = projection.MinecraftLocation(3020, 65, 700, dm_map.worldtomap)
        t_loc = m_loc.to_tile_location(0)
        print(dm_map.image_url(t_loc))

        t_loc = m_loc.to_tile_location(1)
        print(dm_map.image_url(t_loc))

        t_loc = m_loc.to_tile_location(2)
        print(dm_map.image_url(t_loc))
    if args.world and args.map and args.center and args.boundary_size and args.dest and args.zoom:
        maps = dm.worlds[args.world].maps

        if args.map not in maps.keys():
            logging.error('map not found, use: dynmap-timemachine.py http://dynmap-address world_name map_name [x,y,z] [width,height]')
            for name in maps.keys():
                print('%s - %s' % (name, maps[name].title))
            sys.exit(1)

        center = [int(i) for i in args.center.strip('[]').split(',')]
        size = [int(i) for i in args.boundary_size.strip('[]').split(',')]
        # print(size)
        # sys.exit(-1)

        dm_map = maps[args.map]
        m_loc = projection.MinecraftLocation(center[0], center[1], center[2], dm_map.worldtomap)

        tm = time_machine.TimeMachine(dm)
        dest = args.dest
        zoom = int(args.zoom)
        img = tm.capture_single(dm_map, m_loc.to_tile_location(zoom), size)

        if os.path.isdir(dest):
            files = list(glob.iglob(os.path.join(dest, '*.png')))
            difference = 0
            if files:
                newest_image = max(files, key=os.path.getctime)
                difference = tm.compare_images(Image.open(newest_image), img)
                threshold = float(args.threshold)

            if not files or difference >= threshold: