コード例 #1
0
    def erase_skins(self, skins_to_erase):
        images_skins_refs = []
        skin_attachments_removed = {}
        for skin_name in skins_to_erase:
            (
                skin_removed_images,
                attachments_removed,
            ) = self.spine_anim_data.data.remove_skin(skin_name=skin_name)
            images_skins_refs += skin_removed_images
            skin_attachments_removed[skin_name] = attachments_removed

        json_data = self.spine_anim_data.to_json_data()
        self.spine_graph = SpineGraphContainer(json_data)

        # Flattening images refs in skins
        for skin_name, attachments in skin_attachments_removed.items():
            for slot_data in attachments.values():
                for attachment_path in slot_data.values():
                    images_skins_refs.append(attachment_path)

        # Check which attachments are not being used in the remaining skins
        images_to_remove = []

        for img in images_skins_refs:
            attachment_graph_id = SpineGraphParser._to_graph_id(
                node_type_name=NodeType.ATTACHMENT.name, node_base_id=img)
            if not self.spine_graph.graph.get_node(attachment_graph_id):
                images_to_remove.append(img)

        removed_data = self.clean_animation()
        self._clean_images_references(attachments_ids=images_to_remove)

        return removed_data, images_to_remove
コード例 #2
0
 def remove_slots(self, slots_ids: List[str]) -> List[SpamNode]:
     removed_slots = []
     for slot_id in slots_ids:
         slot_graph_id = SpineGraphParser._to_graph_id(
             node_type_name=NodeType.SLOT.name, node_base_id=slot_id)
         slot = self.graph.remove_node_by_id(slot_graph_id)
         removed_slots.append(slot)
     return removed_slots
コード例 #3
0
 def remove_attachments(self, attachment_ids: List[str]) -> List[SpamNode]:
     removed_nodes = []
     for attachment_id in attachment_ids:
         graph_attachment_id = SpineGraphParser._to_graph_id(
             NodeType.ATTACHMENT.name, attachment_id)
         removed_node = self.remove_attachment(graph_attachment_id)
         removed_nodes.append(removed_node)
     return removed_nodes
コード例 #4
0
    def test_spine_graph_creation(self, spine_node_factory, spine_json_data):
        """
        Create a graph from spine_json an generate the json from graph and check if it is equal to original

        :param spine_node_factory:
        :param spine_json_data:
        :return:
        """
        graph = SpineGraphParser.create_from_json_file(
            json_file=SPINE_JSON_PATH, node_factory=spine_node_factory
        )
        graph_json_data = json.loads(SpineGraphParser.to_json(graph=graph))

        json_data_to_compare = {}
        for key, value in graph_json_data.items():
            json_data_to_compare[str(key)] = spine_json_data[str(key)]

        # Comparing de-serialised json with the original one
        assert orderer(json_data_to_compare) == orderer(graph_json_data)
コード例 #5
0
    def _clean_attachments_in_slots(self, attachments_ids: List[str]) -> None:
        """ Cleaning default attachments in slots """

        copy_slots_data = copy.deepcopy(self.spine_anim_data.data.slots)
        for slot_idx, slot_data in enumerate(self.spine_anim_data.data.slots):
            default_attachment_id = slot_data.get("attachment")
            if default_attachment_id is not None:
                attachment_graph_id = SpineGraphParser._to_graph_id(
                    NodeType.ATTACHMENT.name, default_attachment_id)
                if attachment_graph_id in attachments_ids:
                    copy_slots_data[slot_idx].attachment = None

        self.spine_anim_data.data.slots = copy_slots_data
コード例 #6
0
    def remove_empty_slots(self) -> Tuple[List[str], List[str]]:
        """
        Removing from graph every slot leaves of graph and return it
        """
        slots_removed = []
        empty_slots = self.get_leaf_slots()
        while empty_slots:
            slots_removed += [
                SpineGraphParser._to_base_id(
                    node_type_name=NodeType.SLOT.name,
                    graph_id=self.graph.remove_node_by_id(s_id).id,
                ) for s_id in empty_slots
            ]

            empty_slots = self.get_leaf_slots()
        return slots_removed
コード例 #7
0
    def remove_leafs_of_type(self, type_name) -> List[str]:
        """
        Removing from graph every node leaves of type @type_name recursively
        and return the list of ids
        """
        nodes_removed = []
        leaf_nodes = self.get_leafs_of_type(node_type=type_name)
        while leaf_nodes:
            nodes_removed += [
                SpineGraphParser._to_base_id(
                    node_type_name=type_name,
                    graph_id=self.graph.remove_node_by_id(s_id).id,
                ) for s_id in leaf_nodes
            ]

            leaf_nodes = self.get_leafs_of_type(node_type=type_name)
        return nodes_removed
コード例 #8
0
    def remove_heads_of_type(self, type_name) -> List[str]:
        """
        Remove from graph every node that is a head of type @type_name recursively
        and return the list of ids
        """
        nodes_removed = []
        root_node = self.get_heads_with_type(node_type=type_name)
        while root_node:
            nodes_removed += [
                SpineGraphParser._to_base_id(
                    node_type_name=type_name,
                    graph_id=self.graph.remove_node_by_id(s_id).id,
                ) for s_id in root_node
            ]

            root_node = self.get_heads_with_type(node_type=type_name)
        return nodes_removed
コード例 #9
0
 def __init__(self, spine_json_data: Dict[str, Any]) -> None:
     self.graph = SpineGraphParser.create_from_json_data(
         json_data=spine_json_data, node_factory=SpineNodeFactory())