mirror of
https://github.com/Justuser3310/ss14_chemistry_site.git
synced 2025-02-08 01:01:18 +00:00
Compare commits
2 Commits
320a7204e3
...
bda4452390
Author | SHA1 | Date | |
---|---|---|---|
|
bda4452390 | ||
|
53d540c841 |
@ -1,4 +1,5 @@
|
|||||||
from precalc__ import precalc__
|
from precalc__ import precalc__
|
||||||
|
from db import load
|
||||||
|
|
||||||
global expanded
|
global expanded
|
||||||
def expand_recipe(recipe, recipes, main = False):
|
def expand_recipe(recipe, recipes, main = False):
|
||||||
@ -50,9 +51,17 @@ def calc(element, amount, recipes):
|
|||||||
|
|
||||||
return expanded, vol_in, vol_out
|
return expanded, vol_in, vol_out
|
||||||
|
|
||||||
|
|
||||||
def calc_all(recipes, amount):
|
def calc_all(recipes, amount):
|
||||||
precalc = {}
|
precalc = {}
|
||||||
for el in recipes:
|
for el in recipes:
|
||||||
precalc[el] = precalc__(calc(el, amount, recipes))
|
precalc[el] = precalc__(calc(el, amount, recipes))
|
||||||
return precalc
|
return precalc
|
||||||
|
|
||||||
|
|
||||||
|
def precalc(element, amount):
|
||||||
|
try:
|
||||||
|
# Загружаем рецепты с нужным количеством
|
||||||
|
recipes = load(f'{amount}_calc.json', 'precalc')
|
||||||
|
except:
|
||||||
|
return 'Нету такого файла или вещества'
|
||||||
|
return recipes[element]
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
from requests import get
|
from requests import get
|
||||||
from yaml import load, SafeLoader
|
from yaml import load, SafeLoader
|
||||||
from reag__ import reag__
|
from reag__ import reag__
|
||||||
|
from tqdm import tqdm
|
||||||
|
|
||||||
#### Локализация ####
|
#### Локализация ####
|
||||||
|
|
||||||
def parse_ftl(el, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Locale/ru-RU/reagents/meta'):
|
def parse_ftl(el, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Locale/ru-RU/reagents/meta'):
|
||||||
url = f'{prefix}/{el}.ftl'
|
if '.ftl' not in el:
|
||||||
|
el += '.ftl'
|
||||||
|
url = f'{prefix}/{el}'
|
||||||
raw = get(url).content.decode('utf-8')
|
raw = get(url).content.decode('utf-8')
|
||||||
locales = {}
|
locales = {}
|
||||||
for i in raw.splitlines():
|
for i in raw.splitlines():
|
||||||
@ -18,27 +21,33 @@ def parse_ftl(el, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/s
|
|||||||
|
|
||||||
def load_locales(locales_url):
|
def load_locales(locales_url):
|
||||||
locales = {}
|
locales = {}
|
||||||
for el in locales_url:
|
for el in tqdm(locales_url):
|
||||||
locales = locales | parse_ftl(el)
|
locales = locales | parse_ftl(el)
|
||||||
return locales
|
return locales
|
||||||
|
|
||||||
#### Рецепты ####
|
#### Рецепты ####
|
||||||
|
|
||||||
|
SafeLoader.add_multi_constructor('', lambda loader, tag_suffix, node: None)
|
||||||
|
|
||||||
def parse_yml(el, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Prototypes/Recipes/Reactions'):
|
def parse_yml(el, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Prototypes/Recipes/Reactions'):
|
||||||
url = f'{prefix}/{el}.yml'
|
if '.yml' not in el:
|
||||||
|
el += '.yml'
|
||||||
|
url = f'{prefix}/{el}'
|
||||||
yml = load(get(url).content.decode('utf-8'), Loader=SafeLoader)
|
yml = load(get(url).content.decode('utf-8'), Loader=SafeLoader)
|
||||||
return yml
|
return yml
|
||||||
|
|
||||||
def load_recipes(recipes_url, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Prototypes/Recipes/Reactions'):
|
def load_recipes(recipes_url, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Prototypes/Recipes/Reactions'):
|
||||||
for el in recipes_url:
|
recipes = {}
|
||||||
|
for el in tqdm(recipes_url):
|
||||||
yml = parse_yml(el, prefix)
|
yml = parse_yml(el, prefix)
|
||||||
recipes = {}
|
|
||||||
for element in yml:
|
for element in yml:
|
||||||
product = element["id"]
|
if 'products' not in element or 'reactants' not in element:
|
||||||
|
continue
|
||||||
|
product = element['id']
|
||||||
comps = {}
|
comps = {}
|
||||||
for elem in element["reactants"]:
|
for elem in element['reactants']:
|
||||||
comps[elem] = element["reactants"][elem]["amount"]
|
comps[elem] = element['reactants'][elem]['amount']
|
||||||
for id, value in element["products"].items():
|
for id, value in element['products'].items():
|
||||||
out = value
|
out = value
|
||||||
recipes[product] = reag__(comps=comps, out=out, category=el)
|
recipes[product] = reag__(comps=comps, out=out, category=el)
|
||||||
return recipes
|
return recipes
|
||||||
|
@ -12,11 +12,15 @@ vols = [30, 50, 100]
|
|||||||
if inp == '1':
|
if inp == '1':
|
||||||
print('Парсим и обрабатываем данные...')
|
print('Парсим и обрабатываем данные...')
|
||||||
# Загружаем локализацию
|
# Загружаем локализацию
|
||||||
locales_url = ['medicine', 'chemicals']
|
locales_url = ['biological', 'botany', 'chemicals', 'cleaning', 'elements', 'fun',
|
||||||
|
'gases', 'medicine', 'narcotics', 'physical-desc', 'pyrotechnic', 'toxins',
|
||||||
|
'consumable/drink/alcohol', 'consumable/drink/drinks', 'consumable/drink/juice', 'consumable/drink/soda',
|
||||||
|
'consumable/food/condiments', 'consumable/food/food', 'consumable/food/ingredients']
|
||||||
locales = load_locales(locales_url)
|
locales = load_locales(locales_url)
|
||||||
|
|
||||||
# Загружаем сырые рецепты
|
# Загружаем сырые рецепты
|
||||||
recipes_url = ['medicine']
|
recipes_url = ['biological', 'botany', 'chemicals', 'cleaning', 'drinks', 'food',
|
||||||
|
'fun', 'gas', 'medicine', 'pyrotechnic']
|
||||||
raw_recipes = load_recipes(recipes_url)
|
raw_recipes = load_recipes(recipes_url)
|
||||||
|
|
||||||
# Локализируем
|
# Локализируем
|
||||||
|
Loading…
Reference in New Issue
Block a user