Added more research functionality.

This commit is contained in:
Chris Davoren 2023-08-30 23:56:35 +10:00
parent 4c827cbec5
commit 251be8b4e6
1 changed files with 42 additions and 8 deletions

View File

@ -76,16 +76,28 @@ class ResearchItem:
def get_name_from_code(cls, code): def get_name_from_code(cls, code):
return cls.research_ids.get(code, None) if cls.research_ids is not None else None 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.id = id
self.name = ResearchItem.get_name_from_code(id) self.name = ResearchItem.get_name_from_code(id)
self.paused = paused
self.active_stage = active_stage self.active_stage = active_stage
self.stage_states = [] self.stage_states = states
def __str__(self): def __str__(self):
return "{} : {} : {}".format(self.id, self.name, self.active_stage) 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) # A single storage area, with a list of contents (Items)
class StorageArea: class StorageArea:
@ -369,16 +381,33 @@ class GameData:
# Step 5 - Research Data # Step 5 - Research Data
# console.print('Finding research...') # console.print('Finding research...')
res_tag = self.soup.find("research", treeId=True) res_tag = self.soup.find("research", treeId=True)
# console.print(res_tag)
item_ids = [] item_ids = []
for item in res_tag.find_all('l', techId=True): for item in res_tag.find_all('l', techId=True):
# console.print(item['techId'])
active_stage = int(item['activeStageIndex']) active_stage = int(item['activeStageIndex'])
paused = item['paused']
techId = int(item['techId']) techId = int(item['techId'])
item_ids.append(int(item['techId'])) item_ids.append(int(item['techId']))
self.research.append(ResearchItem(techId, active_stage)) stages = []
# console.print(sorted(item_ids)) for stage in item.find_all('l', done=True, stage=True):
# [console.print(id) for id in sorted(item_ids)] 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 writeback(self):
def replace_id(dict, old_key, new_key): def replace_id(dict, old_key, new_key):
@ -446,6 +475,9 @@ 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)
for research_item in self.research:
pass
def add_item(self, item_code, item_quantity): def add_item(self, item_code, item_quantity):
item_name = self.item_database.get_name_from_code(item_code) item_name = self.item_database.get_name_from_code(item_code)
item = Item(item_code, item_name, item_quantity) item = Item(item_code, item_name, item_quantity)
@ -547,6 +579,8 @@ class GameData:
def list_research(self): def list_research(self):
for research in self.research: for research in self.research:
console.print(research) console.print(research)
for ris in research.stage_states:
console.print(ris)
def consolidate_weapons(self): def consolidate_weapons(self):
for ship in self.ships: for ship in self.ships: