Исправлены баги с токсинами

main
none 10 months ago
parent b8130b22c5
commit f1394117a9

@ -16,20 +16,21 @@ app.layout = html.Div([
html.Div([ html.Div([
# Реакция # Реакция
html.Div([ html.Div([
dcc.Dropdown(els, id='reaction', placeholder="Реакция", maxHeight=500) dcc.Dropdown(els, id='reaction', placeholder="Реакция", maxHeight=500, style={'font-size': '120%'})
], style={'flex': 4}), ], style={'flex': 4}),
# Объём # Объём
html.Div([ html.Div([
dcc.Dropdown([30, 50, 100, 300, 1000], 100, id='amount', clearable=False, searchable=False) dcc.Dropdown([30, 50, 100, 300, 1000], 100, id='amount', clearable=False, searchable=False
, style={'font-family': '"Source Sans Pro", sans-serif', 'font-size': '120%'})
], style={'flex': 1, 'padding-left': 25}) ], style={'flex': 1, 'padding-left': 25})
], style={'display': 'flex', 'flexDirection': 'row'}), ], style={'display': 'flex', 'flexDirection': 'row'}),
# Вывод # Вывод
html.Div(id='output', style={'padding': 10, 'padding-left': 15}) html.Div(id='output', style={'text-align': 'center', 'padding-left': '15%', 'padding-right': '15%'})
], style={'padding': 80, 'margin-left': 250, 'margin-right': 250}) ], style={'padding': '5%', 'margin-left': '30%', 'margin-right': '30%'})
# padding - отступ # padding - отступ
# [#####] # [#####]
@ -67,12 +68,14 @@ def update_output(reaction, amount):
if part%10 != 0: if part%10 != 0:
part = round(part/15)*15 part = round(part/15)*15
# Название: количество (локальные части) # Название: количество (локальные части)
parted = {} parted = {}
# Проверяем конфликты с составными частями: 48 != 50 # Проверяем конфликты с составными частями: 48 != 50
lparts = 0 ; lpart = 0 lparts = 0 ; lpart = 0
for i in db[reaction]: for i in db[reaction]:
if i[0] == True: # TODO: только i[1] in db ?
if i[0] == True and i[1] in db:
# Перебираем составные # Перебираем составные
for el in db[i[1]]: for el in db[i[1]]:
lparts += el[2] lparts += el[2]
@ -86,6 +89,7 @@ def update_output(reaction, amount):
# parted["Инапровалин"] = [48, 3] # parted["Инапровалин"] = [48, 3]
# 48 - 1 часть, 3 - кол. частей # 48 - 1 часть, 3 - кол. частей
comps = {} comps = {}
# Распределяем (пока не учитывает большую глубину) # Распределяем (пока не учитывает большую глубину)
for i in db[reaction]: for i in db[reaction]:
@ -94,7 +98,10 @@ def update_output(reaction, amount):
comps[i[1]] = 1 comps[i[1]] = 1
else: else:
comps[i[1]] = part * i[2] comps[i[1]] = part * i[2]
elif i[0] == True: elif i[0] == True and i[1] not in db:
# Фикс Вестина и т.п. (нету крафта, но отмечено как есть)
comps[i[1]] = part * i[2]
elif i[0] == True and i[1] in db:
# Перебираем составные # Перебираем составные
for el in db[i[1]]: for el in db[i[1]]:
if el[1] == "Плазма": if el[1] == "Плазма":
@ -105,13 +112,18 @@ def update_output(reaction, amount):
else: else:
comps[el[1]] += int( parted[i[1]][0]/parted[i[1]][1] * el[2] ) comps[el[1]] += int( parted[i[1]][0]/parted[i[1]][1] * el[2] )
print(comps) print(comps)
# Форматирование для HTML # Форматирование для HTML
result = [] result = []
for i in comps: for i in comps:
result.append( html.Div(i + ': ' + str(comps[i]), style={'background-color': '#efdd12', 'margin-top': 10}) ) result.append( html.Div(i + ': ' + str(comps[i])
, style={'background-color': '#3f3b17', 'margin-top': 10, 'border-radius': 10, 'padding': 15, 'font-family': '"Source Sans Pro", sans-serif', 'font-size': '120%'}) )
# Выходное вещество # Выходное вещество
result.append( html.Div(f'{reaction}: {part*parts}', style={'background-color': '#57ff00', 'margin-top': 10}) ) result.append( html.Div(f'{reaction}: {part*parts}'
, style={'background-color': '#183929', 'margin-top': 10, 'border-radius': 10, 'padding': 15, 'font-family': '"Source Sans Pro", sans-serif', 'font-size': '120%'}) )
print(result) print(result)
return result return result

@ -62,18 +62,19 @@ class Reagent:
def name(self): def name(self):
return localise(self.__name).capitalize() return localise(self.__name).capitalize()
@property # @property
def description(self): # def description(self):
return localise(self.__desc) # return localise(self.__desc)
@property @property
def recipe(self): def recipe(self):
result = [] result = []
if not self.__recipe: if not self.__recipe:
return result return None #return result #[False, "", 0]
for item in self.__recipe: for item in self.__recipe:
# Приводим к НОРМАЛЬНОМУ виду # Приводим к НОРМАЛЬНОМУ виду
# "Бикаридин": [ [0, "Углерод", 1], [1, "Инапровалин"] ] # "Бикаридин": [ [0, "Углерод", 1], [1, "Инапровалин"] ]
print(self.__recipe)
result.append([self.__recipe[item]["reagent"], localise(item).capitalize(), self.__recipe[item]["amount"]]) result.append([self.__recipe[item]["reagent"], localise(item).capitalize(), self.__recipe[item]["amount"]])
return result return result
@ -113,16 +114,19 @@ def localise(key: str) -> str:
else: else:
return f"[!] {key}" return f"[!] {key}"
# Показатель прогресса
load_localisation() from tqdm import tqdm
content = {} content = {}
for item in yaml.load(requests.get(REAGENTS_URL).content.decode("utf-8"), Loader=yaml.SafeLoader): def yml_load(url):
return yaml.load(requests.get(url).content.decode("utf-8"), Loader=yaml.SafeLoader)
for item in tqdm(yml_load(REAGENTS_URL), desc='reagents'):
content[item["id"]] = {"name": item["name"], "desc": item["desc"]} content[item["id"]] = {"name": item["name"], "desc": item["desc"]}
for item in yaml.load(requests.get(TOXINS_URL).content.decode("utf-8"), Loader=yaml.SafeLoader): for item in tqdm(yml_load(TOXINS_URL), desc='toxins'):
content[item["id"]] = {"name": item["name"], "desc": item["desc"]} content[item["id"]] = {"name": item["name"], "desc": item["desc"]}
for item in yaml.load(requests.get(RECIPES_URL).content.decode("utf-8"), Loader=yaml.SafeLoader): for item in tqdm(yml_load(RECIPES_URL), desc='recipies'):
if item["id"] not in content: if item["id"] not in content:
continue continue
content[item["id"]]["heat"] = "minTemp" in item content[item["id"]]["heat"] = "minTemp" in item
@ -131,8 +135,11 @@ for item in yaml.load(requests.get(RECIPES_URL).content.decode("utf-8"), Loader=
item["reactants"]} item["reactants"]}
content[item["id"]]["products"] = item["products"] content[item["id"]]["products"] = item["products"]
reagents = [Reagent(init_data=content[item]) for item in content] # if "reactants" in content[item]] # TODO: Включать ли токсины без крафта? (некоторые имеют крафт)
reagents = [Reagent(init_data=content[item]) for item in content if "reactants" in content[item]]
db = {x.name: x.recipe for x in reagents} db = {x.name: x.recipe for x in reagents}
with open("db.json", mode="w", encoding="utf-8") as db_file: #with open("db.json", mode="w", encoding="utf-8") as db_file:
json.dump(db, db_file, ensure_ascii=False, indent=2) # json.dump(db, db_file, ensure_ascii=False, indent=2)
from db import *
write_db(db)

Loading…
Cancel
Save