mirror of
https://github.com/Justuser3310/ss14_chemistry_site.git
synced 2025-01-19 01:08:48 +00:00
Исправлены баги с токсинами
This commit is contained in:
parent
b8130b22c5
commit
f1394117a9
28
site.py
28
site.py
@ -16,20 +16,21 @@ app.layout = 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}),
|
||||
|
||||
# Объём
|
||||
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={'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 - отступ
|
||||
# [#####]
|
||||
@ -67,12 +68,14 @@ def update_output(reaction, amount):
|
||||
if part%10 != 0:
|
||||
part = round(part/15)*15
|
||||
|
||||
|
||||
# Название: количество (локальные части)
|
||||
parted = {}
|
||||
# Проверяем конфликты с составными частями: 48 != 50
|
||||
lparts = 0 ; lpart = 0
|
||||
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]]:
|
||||
lparts += el[2]
|
||||
@ -86,6 +89,7 @@ def update_output(reaction, amount):
|
||||
# parted["Инапровалин"] = [48, 3]
|
||||
# 48 - 1 часть, 3 - кол. частей
|
||||
|
||||
|
||||
comps = {}
|
||||
# Распределяем (пока не учитывает большую глубину)
|
||||
for i in db[reaction]:
|
||||
@ -94,7 +98,10 @@ def update_output(reaction, amount):
|
||||
comps[i[1]] = 1
|
||||
else:
|
||||
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]]:
|
||||
if el[1] == "Плазма":
|
||||
@ -105,13 +112,18 @@ def update_output(reaction, amount):
|
||||
else:
|
||||
comps[el[1]] += int( parted[i[1]][0]/parted[i[1]][1] * el[2] )
|
||||
|
||||
|
||||
print(comps)
|
||||
# Форматирование для HTML
|
||||
result = []
|
||||
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)
|
||||
return result
|
||||
|
||||
|
31
update_db.py
31
update_db.py
@ -62,18 +62,19 @@ class Reagent:
|
||||
def name(self):
|
||||
return localise(self.__name).capitalize()
|
||||
|
||||
@property
|
||||
def description(self):
|
||||
return localise(self.__desc)
|
||||
# @property
|
||||
# def description(self):
|
||||
# return localise(self.__desc)
|
||||
|
||||
@property
|
||||
def recipe(self):
|
||||
result = []
|
||||
if not self.__recipe:
|
||||
return result
|
||||
return None #return result #[False, "", 0]
|
||||
for item in self.__recipe:
|
||||
# Приводим к НОРМАЛЬНОМУ виду
|
||||
# "Бикаридин": [ [0, "Углерод", 1], [1, "Инапровалин"] ]
|
||||
print(self.__recipe)
|
||||
result.append([self.__recipe[item]["reagent"], localise(item).capitalize(), self.__recipe[item]["amount"]])
|
||||
return result
|
||||
|
||||
@ -113,16 +114,19 @@ def localise(key: str) -> str:
|
||||
else:
|
||||
return f"[!] {key}"
|
||||
|
||||
|
||||
load_localisation()
|
||||
# Показатель прогресса
|
||||
from tqdm import tqdm
|
||||
|
||||
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"]}
|
||||
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"]}
|
||||
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:
|
||||
continue
|
||||
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"]}
|
||||
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}
|
||||
with open("db.json", mode="w", encoding="utf-8") as db_file:
|
||||
json.dump(db, db_file, ensure_ascii=False, indent=2)
|
||||
#with open("db.json", mode="w", encoding="utf-8") as db_file:
|
||||
# json.dump(db, db_file, ensure_ascii=False, indent=2)
|
||||
from db import *
|
||||
write_db(db)
|
||||
|
Loading…
Reference in New Issue
Block a user