From 251be8b4e65f9394b1c505c205ded8831107897a Mon Sep 17 00:00:00 2001 From: Chris Davoren Date: Wed, 30 Aug 2023 23:56:35 +1000 Subject: [PATCH] Added more research functionality. --- sheditor.py | 50 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/sheditor.py b/sheditor.py index a001cef..c99da82 100644 --- a/sheditor.py +++ b/sheditor.py @@ -76,16 +76,28 @@ class ResearchItem: def get_name_from_code(cls, code): return cls.research_ids.get(code, None) if cls.research_ids is not None else None - def __init__(self, id, active_stage): + def __init__(self, id, active_stage, paused, states): self.id = id self.name = ResearchItem.get_name_from_code(id) + self.paused = paused self.active_stage = active_stage - self.stage_states = [] + self.stage_states = states def __str__(self): return "{} : {} : {}".format(self.id, self.name, self.active_stage) +class ResearchItemState: + + def __init__(self, done, stage, blocksdone): + self.done = done + self.stage = int(stage) + self.blocksdone = blocksdone + + def __str__(self): + return " {} : {} : {}".format(self.done, self.stage, self.blocksdone) + + # A single storage area, with a list of contents (Items) class StorageArea: @@ -190,7 +202,7 @@ class Character: # Max POINTS is 6 for attribute in self.attributes: attribute['points'] = 6 - + def clear_conditions(self): self.conditions = [1550, 2246, 3311] @@ -369,16 +381,33 @@ class GameData: # Step 5 - Research Data # console.print('Finding research...') res_tag = self.soup.find("research", treeId=True) - # console.print(res_tag) item_ids = [] for item in res_tag.find_all('l', techId=True): - # console.print(item['techId']) active_stage = int(item['activeStageIndex']) + paused = item['paused'] techId = int(item['techId']) item_ids.append(int(item['techId'])) - self.research.append(ResearchItem(techId, active_stage)) - # console.print(sorted(item_ids)) - # [console.print(id) for id in sorted(item_ids)] + stages = [] + for stage in item.find_all('l', done=True, stage=True): + done = stage['done'] + stage_no = stage['stage'] + # console.print(stage) + blocksdone_tag = stage.find('blocksDone') + blocksdone = None + if blocksdone_tag is not None: + blocksdone = [int(blocksdone_tag['level1']), int(blocksdone_tag['level2']), int(blocksdone_tag['level3'])] + ris = ResearchItemState(done, stage_no, blocksdone) + stages.append(ris) + ri = ResearchItem(techId, active_stage, paused, stages) + self.research.append(ri) + + """ + # Research data + console.print('Research stage counts:') + res_tag = self.soup.find('research', treeId=True) + for category in res_tag.find_all('l', techId=True): + console.print("{} : {}".format(category['techId'], len(category.find_all('l', done=True, stage=True)))) + """ def writeback(self): def replace_id(dict, old_key, new_key): @@ -446,6 +475,9 @@ class GameData: new_tag = self.soup.new_tag('s', attrs=tag_dict) area_tag.append(new_tag) + for research_item in self.research: + pass + def add_item(self, item_code, item_quantity): item_name = self.item_database.get_name_from_code(item_code) item = Item(item_code, item_name, item_quantity) @@ -547,6 +579,8 @@ class GameData: def list_research(self): for research in self.research: console.print(research) + for ris in research.stage_states: + console.print(ris) def consolidate_weapons(self): for ship in self.ships: