Ejemplo n.º 1
0
    def test_correct_position(self):
        self.assertEqual(Position(1.5, 1.5),
                         get_entity("assembling-machine-1", 1.5, 1.5).position)

        self.assertEqual(Position(1, 0.5),
                         get_entity("splitter", 1, 0.5).position)
        self.assertEqual(Position(0, 0.5),
                         get_entity("splitter", -0.5, 0).position)

        self.assertEqual(Position(0.5, 0.5),
                         get_entity("transport-belt", 0.5, 0.5).position)
Ejemplo n.º 2
0
    def bounding_box(self):
        min_x, max_x = float('inf'), float('-inf')
        min_y, max_y = float('inf'), float('-inf')

        for e in self.entities:
            e_min_x, e_min_y = e.bounding_box[1]  # Top Left
            e_max_x, e_max_y = e.bounding_box[2]  # Bottom Right

            if e_min_x < min_x:
                min_x = e_min_x
            if e_max_x > max_x:
                max_x = e_max_x

            if e_min_y < min_y:
                min_y = e_min_y
            if e_max_y > max_y:
                max_y = e_max_y

        return Position(min_x, min_y), Position(max_x, max_y)
Ejemplo n.º 3
0
    def __init__(self,
                 entities: List[EntityDict] = (),
                 item: str = None,
                 version: int = None,
                 label: str = None,
                 icons: List[IconDict] = (),
                 label_color: ColorDict = None,
                 tiles: List[TileDict] = (),
                 schedules: List[ScheduleDict] = (),
                 description: str = None,
                 *args,
                 **kwargs):
        self.entities: List[Entity] = [
            Blueprint._create_entity(e) for e in entities
        ]
        self.item: str = item
        self.label: str = label
        self.tiles: List[Tile] = [Tile(**t) for t in tiles]
        self.icons: List[Icon] = [Icon(**i) for i in icons]
        self.schedules: List[Schedule] = [Schedule(**s) for s in schedules]
        self.version: int = version
        self.label_color: Color = None if label_color is None else Color(
            **label_color)
        self.description: str = description

        self.snap_to_grid: Position
        if "snap-to-grid" in kwargs:
            self.snap_to_grid = Position(**kwargs["snap-to-grid"])
            del kwargs["snap-to-grid"]

        self.position_relative_to_grid: Position
        if "position-relative-to-grid" in kwargs:
            self.position_relative_to_grid = Position(
                **kwargs["position-relative-to-grid"])
            del kwargs["position-relative-to-grid"]

        self.absolute_snapping: bool
        if "absolute-snapping" in kwargs:
            self.absolute_snapping = kwargs["absolute-snapping"]
            del kwargs["absolute-snapping"]

        if len(kwargs) > 0:
            print(f"Unknown kwargs in {self.__class__.__name__}: {kwargs}")
Ejemplo n.º 4
0
    def test_bounding_box_single_3x3(self):
        bp = Blueprint(**BlueprintDict(entities=[get_entity_dict("assembling-machine-1", 0.5, 0.5)]))
        self.assertEqual((Position(-1, -1), Position(2, 2)), bp.bounding_box)

        bp = Blueprint(**BlueprintDict(entities=[get_entity_dict("assembling-machine-1", 1.5, 1.5)]))
        self.assertEqual((Position(0, 0), Position(3, 3)), bp.bounding_box)

        bp = Blueprint(**BlueprintDict(entities=[get_entity_dict("assembling-machine-1", -1.5, -1.5)]))
        self.assertEqual((Position(-3, -3), Position(0, 0)), bp.bounding_box)
Ejemplo n.º 5
0
    def test_get_bounding_box_3x3_square(self):
        bp = Blueprint(**BlueprintDict(entities=[
            get_entity_dict("transport-belt", 0.5, 0.5),
            get_entity_dict("transport-belt", 2.5, 2.5),
        ]))
        self.assertEqual((Position(0, 0), Position(3, 3)), bp.bounding_box)

        bp = Blueprint(**BlueprintDict(entities=[
            get_entity_dict("transport-belt", -0.5, -0.5),
            get_entity_dict("transport-belt", 1.5, 1.5),
        ]))
        self.assertEqual((Position(-1, -1), Position(2, 2)), bp.bounding_box)

        bp = Blueprint(**BlueprintDict(entities=[
            get_entity_dict("transport-belt", -2.5, -2.5),
            get_entity_dict("transport-belt", -0.5, -0.5),
        ]))
        self.assertEqual((Position(-3, -3), Position(0, 0)), bp.bounding_box)
Ejemplo n.º 6
0
    def __init__(self,
                 entity_number: int,
                 name: str,
                 position: PositionDict,
                 direction: int = None,
                 orientation: float = None,
                 connections: ConnectionDict = None,
                 control_behavior: object = None,
                 items: object = None,
                 recipe: str = None,
                 bar: int = None,
                 inventory: InventoryDict = None,
                 infinity_settings: InfinitySettingsDict = None,
                 type: str = None,
                 input_priority: str = None,
                 output_priority: str = None,
                 filter: str = None,
                 filters: List[ItemFilterDict] = (),
                 filter_mode: str = None,
                 override_stack_size: int = None,
                 drop_position: PositionDict = None,
                 pickup_position: PositionDict = None,
                 request_filters: List[LogisticFilterDict] = (),
                 request_from_buffers: bool = None,
                 parameters: SpeakerParameterDict = None,
                 alert_parameters: SpeakerAlertParameterDict = None,
                 auto_launch: bool = None,
                 variation: object = None,
                 color: ColorDict = None,
                 station: str = None,
                 neighbours: List[int] = (),
                 buffer_size: int = None,
                 power_production: int = None,
                 power_usage: int = None,
                 switch_state: bool = None,
                 manual_trains_limit: int = None,
                 signal: object = None,
                 *args,
                 **kwargs):
        if name not in self.get_entity_size_dict():
            raise UnknownEntityException(name)

        self.entity_number: int = entity_number
        self.name: str = name
        self.position: Position = Position(**position)
        self.direction: int = 0 if direction is None else direction
        self.orientation: float = orientation
        self.connections: Connection = None if connections is None else Connection(
            **connections)
        self.control_behavior: object = control_behavior
        self.items: object = items
        self.recipe: str = recipe
        self.bar: int = bar
        self.inventory: Inventory = None if inventory is None else Inventory(
            **inventory)
        self.infinity_settings: InfinitySettings = None if infinity_settings is None else InfinitySettings(
            **infinity_settings)
        self.type: str = type
        self.input_priority: str = input_priority
        self.output_priority: str = output_priority
        self.filter: str = filter
        self.filters: List[ItemFilter] = [ItemFilter(**f) for f in filters]
        self.filter_mode: str = filter_mode
        self.override_stack_size: int = override_stack_size
        self.drop_position: Position = None if drop_position is None else Position(
            **drop_position)
        self.pickup_position: Position = None if pickup_position is None else Position(
            **pickup_position)
        self.request_filters: List[LogisticFilter] = [
            LogisticFilter(**f) for f in request_filters
        ]
        self.request_from_buffers: bool = request_from_buffers
        self.parameters: SpeakerParameter = None if parameters is None else SpeakerParameter(
            **parameters)
        self.alert_parameters: SpeakerAlertParameter = None if alert_parameters is None else SpeakerAlertParameter(
            **alert_parameters)
        self.auto_launch: bool = auto_launch
        self.variation: object = variation
        self.color: Color = None if color is None else Color(**color)
        self.station: str = station
        self.neighbours: List[int] = list(neighbours)
        self.buffer_size: int = buffer_size
        self.power_production: int = power_production
        self.power_usage: int = power_usage
        self.switch_state: bool = switch_state
        self.manual_trains_limit: int = manual_trains_limit
        self.signal: object = signal

        if self.direction > 7:
            raise Exception("Invalid direction")

        self._init_dimensions()
        self._correct_position()

        if len(kwargs) > 0:
            print(f"Unknown kwargs in {self.__class__.__name__}: {kwargs}")
Ejemplo n.º 7
0
    def test_bounding_box_single_1x1(self):
        bp = Blueprint(**BlueprintDict(entities=[get_entity_dict("transport-belt", 0.5, 0.5)]))
        self.assertEqual((Position(0, 0), Position(1, 1)), bp.bounding_box)

        bp = Blueprint(**BlueprintDict(entities=[get_entity_dict("transport-belt", -0.5, -0.5)]))
        self.assertEqual((Position(-1, -1), Position(0, 0)), bp.bounding_box)