def from_config(cls, config): """ Creates a bottle object from a config dictionary. """ pos = Point(config['x'], config['y']) radius = config['radius'] color = config['color'] return cls(pos, radius, color)
def from_config(cls, config): """ Creates a lakes based on the given config. """ pos = Point(config['x'], config['y']) dims = Dimensions(config['width'], config['height']) color = tuple(config['color']) return cls(pos, dims, color)
def test_add_robot(self): conf = TestRobotState.default_config() state = RobotState(conf) sidebar = Sidebar(Point(100, 150), Dimensions(200, 300)) sidebar_sprite_mock = MagicMock() sidebar.init_robot(state.name, state.sensors, state.bricks, [sidebar_sprite_mock]) self.assertEqual(len(sidebar.robot_info), 1)
def from_config(cls, config): """ Creates a rock from a rock configuration file instance """ pos = Point(config['x'], config['y']) dims = Dimensions(config['width'], config['height']) color = tuple(config['color']) angle = config['angle'] movable = True if 'movable' not in config else config['movable'] return cls(pos, dims, color, angle, movable)
def _setup_sidebar(self): sidebar_width = get_simulation_settings( )['screen_settings']['side_bar_width'] sidebar = Sidebar( Point(self.size.width - sidebar_width, self.size.height - 70), Dimensions(sidebar_width, self.size.height)) for robot in self.world_state.get_robots(): sidebar.init_robot(robot.name, robot.sensors, robot.bricks, robot.side_bar_sprites) return sidebar
def from_config(cls, config): """ Creates a lakes based on the given config. """ border_width = config['border_width'] inner_radius = config['inner_radius'] outer_radius = inner_radius + border_width pos = Point(config['x'], config['y']) has_hole = config['hole'] if 'hole' in config else True color = tuple(config['color']) return cls(pos, outer_radius, inner_radius, color, border_width, has_hole)
def __init__(self, brick: int, robot, side, brick_x_offset, brick_y_offset): offset_x = -20 if side == 'left' else 20 config = { 'brick': brick, 'name': f'led_{side}', 'x_offset': brick_x_offset, 'y_offset': brick_y_offset, } dims = get_simulation_settings()['body_part_sizes']['led'] super().__init__(config, robot, Dimensions(dims['width'], dims['height']), 'led', Point(offset_x, -32.5)) self.old_texture_index = 1
def test_add_robot_info(self): conf = TestRobotState.default_config() state = RobotState(conf) sidebar = Sidebar(Point(100, 150), Dimensions(200, 300)) sidebar_sprite_mock = MagicMock() state.values[(0, 'ev3-ports:in4')] = 5 state.sounds[(0, 'speaker')] = 'test_sound' sidebar.init_robot(state.name, state.sensors, state.bricks, [sidebar_sprite_mock]) sidebar.add_robot_info(state.name, state.values, state.sounds) self.assertEqual( sidebar.robot_info[state.name][(0, 'ev3-ports:in4')]['value'], 5) self.assertEqual( sidebar.robot_info[state.name][(0, 'speaker')]['value'], 'test_sound')
def __init__(self, config, robot, dimensions: Dimensions, ev3type, offset=Point(0.0, 0.0), driver_name=None): self.name = config['name'] if 'name' in config else 'unnamed' self.ev3type = ev3type self.brick = int(config['brick']) self.address = config['port'] if 'port' in config else 'no_address' self.robot = robot self.driver_name = driver_name self.width_mm = dimensions.width self.height_mm = dimensions.height self.x_offset = float(config['x_offset']) + offset.x self.y_offset = float(config['y_offset']) + offset.y self.sensible_obstacles = [] self.sprite = None self.shape = None
def _get_orig_position(self) -> Point: """ Get the position of the robot as specified in the robot configuration file """ return Point(float(self.config['center_x']), float(self.config['center_y']) + 22.5)
def set_last_pos(self, pos): """ Updates the last pos as the given position multiplied by the inverse of the scale. """ self.last_pos = Point(pos.x * (1 / self.scale), pos.y * (1 / self.scale))