def merge_textures(self, data):
        """
        data: A list of (id, height) tuples.
        """
        texturesToMerge = []
        for id, height in data:
            if id <= 0:
                continue
            texture = self.textures.get(id)
            if texture is None: 
                continue
            texturesToMerge.append((height, texture))

        if not texturesToMerge:
            return None
        rects = [
            pg.Rect((-t.xoff, -t.yoff - height), t.image.get_size()) 
            for height, t in texturesToMerge
        ]
        rect = rects[0].unionall(rects)
        image = utils.new_surface(rect.size)
        # image.fill((0x50, 0x50, 0x50, 100))
        x, y = -rect.x, -rect.y
        for height, t in texturesToMerge:
            image.blit(t.image, (x - t.xoff, y - t.yoff - height))
        return Texture(x, y, image)
Beispiel #2
0
    def merge_textures(self, data):
        """
        data: A list of (id, height) tuples.
        """
        texturesToMerge = []
        for id, height in data:
            if id <= 0:
                continue
            texture = self.textures.get(id)
            if texture is None:
                continue
            texturesToMerge.append((height, texture))

        if not texturesToMerge:
            return None
        rects = [
            pg.Rect((-t.xoff, -t.yoff - height), t.image.get_size())
            for height, t in texturesToMerge
        ]
        rect = rects[0].unionall(rects)
        image = utils.new_surface(rect.size)
        # image.fill((0x50, 0x50, 0x50, 100))
        x, y = -rect.x, -rect.y
        for height, t in texturesToMerge:
            image.blit(t.image, (x - t.xoff, y - t.yoff - height))
        return Texture(x, y, image)
Beispiel #3
0
    def __init__(self, game):
        super().__init__()
        self.game = game
        self.currentIdx = 0
        self.select(0)

        self.rect = self.make_rect(self.items)
        self.image = utils.new_surface(self.rect.size)
        self._dirty = True
Beispiel #4
0
    def __init__(self, game):
        super().__init__()
        self.game = game
        self.currentIdx = 0
        self.select(0)

        self.rect = self.make_rect(self.items)
        self.image = utils.new_surface(self.rect.size)
        self._dirty = True
 def make_image(self, waste_color=0xFF0000):
     surface = utils.new_surface(self.size)
     surface.fill(waste_color)
     for image, pos in zip(self.images, self.poses):
         colorKey = image.get_colorkey()
         image.set_colorkey(None)
         surface.blit(image, pos)
         image.set_colorkey(colorKey)
     return surface
 def __on_size_allocate(self, widget, alloc):
     x, y, w, h = self.allocation
     # !! no expose and blur.
     if ((self.old_w == w and self.old_h == h)):
         return False
     # 
     self.surface, self.surface_cr = new_surface(w, h)
     self.__compute_shadow(w, h)
     self.old_w = w
     self.old_h = h
    def __init__(self, xmax, ymax, textures):
        super().__init__()
        self.textures = textures
        size = (
            config.screenWidth + self.PAD_X * 2, 
            config.screenHeight + self.PAD_Y * 2 + config.bottomPadding,
        )
        innerSize = (
            config.screenWidth - 2 * config.debugMargin,
            config.screenHeight - 2 * config.debugMargin,
        )
        self.rect = pg.Rect((-self.PAD_X, -self.PAD_Y), size)

        self.image = utils.new_surface(size)
        self.drawImage = self.image.copy()
        self.floorImage = self.image.copy()

        if CLIP:
            clip_rect = (
                (self.PAD_X + config.debugMargin - self.GX,
                    self.PAD_Y + config.debugMargin - self.GY),
                add(innerSize, (2 * self.GX, 2 * self.GY)),
            )
            self.image.set_clip(clip_rect)
            self.drawImage.set_clip(clip_rect)

        self.currentPos = (0, 0)
        self.directionQueue = []
        self.xmax = xmax
        self.ymax = ymax
        self.looper = ScrollLooper(
            # (config.screenWidth, config.screenHeight),  # size
            innerSize,  # size
            (self.GX, self.GY),  # grid size
        )

        self._gridTextureCache = pyxlru.lru(config.mainMapCacheSize)
        # self._gridTextureCache = {}
        self._dirty = threading.Condition()
        self._swapped = False
        self._drawnPos = (-1, -1)
        self._rows = deque()
        self._quit = False
        self.drawLock = threading.RLock()
        if config.smoothTicks > 1:
            self.drawerThread = threading.Thread(target=self.drawer)
            self.drawerThread.daemon = True
            self.drawerThread.start()
        self.rAdjuster = SimpleRateAdjuster()
Beispiel #8
0
    def __init__(self, xmax, ymax, textures):
        super().__init__()
        self.textures = textures
        size = (
            config.screenWidth + self.PAD_X * 2,
            config.screenHeight + self.PAD_Y * 2 + config.bottomPadding,
        )
        innerSize = (
            config.screenWidth - 2 * config.debugMargin,
            config.screenHeight - 2 * config.debugMargin,
        )
        self.rect = pg.Rect((-self.PAD_X, -self.PAD_Y), size)

        self.image = utils.new_surface(size)
        self.drawImage = self.image.copy()
        self.floorImage = self.image.copy()

        if CLIP:
            clip_rect = (
                (self.PAD_X + config.debugMargin - self.GX,
                 self.PAD_Y + config.debugMargin - self.GY),
                add(innerSize, (2 * self.GX, 2 * self.GY)),
            )
            self.image.set_clip(clip_rect)
            self.drawImage.set_clip(clip_rect)

        self.currentPos = (0, 0)
        self.directionQueue = []
        self.xmax = xmax
        self.ymax = ymax
        self.looper = ScrollLooper(
            # (config.screenWidth, config.screenHeight),  # size
            innerSize,  # size
            (self.GX, self.GY),  # grid size
        )

        self._gridTextureCache = pyxlru.lru(config.mainMapCacheSize)
        # self._gridTextureCache = {}
        self._dirty = threading.Condition()
        self._swapped = False
        self._drawnPos = (-1, -1)
        self._rows = deque()
        self._quit = False
        self.drawLock = threading.RLock()
        if config.smoothTicks > 1:
            self.drawerThread = threading.Thread(target=self.drawer)
            self.drawerThread.daemon = True
            self.drawerThread.start()
        self.rAdjuster = SimpleRateAdjuster()
    def make_minimap(self, save_to, scale=1 / 4):
        gx = self.GX * scale
        gy = self.GY * scale
        print('gx gy:', (gx, gy))
        xmax, ymax = self.xmax, self.ymax
        # xmax //= 2
        # ymax //= 2
        # Left most grid: (0, ymax) 
        # Right most grid: (xmax, 0)
        # Top most grid: (0, 0)
        # Bottom most grid: (xmax, ymax)
        centerX, centerY = 0, 0
        open(save_to, 'wb').close()

        # Function to convert from grid to surface
        def to_spos(pos):
            x, y = pos
            return ((centerX + (x - y) * gx), ((x + y + 1) * gy))

        width = int(gx * 2 + minus(to_spos((xmax, 0)), to_spos((0, ymax)))[0])
        height = int(gy * 2 + minus(to_spos((xmax, ymax)), to_spos((0, 0)))[1])

        progress = utils.ProgressBar(xmax * ymax)

        surface = utils.new_surface((width, height))
        print('dest size:', surface.get_size())
        centerX, centerY = surface.get_rect().center

        utils.clear_surface(surface)
        tmpSize = tmpWidth, tmpHeight = (2 ** 12,) * 2
        print('tmp buffer size:', tmpSize)
        tmpScaleSize = (int(tmpWidth * scale), int(tmpHeight * scale))
        print('tmpScaleSize:', tmpScaleSize)
        tmpSurface = utils.new_surface(tmpSize)
        blockDx = blockDy = int(min(tmpWidth / self.GX / 2, tmpHeight / self.GY / 2))

        for blockX in range(0, xmax, blockDx):
            for blockY in range(0, ymax, blockDy):
                utils.clear_surface(tmpSurface)
                for x in range(blockDx):
                    for y in range(blockDy):
                        if not 0 <= x < xmax or not 0 <= y < ymax:
                            continue
                        # Draw floor
                        texture = self.get_floor_texture((blockX + x, blockY + y))\
                            or self.textures.get(0)
                        spos = (
                            tmpWidth / 2 - texture.xoff + (x - y) * self.GX, 
                            -texture.yoff + (x + y + 1) * self.GY,
                        )
                        tmpSurface.blit(texture.image, spos)
                        # Draw other
                        texture = self.get_grid_texture((blockX + x, blockY + y))
                        if texture:
                            spos = (
                                tmpWidth / 2 - texture.xoff + (x - y) * self.GX, 
                                -texture.yoff + (x + y + 1) * self.GY,
                            )
                            tmpSurface.blit(texture.image, spos)
                        progress.update()

                surface.blit(
                    pg.transform.scale(tmpSurface, add((1, 1), tmpScaleSize)),
                    minus(to_spos((blockX, blockY)), (tmpScaleSize[0] / 2, gy))
                )
                # print((blockX, blockY), to_spos((blockX, blockY)))

        pg.image.save(surface, save_to)
        print('\nfinished')
Beispiel #10
0
    def make_minimap(self, save_to, scale=1 / 4):
        gx = self.GX * scale
        gy = self.GY * scale
        print('gx gy:', (gx, gy))
        xmax, ymax = self.xmax, self.ymax
        # xmax //= 2
        # ymax //= 2
        # Left most grid: (0, ymax)
        # Right most grid: (xmax, 0)
        # Top most grid: (0, 0)
        # Bottom most grid: (xmax, ymax)
        centerX, centerY = 0, 0
        open(save_to, 'wb').close()

        # Function to convert from grid to surface
        def to_spos(pos):
            x, y = pos
            return ((centerX + (x - y) * gx), ((x + y + 1) * gy))

        width = int(gx * 2 + minus(to_spos((xmax, 0)), to_spos((0, ymax)))[0])
        height = int(gy * 2 + minus(to_spos((xmax, ymax)), to_spos((0, 0)))[1])

        progress = utils.ProgressBar(xmax * ymax)

        surface = utils.new_surface((width, height))
        print('dest size:', surface.get_size())
        centerX, centerY = surface.get_rect().center

        utils.clear_surface(surface)
        tmpSize = tmpWidth, tmpHeight = (2**12, ) * 2
        print('tmp buffer size:', tmpSize)
        tmpScaleSize = (int(tmpWidth * scale), int(tmpHeight * scale))
        print('tmpScaleSize:', tmpScaleSize)
        tmpSurface = utils.new_surface(tmpSize)
        blockDx = blockDy = int(
            min(tmpWidth / self.GX / 2, tmpHeight / self.GY / 2))

        for blockX in range(0, xmax, blockDx):
            for blockY in range(0, ymax, blockDy):
                utils.clear_surface(tmpSurface)
                for x in range(blockDx):
                    for y in range(blockDy):
                        if not 0 <= x < xmax or not 0 <= y < ymax:
                            continue
                        # Draw floor
                        texture = self.get_floor_texture((blockX + x, blockY + y))\
                            or self.textures.get(0)
                        spos = (
                            tmpWidth / 2 - texture.xoff + (x - y) * self.GX,
                            -texture.yoff + (x + y + 1) * self.GY,
                        )
                        tmpSurface.blit(texture.image, spos)
                        # Draw other
                        texture = self.get_grid_texture(
                            (blockX + x, blockY + y))
                        if texture:
                            spos = (
                                tmpWidth / 2 - texture.xoff +
                                (x - y) * self.GX,
                                -texture.yoff + (x + y + 1) * self.GY,
                            )
                            tmpSurface.blit(texture.image, spos)
                        progress.update()

                surface.blit(
                    pg.transform.scale(tmpSurface, add((1, 1), tmpScaleSize)),
                    minus(to_spos((blockX, blockY)),
                          (tmpScaleSize[0] / 2, gy)))
                # print((blockX, blockY), to_spos((blockX, blockY)))

        pg.image.save(surface, save_to)
        print('\nfinished')