From 42f55bab979c65437f4f22fd3d9ee8838a93ba7d Mon Sep 17 00:00:00 2001 From: Chris Davoren Date: Fri, 30 Jun 2023 16:50:42 +1000 Subject: [PATCH] Appeared to have improved character cloning. --- sheditor.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sheditor.py b/sheditor.py index 9adfb91..9dfb4ba 100644 --- a/sheditor.py +++ b/sheditor.py @@ -138,6 +138,7 @@ class Character: # How to deep copy the skills/attributes appropriately? new_char = Character(new_name, copy.copy(self.tag)) new_char.is_clone = True + new_char.tag['name'] = new_name new_skills = [s.copy() for s in self.skills] new_attributes = [a.copy() for a in self.attributes] @@ -301,6 +302,7 @@ class GameData: for character in ship.characters: # Cloned character tags have to be added to the list if character.is_clone: + print("ADDING CLONED CHARACTER") charlist_tag = ship.tag.find('characters') charlist_tag.append(character.tag) @@ -343,6 +345,14 @@ class GameData: def add_currency(self, amount): self.player.currency += amount + def clone_character(self, character_name, new_name): + for ship in self.ships: + for character in ship.characters: + if character.name == character_name: + new_char = character.clone(new_name) + ship.characters.append(new_char) + return + def print_detailed_character_summary(self): for ship in self.ships: if len(ship.characters) == 0: @@ -580,6 +590,7 @@ def main(): # game_data.add_currency(10000) game_data.print_summary() # game_data.print_detailed_item_summary() + game_data.clone_character("Byron", "Anthony") game_data.print_detailed_character_summary() game_data.writeback()