Added entirely experimental character cloning.

This commit is contained in:
Chris Davoren 2023-06-30 15:13:59 +10:00
parent 23b6a09b2e
commit 9263aa2b52
1 changed files with 16 additions and 4 deletions

View File

@ -1,4 +1,4 @@
import sys, argparse import sys, argparse, copy
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
char_skills = { char_skills = {
@ -106,6 +106,7 @@ class Character:
def __init__(self, name, tag): def __init__(self, name, tag):
self.name = name self.name = name
self.tag = tag self.tag = tag
self.is_clone = False
self.skills = [] self.skills = []
self.attributes = [] self.attributes = []
@ -135,7 +136,14 @@ class Character:
def clone(self, new_name): def clone(self, new_name):
# How to deep copy the skills/attributes appropriately? # 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): def print_summary(self):
print("Name: {}".format(self.name)) print("Name: {}".format(self.name))
@ -262,6 +270,7 @@ class GameData:
dict_copy[new_key] = dict_copy[old_key] dict_copy[new_key] = dict_copy[old_key]
del dict_copy[old_key] del dict_copy[old_key]
return dict_copy return dict_copy
# Purpose of this mission is to take all our data and replace the relevant parts of the soup # 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) # 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 ship in self.ships:
for character in ship.characters: 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 = character.tag.find('skills')
skill_tag.clear() skill_tag.clear()
for skill in character.skills: for skill in character.skills:
@ -299,8 +313,6 @@ class GameData:
new_tag = self.soup.new_tag('s', attrs=tag_dict) new_tag = self.soup.new_tag('s', attrs=tag_dict)
area_tag.append(new_tag) area_tag.append(new_tag)
def print_summary(self): def print_summary(self):
print("Start game summary:") print("Start game summary:")
print(" Player currency: {}".format(self.player.currency)) print(" Player currency: {}".format(self.player.currency))