2024-04-28 18:02:09 +00:00
|
|
|
from requests import get
|
|
|
|
from yaml import load, SafeLoader
|
2024-04-30 12:29:00 +00:00
|
|
|
from reag__ import reag__
|
2024-05-07 19:04:02 +00:00
|
|
|
from tqdm import tqdm
|
2024-04-28 18:02:09 +00:00
|
|
|
|
2024-05-04 11:00:31 +00:00
|
|
|
#### Локализация ####
|
2024-04-28 18:02:09 +00:00
|
|
|
|
2024-05-04 11:00:31 +00:00
|
|
|
def parse_ftl(el, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Locale/ru-RU/reagents/meta'):
|
2024-05-07 19:04:02 +00:00
|
|
|
if '.ftl' not in el:
|
|
|
|
el += '.ftl'
|
|
|
|
url = f'{prefix}/{el}'
|
2024-04-28 18:02:09 +00:00
|
|
|
raw = get(url).content.decode('utf-8')
|
2024-04-28 18:14:47 +00:00
|
|
|
locales = {}
|
|
|
|
for i in raw.splitlines():
|
|
|
|
if 'name' in i:
|
|
|
|
splitted = i.split()
|
|
|
|
name = splitted[0][13:]
|
|
|
|
locale = splitted[2]
|
|
|
|
locales[name] = locale
|
|
|
|
return locales
|
2024-04-30 12:29:00 +00:00
|
|
|
|
2024-05-04 11:00:31 +00:00
|
|
|
def load_locales(locales_url):
|
|
|
|
locales = {}
|
2024-05-07 19:04:02 +00:00
|
|
|
for el in tqdm(locales_url):
|
2024-05-04 11:00:31 +00:00
|
|
|
locales = locales | parse_ftl(el)
|
|
|
|
return locales
|
|
|
|
|
|
|
|
#### Рецепты ####
|
|
|
|
|
2024-05-07 19:04:02 +00:00
|
|
|
SafeLoader.add_multi_constructor('', lambda loader, tag_suffix, node: None)
|
|
|
|
|
2024-05-04 11:00:31 +00:00
|
|
|
def parse_yml(el, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Prototypes/Recipes/Reactions'):
|
2024-05-07 19:04:02 +00:00
|
|
|
if '.yml' not in el:
|
|
|
|
el += '.yml'
|
|
|
|
url = f'{prefix}/{el}'
|
2024-05-04 11:00:31 +00:00
|
|
|
yml = load(get(url).content.decode('utf-8'), Loader=SafeLoader)
|
|
|
|
return yml
|
|
|
|
|
|
|
|
def load_recipes(recipes_url, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Prototypes/Recipes/Reactions'):
|
2024-05-07 19:04:02 +00:00
|
|
|
recipes = {}
|
|
|
|
for el in tqdm(recipes_url):
|
2024-05-04 11:00:31 +00:00
|
|
|
yml = parse_yml(el, prefix)
|
|
|
|
for element in yml:
|
2024-05-07 19:04:02 +00:00
|
|
|
if 'products' not in element or 'reactants' not in element:
|
|
|
|
continue
|
|
|
|
product = element['id']
|
2024-05-04 11:00:31 +00:00
|
|
|
comps = {}
|
2024-05-07 19:04:02 +00:00
|
|
|
for elem in element['reactants']:
|
|
|
|
comps[elem] = element['reactants'][elem]['amount']
|
|
|
|
for id, value in element['products'].items():
|
2024-05-04 11:00:31 +00:00
|
|
|
out = value
|
2024-05-04 11:20:09 +00:00
|
|
|
recipes[product] = reag__(comps=comps, out=out, category=el)
|
2024-04-30 13:09:46 +00:00
|
|
|
return recipes
|
2024-05-02 16:07:06 +00:00
|
|
|
|
2024-05-03 15:04:09 +00:00
|
|
|
|
2024-05-04 11:00:31 +00:00
|
|
|
#### Локализируем ####
|
|
|
|
|
2024-05-03 15:04:09 +00:00
|
|
|
def localize(recipes, locale):
|
|
|
|
loc_recipes = {}
|
|
|
|
# Итерируем элементы
|
|
|
|
for element in recipes:
|
|
|
|
# Итерируем составные
|
|
|
|
el = recipes[element]
|
|
|
|
# Локализованные составные
|
|
|
|
loc_comps = {}
|
|
|
|
for comp in el.comps:
|
|
|
|
# Ищем перевод
|
|
|
|
if comp.lower() in locale:
|
|
|
|
loc = locale[comp.lower()].capitalize()
|
|
|
|
loc_comps[loc] = el.comps[comp]
|
|
|
|
else:
|
|
|
|
loc_comps[comp] = el.comps[comp]
|
|
|
|
# Заменяем на локализованное
|
|
|
|
el.comps = loc_comps
|
|
|
|
|
|
|
|
# Локализуем ключ
|
|
|
|
if element.lower() in locale:
|
|
|
|
loc = locale[element.lower()].capitalize()
|
|
|
|
loc_recipes[loc] = recipes[element]
|
|
|
|
else:
|
|
|
|
loc_recipes[element] = recipes[element]
|
|
|
|
|
|
|
|
return loc_recipes
|