Skip to content

Commit

Permalink
Bugfix: allow copying attacker
Browse files Browse the repository at this point in the history
Note: attacker entrypoints are not copied correctly still
  • Loading branch information
mrkickling committed Nov 21, 2024
1 parent 179f612 commit 1e5f88f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
15 changes: 10 additions & 5 deletions mal_gui/model_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ def add_attacker(self, position, name = None):
)
new_item.attackerAttachment = new_attacker_attachment
self._attacker_id_to_item[new_attacker_attachment.id] = new_item
return new_item

def create_item(self, itemType, position, name):
"""Create item"""
Expand Down Expand Up @@ -599,7 +600,7 @@ def serialize_graphics_items(self, items: list[AssetBase], cut_intended):
# - This is causing issue with Serialization
asset_name = str(item.asset_name)
prop_keys_to_ignore = ['id','type']

print(asset_name, item.asset_type)
item_details = {
'asset_type': item.asset_type,
'asset_name': asset_name,
Expand All @@ -613,12 +614,16 @@ def serialize_graphics_items(self, items: list[AssetBase], cut_intended):
if conn.start_item.asset_sequence_id in selected_sequence_ids
and conn.end_item.asset_sequence_id in selected_sequence_ids
],
'asset_properties': [
'asset_properties': []
}

if item.asset_type != "Attacker":
item_details['asset_properties'] = [
(str(key),str(value))
for key,value in item.asset._properties.items()
if key not in prop_keys_to_ignore
for key, value in item.asset._properties.items()
if key not in prop_keys_to_ignore
]
}

objdetails.append(item_details)

serialized_data = pickle.dumps(objdetails)
Expand Down
11 changes: 3 additions & 8 deletions mal_gui/undo_redo_commands/paste_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from PySide6.QtGui import QUndoCommand
from PySide6.QtCore import QPointF

from maltoolbox.model import AttackerAttachment

from ..connection_item import AssociationConnectionItem

if TYPE_CHECKING:
Expand Down Expand Up @@ -49,14 +51,7 @@ def redo(self):

# AddAsset Equivalent - Start - To Be Discussed
if asset_type == "Attacker":
# newAttackerAttachment = AttackerAttachment()
# self.scene.model.add_attacker(newAttackerAttachment)

new_item = self.scene.asset_factory.get_asset(asset_type)
# new_item.asset_name = "Attacker"
# new_item.type_text_item.setPlainText(str("Attacker"))
new_item.setPos(position)
# self.scene._attacker_id_to_item[newAttackerAttachment.id] = new_item
new_item = self.scene.add_attacker(position)
else:
new_item = self.scene.add_asset(asset_type, position)
# we can assign the properties to new asset
Expand Down

0 comments on commit 1e5f88f

Please sign in to comment.