велосипеды починены, локализация теперь работает

main
сачтик 9 months ago committed by GitHub
parent 72ac2e2b90
commit 873c221bb9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -9,6 +9,8 @@ yaml.SafeLoader.add_multi_constructor("", lambda loader, tag_suffix, node: None)
REAGENTS_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Reagents/medicine.yml" REAGENTS_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Reagents/medicine.yml"
MEDICINE_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/medicine.ftl" MEDICINE_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/medicine.ftl"
RECIPES_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Recipes/Reactions/medicine.yml" RECIPES_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Recipes/Reactions/medicine.yml"
CHEMICALS_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Reagents/chemicals.yml"
CHEMICALS_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/chemicals.ftl"
# элементы раздатчика химикатов # элементы раздатчика химикатов
ELEMENTS_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Reagents/elements.yml" ELEMENTS_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Reagents/elements.yml"
@ -29,18 +31,22 @@ GASES_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/r
BIOLOGY_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Reagents/biological.yml" BIOLOGY_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Reagents/biological.yml"
BIOLOGY_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/biological.ftl" BIOLOGY_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/biological.ftl"
# ботаника
BOTANY_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Reagents/botany.yml"
BOTANY_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/botany.ftl"
# все съедобное и питьевое # все съедобное и питьевое
FOOD_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/dev/Resources/Prototypes/Reagents/Consumable/Food/food.yml" FOOD_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/dev/Resources/Prototypes/Reagents/Consumable/Food/food.yml"
CONDIMENTS_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Reagents/Consumable/Food/condiments.yml" CONDIMENTS_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Reagents/Consumable/Food/condiments.yml"
INGREDIENTS_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Reagents/Consumable/Food/ingredients.yml"
DRINKS_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Reagents/Consumable/Drink/drinks.yml" DRINKS_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Reagents/Consumable/Drink/drinks.yml"
ALCOHOL_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Reagents/Consumable/Drink/alcohol.yml"
INGREDIENTS_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/consumable/food/ingredients.ftl"
ALCOHOL_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/consumable/drink/alcohol.ftl"
CONDIMENTS_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/consumable/food/condiments.ftl" CONDIMENTS_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/consumable/food/condiments.ftl"
DRINKS_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/consumable/drink/drinks.ftl" DRINKS_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/consumable/drink/drinks.ftl"
FOOD_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/consumable/food/ingredients.ftl" FOOD_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/consumable/food/ingredients.ftl"
localisation_list = [MEDICINE_LOCALISATION_URL, ELEMENTS_LOCALISATION_URL, TOXINS_LOCALISATION_URL,
GASES_LOCALISATION_URL, DRINKS_LOCALISATION_URL, FOOD_LOCALISATION_URL, CONDIMENTS_LOCALISATION_URL,
BIOLOGY_LOCALISATION_URL, NARCOTICS_LOCALISATION_URL]
class Reagent: class Reagent:
def __init__(self, init_data: dict): def __init__(self, init_data: dict):
@ -71,64 +77,37 @@ class Reagent:
def load_localisation(): def load_localisation():
# TODO: почистить data = {"elements": {}, "placeholders": {}}
data = {"elements": {}, "reagents": {}, "toxins": {}, "gases": {}, "food": {}, "drinks": {}, "condiments": {}, "biology": {}, elements_urls = [ELEMENTS_URL, REAGENTS_URL, TOXINS_URL, GASES_URL, FOOD_URL, DRINKS_URL, BIOLOGY_URL,
"total": {}} CONDIMENTS_URL, BOTANY_URL, ALCOHOL_URL, CHEMICALS_URL, INGREDIENTS_URL]
elements = yaml.load(requests.get(ELEMENTS_URL).content.decode("utf-8"), Loader=yaml.SafeLoader) for url in elements_urls:
for element in elements: response = yaml.load(requests.get(url).content.decode("utf-8"), Loader=yaml.SafeLoader)
data["elements"][element["id"]] = {"name": element["name"], "desc": element["desc"]} for i in response:
reagents = yaml.load(requests.get(REAGENTS_URL).content.decode("utf-8"), Loader=yaml.SafeLoader) data["elements"][i["id"]] = {"name": i["name"], "desc": i["desc"]}
for reagent in reagents:
data["reagents"][reagent["id"]] = {"name": reagent["name"], "desc": reagent["desc"]} localisation_urls = [MEDICINE_LOCALISATION_URL, ELEMENTS_LOCALISATION_URL, TOXINS_LOCALISATION_URL,
toxins = yaml.load(requests.get(TOXINS_URL).content.decode("utf-8"), Loader=yaml.SafeLoader) GASES_LOCALISATION_URL, DRINKS_LOCALISATION_URL, FOOD_LOCALISATION_URL,
for toxin in toxins: CONDIMENTS_LOCALISATION_URL, BIOLOGY_LOCALISATION_URL, NARCOTICS_LOCALISATION_URL,
data["toxins"][toxin["id"]] = {"name": toxin["name"], "desc": toxin["desc"]} BOTANY_LOCALISATION_URL, ALCOHOL_LOCALISATION_URL, CHEMICALS_LOCALISATION_URL,
gases = yaml.load(requests.get(GASES_URL).content.decode("utf-8"), Loader=yaml.SafeLoader) INGREDIENTS_LOCALISATION_URL]
for gase in gases:
data["gases"][gase["id"]] = {"name": gase["name"], "desc": gase["desc"]} for url in localisation_urls:
food = yaml.load(requests.get(FOOD_URL).content.decode("utf-8"), Loader=yaml.SafeLoader) response = requests.get(url).content.decode("utf-8")
for item in food: for entry in parse(response).body:
data["food"][item["id"]] = {"name": item["name"], "desc": item["desc"]}
drinks = yaml.load(requests.get(DRINKS_URL).content.decode("utf-8"), Loader=yaml.SafeLoader)
for drink in drinks:
data["drinks"][drink["id"]] = {"name": drink["name"], "desc": drink["desc"]}
biology = yaml.load(requests.get(BIOLOGY_URL).content.decode("utf-8"), Loader=yaml.SafeLoader)
for item in biology:
data["biology"][item["id"]] = {"name": item["name"], "desc": item["desc"]}
condiments = yaml.load(requests.get(CONDIMENTS_URL).content.decode("utf-8"), Loader=yaml.SafeLoader)
for item in condiments:
data["condiments"][item["id"]] = {"name": item["name"], "desc": item["desc"]}
for url in localisation_list:
content = requests.get(url).content.decode("utf-8")
for entry in parse(content).body:
if isinstance(entry, ast.Message): if isinstance(entry, ast.Message):
data["total"][entry.id.name] = entry.value.elements[0].value data["placeholders"][entry.id.name] = entry.value.elements[0].value
with open("locale.json", mode="w", encoding="utf-8") as localisation_file: with open("locale.json", mode="w", encoding="utf-8") as localisation_file:
json.dump(data, localisation_file, ensure_ascii=False, indent=2) json.dump(data, localisation_file, ensure_ascii=False, indent=2)
def localise(key: str) -> str: def localise(key: str) -> str:
# TODO: почистить это говно
with open("locale.json", mode="r", encoding="utf-8") as file: with open("locale.json", mode="r", encoding="utf-8") as file:
data = json.load(file) data = json.load(file)
if key in data["elements"]: if "-" in key: # если это placeholder
return data["total"].get(data["elements"][key]["name"]) return data["placeholders"].get(key, f"[p] {key}")
elif key in data["reagents"]: elif key in data["elements"]:
return data["total"].get(data["reagents"][key]["name"]) return localise(data["elements"][key]["name"])
elif key in data["toxins"]:
return data["total"].get(data["toxins"][key]["name"])
elif key in data["gases"]:
return data["total"].get(data["gases"][key]["name"])
elif key in data["food"]:
return data["total"].get(data["food"][key]["name"])
elif key in data["drinks"]:
return data["total"].get(data["drinks"][key]["name"])
elif key in data["biology"]:
return data["total"].get(data["biology"][key]["name"])
elif key in data["total"]:
return data["total"][key]
else: else:
return f"[!] {key}" return f"[!] {key}"
@ -151,8 +130,6 @@ for item in yaml.load(requests.get(RECIPES_URL).content.decode("utf-8"), Loader=
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]] reagents = [Reagent(init_data=content[item]) for item in content if "reactants" in content[item]]
print(reagents[0].name)
print(reagents[0].recipe)
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:

Loading…
Cancel
Save