Ejemplo n.º 1
0
    def remap_point(vec: Vector, old_extent: 'Extent',
                    new_extent: 'Extent') -> Vector:

        x, y = vec

        if old_extent is None or new_extent is None:
            logger.warning("Could not remap the point")

        else:
            old_width, old_height = old_extent.get_size()
            new_width, new_height = new_extent.get_size()

            x -= old_extent.x_min
            y -= old_extent.y_min

            x /= old_width
            y /= old_height

            x *= new_width
            y *= new_height

            if new_extent.y_inverted != old_extent.y_inverted:
                y = new_height - y

            x += new_extent.x_min
            y += new_extent.y_min

            ret = Vector(x, y)
            return ret
Ejemplo n.º 2
0
    def game_mode_change(self, response: dict):

        logger.info("the landscapelab tries to change the game mode")

        if "projection_epsg" in response:
            epsg = int(response["projection_epsg"])
        else:
            epsg = self.config.get("map_settings", "coordinate_reference_system")

        # calculate the main map extent based on the starting location
        start_position = Vector(float(response["start_position_x"]), float(response["start_position_y"]))
        width = float(response["start_extent_x"])
        height = float(response["start_extent_y"])
        start_extent = Extent.around_center(start_position, width, height/width)
        self.extent_tracker.map_extent = start_extent

        # setup the minimap extent
        mm_min_x = float(response["minimap_min_x"])
        mm_min_y = float(response["minimap_min_y"])
        mm_max_x = float(response["minimap_max_x"])
        mm_max_y = float(response["minimap_max_y"])
        minimap_extent = Extent(mm_min_x, mm_min_y, mm_max_x, mm_max_y)

        # change the maps
        self.mini_map.initialize_map(epsg, minimap_extent)
        self.main_map.initialize_map(epsg, start_extent)

        # reset the tracker and feed him the allowed brick combinations
        allowed_bricks = []
        for token_dict in response["used_tokens"]:
            shape = BrickShape[token_dict["shape"]]
            color = BrickColor[token_dict["color"]]
            icon_id = token_dict["icon_name"] 
            brick_config.icon_config[(token_dict["shape"], token_dict["color"])] = icon_id

            disappear = float(token_dict["disappear_after_seconds"])  # FIXME: to be implemented
            token = Token(shape, color, icon_id)  # FIXME: currently the svg is not implemented (coded via icon names)
            allowed_bricks.append(token)
        self.tracker.change_game_mode(allowed_bricks)

        # add new tokens
        for brick in response["existing_tokens"]:
            self.create_local_brick(brick)

        # create the scores for the new game mode
        scores = []
        for score_dict in response["scores"]:
            score_id = int(score_dict["score_id"])
            initial_value = float(score_dict["initial_value"])
            target_value = float(score_dict["target_value"])
            name = ""
            if score_dict["name"]:
                name = score_dict["name"]
            score = Score(score_id, target_value, initial_value, name)
            scores.append(score)
        UISetup.add_progressbars_to_ui(self.progressbars_ui, self.config, scores)

        # finally set to EXTERNAL ProgramStage
        self.program_stage.next()
Ejemplo n.º 3
0
    def get_start_extent(self):
        starting_location = Vector(self.config.get("map_settings", "start_x"),
                                   self.config.get("map_settings", "start_y"))

        # extrude start location to start extent
        zoom = self.config.get("map_settings", "start_zoom")

        return Extent.around_center(starting_location, zoom, 1)
Ejemplo n.º 4
0
    def remap_brick(brick: Brick, old_extent: 'Extent', new_extent: 'Extent'):
        remapped_brick = brick.clone()

        if old_extent is None or new_extent is None:
            logger.warning(
                "Could not remap the brick: {} (old: {} or new: {} is None)".
                format(brick, old_extent, new_extent))

        else:
            x, y = Extent.remap_point(
                Vector(remapped_brick.centroid_x, remapped_brick.centroid_y),
                old_extent, new_extent)

            remapped_brick.centroid_x = x
            remapped_brick.centroid_y = y

        return remapped_brick
Ejemplo n.º 5
0
 def __init__(self):
     self.position = Vector()  # use set_position to modify
     self.visible: bool = True
     self.parent: Optional[UIElement] = None
     self.children: List[UIElement] = []
Ejemplo n.º 6
0
 def get_lower_right(self) -> Vector:
     return Vector(self.x_max, self.y_max)
Ejemplo n.º 7
0
 def get_upper_left(self) -> Vector:
     return Vector(self.x_min, self.y_min)
Ejemplo n.º 8
0
 def get_center(self) -> Vector:
     return Vector((self.x_min + self.x_max) / 2,
                   (self.y_min + self.y_max) / 2)
Ejemplo n.º 9
0
 def get_size(self) -> Vector:
     return Vector(self.get_width(), self.get_height())