diff --git a/characters.py b/characters.py index 4cb3d36..cc972ec 100644 --- a/characters.py +++ b/characters.py @@ -1,4 +1,4 @@ -import sys, argparse +import sys, argparse, copy from bs4 import BeautifulSoup char_skills = { @@ -106,6 +106,7 @@ class Character: def __init__(self, name, tag): self.name = name self.tag = tag + self.is_clone = False self.skills = [] self.attributes = [] @@ -135,7 +136,14 @@ class Character: def clone(self, new_name): # How to deep copy the skills/attributes appropriately? - pass + new_char = Character(new_name, copy.copy(self.tag)) + new_char.is_clone = True + + new_skills = [s.copy() for s in self.skills] + new_attributes = [a.copy() for a in self.attributes] + new_char.skills = new_skills + new_char.attributes = new_attributes + return new_char def print_summary(self): print("Name: {}".format(self.name)) @@ -262,6 +270,7 @@ class GameData: dict_copy[new_key] = dict_copy[old_key] del dict_copy[old_key] return dict_copy + # Purpose of this mission is to take all our data and replace the relevant parts of the soup # Suspect this may be harder than it sounds - original saved game editor more or less deleted and rewrote some sections (e.g. item lists) @@ -278,6 +287,11 @@ class GameData: for ship in self.ships: for character in ship.characters: + # Cloned character tags have to be added to the list + if character.is_clone: + charlist_tag = ship.tag.find('characters') + charlist_tag.append(character.tag) + skill_tag = character.tag.find('skills') skill_tag.clear() for skill in character.skills: @@ -299,8 +313,6 @@ class GameData: new_tag = self.soup.new_tag('s', attrs=tag_dict) area_tag.append(new_tag) - - def print_summary(self): print("Start game summary:") print(" Player currency: {}".format(self.player.currency))