Completed writeout of class-based system.
This commit is contained in:
parent
b00912b1e1
commit
23b6a09b2e
File diff suppressed because it is too large
Load Diff
103
characters.py
103
characters.py
|
@ -2,7 +2,7 @@ import sys, argparse
|
|||
from bs4 import BeautifulSoup
|
||||
|
||||
char_skills = {
|
||||
1 : "Piloting",
|
||||
1 : "Piloting", # Likely deprecated
|
||||
2 : "Mining",
|
||||
3 : "Botany",
|
||||
4 : "Construction",
|
||||
|
@ -12,10 +12,13 @@ char_skills = {
|
|||
8 : "Shielding",
|
||||
9 : "Operations",
|
||||
10 : "Weapons",
|
||||
12 : "Logistics",
|
||||
13 : "Unknown",
|
||||
11 : "Unknown-1",
|
||||
12 : "Logistics", # All characters seem to have this but it doesn't show up in the UI
|
||||
13 : "Unknown-2-enigma", # All characters seem to have this skill but what is it for?
|
||||
14 : "Navigation",
|
||||
15 : "Unknown-3",
|
||||
16 : "Research",
|
||||
22 : "Piloting", # Appears to be the new piloting code?
|
||||
}
|
||||
|
||||
char_attributes = {
|
||||
|
@ -99,32 +102,53 @@ class StorageArea:
|
|||
|
||||
|
||||
class Character:
|
||||
# Will need an internal sense of what the codes mean for string output purposes
|
||||
|
||||
def __init__(self, name, tag):
|
||||
self.name = name
|
||||
self.tag = tag
|
||||
|
||||
self.skills = {}
|
||||
self.attributes = {}
|
||||
self.skills = []
|
||||
self.attributes = []
|
||||
|
||||
def set_skills(self, skill_list):
|
||||
# Expected format is a list of dictionaries
|
||||
# Each dictionary has keys id, mxn, exp, expd, level
|
||||
self.skills = skill_list
|
||||
|
||||
def set_attributes(self, attribute_list):
|
||||
# Expected format is a list of dictionaries
|
||||
# Each dictionary has keys id, points
|
||||
self.attributes = attribute_list
|
||||
|
||||
def maximize_skills(self):
|
||||
pass
|
||||
# Max LEVEL is 5
|
||||
# Max MXN should be 8 for some reason
|
||||
# Exp* keys are probably for a future experience system but I don't know how they work so I won't touch them
|
||||
for skill in self.skills:
|
||||
skill['level'] = 5
|
||||
skill['mxn'] = 8
|
||||
|
||||
def maximize_attributes(self):
|
||||
pass
|
||||
# Max POINTS is 6
|
||||
for attribute in self.attributes:
|
||||
attribute['points'] = 6
|
||||
|
||||
def clone(self, new_name):
|
||||
# How to deep copy the skills/attributes appropriately?
|
||||
pass
|
||||
|
||||
def print_summary(self):
|
||||
print("Name: {}".format(self.name))
|
||||
print("Skills:")
|
||||
for skill in self.skills:
|
||||
print("{} : {}".format(char_skills[skill['id']], skill['level']))
|
||||
print()
|
||||
print("Attributes:")
|
||||
for attribute in self.attributes:
|
||||
print("{} : {}".format(char_attributes[attribute['id']], attribute['points']))
|
||||
|
||||
def __repr__(self):
|
||||
return "{} - {} - {}".format(self.name, repr(self.skills), repr(self.attributes))
|
||||
return "{} - Skills: {} - Attributes: {}".format(self.name, repr(self.skills), repr(self.attributes))
|
||||
|
||||
|
||||
class Ship:
|
||||
|
@ -147,8 +171,9 @@ class Ship:
|
|||
|
||||
class Player:
|
||||
|
||||
def __init__(self, currency):
|
||||
def __init__(self, currency, tag):
|
||||
self.currency = currency
|
||||
self.tag = tag
|
||||
|
||||
|
||||
class GameData:
|
||||
|
@ -164,7 +189,7 @@ class GameData:
|
|||
# Step 1 - Player data
|
||||
char_tag = self.soup.find('playerBank')
|
||||
currency = char_tag['ca']
|
||||
self.player = Player(currency)
|
||||
self.player = Player(currency, char_tag)
|
||||
|
||||
# Step 2 - Ship data
|
||||
ship_tags = self.soup.find_all('ship')
|
||||
|
@ -181,7 +206,7 @@ class GameData:
|
|||
|
||||
# Step 3 - Storage area data
|
||||
for inv_tag in ship_tag.find_all('feat', eatAllowed=True):
|
||||
storage_area = StorageArea(inv_tag)
|
||||
storage_area = StorageArea(inv_tag.find('inv'))
|
||||
ship.add_storage_area(storage_area)
|
||||
# Items within storage area
|
||||
for s_tag in inv_tag.find_all('s'):
|
||||
|
@ -230,20 +255,51 @@ class GameData:
|
|||
attributes.append(attribute_dict)
|
||||
character.set_attributes(attributes)
|
||||
|
||||
"""
|
||||
Need to find player
|
||||
Need to find ships
|
||||
Within ships, need to find:
|
||||
- Storage areas, then items within storage areas
|
||||
- Characters, then names, skills, attributes etc
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
def writeback(self):
|
||||
def replace_id(dict, old_key, new_key):
|
||||
dict_copy = dict.copy()
|
||||
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)
|
||||
pass
|
||||
|
||||
# Shouldn't need to update player tag as this will be done directly
|
||||
# Only need to update things with structure / lists
|
||||
|
||||
"""
|
||||
Step 1 - Update characters
|
||||
Step 2 - Update storage areas
|
||||
"""
|
||||
|
||||
# Step 1 - Update characters
|
||||
# Names etc will be done automatically - just need to reconstruct skills and attributes
|
||||
|
||||
for ship in self.ships:
|
||||
for character in ship.characters:
|
||||
skill_tag = character.tag.find('skills')
|
||||
skill_tag.clear()
|
||||
for skill in character.skills:
|
||||
skill_copy = replace_id(skill, 'id', 'sk')
|
||||
new_tag = self.soup.new_tag('s', attrs=skill_copy)
|
||||
skill_tag.append(new_tag)
|
||||
|
||||
attribute_tag = character.tag.find('attr')
|
||||
attribute_tag.clear()
|
||||
for attribute in character.attributes:
|
||||
new_tag = self.soup.new_tag('a', attrs=attribute)
|
||||
attribute_tag.append(new_tag)
|
||||
|
||||
for storage_area in ship.storage_areas:
|
||||
area_tag = storage_area.tag
|
||||
area_tag.clear()
|
||||
for item in storage_area.items:
|
||||
tag_dict = { 'elementaryId' : item.code, 'inStorage' : item.quantity, 'onTheWayIn' : 0, 'onTheWayOut' : 0}
|
||||
new_tag = self.soup.new_tag('s', attrs=tag_dict)
|
||||
area_tag.append(new_tag)
|
||||
|
||||
|
||||
|
||||
def print_summary(self):
|
||||
print("Start game summary:")
|
||||
|
@ -258,7 +314,7 @@ class GameData:
|
|||
print(" Has {} character(s):".format(len(ship.characters)))
|
||||
for char in ship.characters:
|
||||
print(" {}".format(char.name))
|
||||
print(" {}".format(repr(char)))
|
||||
char.print_summary()
|
||||
|
||||
|
||||
def characters(soup):
|
||||
|
@ -442,6 +498,7 @@ def main():
|
|||
game_data = GameData(soup, item_code_database)
|
||||
game_data.populate()
|
||||
game_data.print_summary()
|
||||
game_data.writeback()
|
||||
|
||||
text = soup.prettify()
|
||||
# Delete XML header - game doesn't have it
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
from bs4 import BeautifulSoup
|
||||
|
||||
markup = """
|
||||
|
||||
<!DOCTYPE>
|
||||
<html>
|
||||
<head><title>Example</title></head>
|
||||
<body>
|
||||
<div id="parent">
|
||||
|
||||
<p>
|
||||
This is child of div with id = "parent".
|
||||
<span>Child of "P"</span>
|
||||
</p>
|
||||
|
||||
<div>
|
||||
Another Child of div with id = "parent".
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<p>
|
||||
Piyush
|
||||
</p>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
# parsering string to HTML
|
||||
soup = BeautifulSoup(markup, 'html.parser')
|
||||
|
||||
# finding tag whose child to be deleted
|
||||
div_bs4 = soup.find('div')
|
||||
|
||||
print(div_bs4)
|
||||
print('-------')
|
||||
|
||||
# delete the child element
|
||||
div_bs4.clear()
|
||||
|
||||
new_tag = soup.new_tag('s', attrs={'sk' : 2, 'level' : 5})
|
||||
div_bs4.append(new_tag)
|
||||
|
||||
print(div_bs4)
|
Loading…
Reference in New Issue