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()
Beispiel #2
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)