Example #1
0
    def new_no_garbage_cube(self) -> Cube:
        if self._new_no_garbage_cube is None:
            self._new_no_garbage_cube = (
                self.cube +
                ~CubeDeltaOperation(self.cube.garbage_traps.elements()) +
                self._patch.cube_delta_operation)

        return self._new_no_garbage_cube
Example #2
0
 def from_meta_delta(cls, from_meta: MetaCube,
                     to_meta: MetaCube) -> CubePatch:
     return cls(
         cube_delta_operation=(
             CubeDeltaOperation(to_meta.cube.cubeables.elements()) -
             CubeDeltaOperation(from_meta.cube.cubeables.elements())),
         node_delta_operation=(
             NodesDeltaOperation(to_meta.node_collection.nodes.elements()) -
             NodesDeltaOperation(
                 from_meta.node_collection.nodes.elements())),
         group_map_delta_operation=(
             GroupMapDeltaOperation(to_meta.group_map.groups) -
             GroupMapDeltaOperation(from_meta.group_map.groups)),
         infinites_delta_operation=InfinitesDeltaOperation.from_change(
             from_meta.infinites,
             to_meta.infinites,
         ),
     )
Example #3
0
 def as_patch(self) -> CubePatch:
     return CubePatch(
         CubeDeltaOperation({
             self._trap: 1,
         }),
         NodesDeltaOperation({
             self._node: -1,
         }),
     )
Example #4
0
 def add_cubeables(self, amount: int = 1) -> None:
     add = self._get_cubeables(amount)
     if add:
         self._hand_scene.get_cube_modification(
             CubeDeltaOperation(add),
             closed_operation=True,
         ).redo()
     self._undo_stack.clear()
     self._hand_view.update()
Example #5
0
 def duplicate_selected(self) -> None:
     cards = self._scene.selectedItems()
     if cards:
         self._undo_stack.push(
             self._scene.get_cube_modification(
                 CubeDeltaOperation(
                     Multiset(card.cubeable for card in cards).elements()),
                 cards[0].pos() + QPoint(1, 1),
             ))
Example #6
0
 def as_patch(self) -> CubePatch:
     return CubePatch(
         CubeDeltaOperation({
             printing: multiplicity
             for printing, multiplicity in self._after.items()
         }),
         NodesDeltaOperation({
             self._before: -1,
         }),
     )
Example #7
0
    def setData(self, index: QModelIndex, value: int, role: int = ...) -> bool:
        if role != Qt.EditRole or index.column() != 0:
            return False

        try:
            cubeable, quantity = self._lines.items()[index.row()]
        except IndexError:
            return False

        self._undo_stack.push(
            self._cube_scene.get_cube_modification(
                modification=CubeDeltaOperation({cubeable: value - quantity})))
        return True
Example #8
0
    def _paste(self):
        mime = Context.clipboard.mimeData()
        cards = mime.data('cards')

        if not cards:
            return

        cube = PickleStrategy(Context.db).deserialize(Cube, cards)

        self._undo_stack.push(
            self._scene.get_cube_modification(
                CubeDeltaOperation(cube.cubeables.elements()),
                QPoint() if self._last_move_event_pos is None else
                self.mapToScene(self._last_move_event_pos),
            ))
Example #9
0
 def __init__(
     self,
     cube_delta_operation: t.Optional[CubeDeltaOperation] = None,
     node_delta_operation: t.Optional[NodesDeltaOperation] = None,
     group_map_delta_operation: t.Optional[GroupMapDeltaOperation] = None,
     infinites_delta_operation: t.Optional[InfinitesDeltaOperation] = None,
 ):
     self._cube_delta_operation = CubeDeltaOperation(
     ) if cube_delta_operation is None else cube_delta_operation
     self._node_delta_operation = NodesDeltaOperation(
     ) if node_delta_operation is None else node_delta_operation
     self._group_map_delta_operation = (GroupMapDeltaOperation()
                                        if group_map_delta_operation is None
                                        else group_map_delta_operation)
     self._infinites_delta_operation = (InfinitesDeltaOperation()
                                        if infinites_delta_operation is None
                                        else infinites_delta_operation)
Example #10
0
 def _on_printing_selected(self, printing: Printing) -> None:
     modifiers = EmbargoApp.current.keyboardModifiers()
     if modifiers & QtCore.Qt.ControlModifier:
         amount, ok = QInputDialog.getInt(
             self,
             'Choose printing amount',
             '',
             4,
             1,
             99,
         )
         if not ok:
             amount = 0
     else:
         amount = 4 if modifiers & QtCore.Qt.ShiftModifier else 1
     if amount:
         self.add_printings.emit(CubeDeltaOperation({printing: amount}))
Example #11
0
    def removeRows(self,
                   row: int,
                   count: int,
                   parent: QModelIndex = ...) -> bool:
        with self._changing:
            self.beginRemoveRows(parent, row, row - 1 + count)

            if row + count > len(self._lines):
                return False

            self._undo_stack.push(
                self._cube_scene.get_cube_modification(
                    modification=CubeDeltaOperation({
                        cubeable: -value
                        for cubeable, value in self._lines.items()[row:row +
                                                                   count]
                    })))

            self.endRemoveRows()
        return True
Example #12
0
 def cube_delta_operation(self):
     return CubeDeltaOperation(
         Counter(card.cubeable for card in self.added) -
         Counter(card.cubeable for card in self.removed))
Example #13
0
 def as_patch(self) -> CubePatch:
     return CubePatch(
         CubeDeltaOperation({
             self._before: -1,
             self._after: 1,
         }), )
Example #14
0
 def as_patch(self) -> CubePatch:
     return CubePatch(CubeDeltaOperation({
         self._cubeable: -1,
     }))
Example #15
0
def test():
    db = Loader.load()
    strategy = JsonId(db)
    cube = CubeLoader(db).load()

    constrained_nodes = NodeCollection(
        ConstrainedNodeFetcher(db).fetch_garbage())

    groups = GroupMap(_GROUP_WEIGHTS)

    # s = '{"cube_delta": {}, "nodes_delta": {"nodes": []}}'
    # patch = strategy.deserialize(CubePatch, s)

    patch = CubePatch(
        CubeDeltaOperation({
            db.cardboards['Brainstorm'].from_expansion('ICE'):
            -1,
            db.cardboards['Brainstorm'].from_expansion('EMA'):
            1,
            # Trap(
            #     AllNode(
            #         (
            #             db.cardboards['Brainstorm'].from_expansion('ICE'),
            #             db.cardboards['Web'].from_expansion('LEA'),
            #         )
            #     ),
            #     intention_type=IntentionType.SYNERGY,
            # ): 2
        }),
        NodesDeltaOperation({
            # ConstrainedNode(
            #     node = AllNode(
            #         (
            #             db.cardboards['Web'].from_expansion('LEA'),
            #         )
            #     ),
            #     groups = ['ok', 'lmao'],
            #     value = 2,
            # ): 1,
            ConstrainedNode(
                node=AllNode((
                    db.cardboards['Brainstorm'].from_expansion('ICE'),
                    db.cardboards['Web'].from_expansion('LEA'),
                )),
                groups=['lolHAHA'],
                value=1,
            ):
            1,
        }))

    print(patch)

    meta_cube = MetaCube(cube, constrained_nodes, groups)

    verbose_patch = patch.as_verbose(meta_cube)

    print(verbose_patch)

    updater = CubeUpdater(meta_cube, patch)

    print(updater)

    report = UpdateReport(updater)

    for notification in report.notifications:
        print(notification.title + '\n' + notification.content + '\n\n')