mirror of
https://github.com/SunsetMkt/Akebi-GC.git
synced 2025-09-19 20:16:01 +08:00
Character and weapon based filter for Interactive Map
This commit is contained in:
@ -2,14 +2,14 @@ import requests
|
||||
import json
|
||||
import re
|
||||
|
||||
# Reading api
|
||||
# Reading api list
|
||||
with open("map_api.txt", "r") as map_api_file:
|
||||
api_list = []
|
||||
for line in map_api_file.readlines():
|
||||
name, address = line.split()
|
||||
api_list.append((name, address))
|
||||
|
||||
# Getting points data
|
||||
# Getting map points data
|
||||
points_messages = []
|
||||
for (name, address) in api_list:
|
||||
r = requests.get(address)
|
||||
@ -19,7 +19,7 @@ for (name, address) in api_list:
|
||||
|
||||
points_messages.append((name, json.loads(r.content.decode())))
|
||||
|
||||
# Refactor data to our format
|
||||
# Refactor map points data to our format
|
||||
refactored_data = {}
|
||||
for (name, message) in points_messages:
|
||||
label_list = message["data"]["label_list"]
|
||||
@ -30,6 +30,7 @@ for (name, message) in points_messages:
|
||||
label_map[label["id"]] = label
|
||||
|
||||
data = {}
|
||||
|
||||
for point in point_list:
|
||||
label_id = point["label_id"]
|
||||
if label_id not in data:
|
||||
@ -48,12 +49,14 @@ for (name, message) in points_messages:
|
||||
"x_pos": point["x_pos"],
|
||||
"y_pos": point["y_pos"]
|
||||
})
|
||||
data[label_id]["points"] = sorted(points, key=lambda x: x["id"])
|
||||
|
||||
|
||||
refactored_data[name] = {
|
||||
"labels": data
|
||||
"labels": dict(sorted(data.items())) # Sorting it so we can easily track changes in updates
|
||||
}
|
||||
|
||||
# Getting categories data
|
||||
# Getting map categories data
|
||||
categories_messages = []
|
||||
for (name, address) in api_list:
|
||||
r = requests.get(address.replace("list", "tree").replace("point", "label"))
|
||||
@ -63,7 +66,7 @@ for (name, address) in api_list:
|
||||
|
||||
categories_messages.append((name, json.loads(r.content.decode())))
|
||||
|
||||
# Refactor data to our format
|
||||
# Refactor map categories data to our format
|
||||
for (name, message) in categories_messages:
|
||||
categories_list = message["data"]["tree"]
|
||||
|
||||
@ -73,11 +76,69 @@ for (name, message) in categories_messages:
|
||||
{
|
||||
"id": category["id"],
|
||||
"name": category["name"],
|
||||
"children": [child["id"] for child in category["children"]]
|
||||
"children": sorted([child["id"] for child in category["children"]])
|
||||
}
|
||||
)
|
||||
|
||||
refactored_data[name]["categories"] = sorted(data, key=lambda x: x["id"])
|
||||
|
||||
refactored_data[name]["categories"] = data
|
||||
# Get ascension materials data
|
||||
# They don't provide names for attrs so just manually set it...
|
||||
character_types = {"1":"Pyro", "2":"Anemo", "3":"Geo", "4":"Dendro", "5":"Electro", "6":"Hydro", "7":"Cryo"}
|
||||
weapon_types = {"1":"Swords", "10":"Catalysts", "11":"Claymores", "12":"Bows", "13":"Polearms"}
|
||||
|
||||
ascension_materials_messages = []
|
||||
r = requests.get(api_list[0][1].replace("point/list", "game_item"))
|
||||
if r.status_code != 200:
|
||||
print(f"Failed load ascension materials data")
|
||||
else:
|
||||
ascension_materials_messages.append(("ascension_materials", json.loads(r.content.decode())))
|
||||
|
||||
# Refactor ascension materials data to our format
|
||||
# Note: I've manually added the prefix "Character" to the clean_name in the generated json and image file of
|
||||
# Amber and Tartaglia since they have conflicting clear_name with other labels icons.
|
||||
# Entry for female Traveler is also removed since it's just a duplicate of the mc
|
||||
material_types = { "avatar", "weapon" }
|
||||
material_data = {}
|
||||
for (name, message) in ascension_materials_messages:
|
||||
for type in material_types:
|
||||
material_list = message["data"][type]["list"]
|
||||
material_category_list = message["data"][type]["attrs"]
|
||||
data = {}
|
||||
for material in material_list:
|
||||
material_id = material["item_id"]
|
||||
clear_name = re.sub(r"[^\w\d_]", "", material["name"])
|
||||
data[material_id] = {
|
||||
"name": material["name"],
|
||||
"clear_name": clear_name,
|
||||
"materials": sorted(material["labels"]),
|
||||
"icon": material["icon"]
|
||||
}
|
||||
material_data[type] = dict(sorted(data.items()))
|
||||
|
||||
data = []
|
||||
for category in material_category_list:
|
||||
children = []
|
||||
for material in material_list:
|
||||
if category == str(material["attr"]):
|
||||
children.append(material["item_id"])
|
||||
|
||||
data.append(
|
||||
{
|
||||
"id": category,
|
||||
"name": character_types[category] if type == "avatar" else weapon_types[category],
|
||||
"children": sorted(children),
|
||||
"icon": material_category_list[category]["icon_chosen"]
|
||||
}
|
||||
)
|
||||
material_data[type + "_types"] = sorted(data, key=lambda x: x["id"])
|
||||
|
||||
refactored_data[name] = {
|
||||
"character": material_data["avatar"],
|
||||
"character_types": material_data["avatar_types"],
|
||||
"weapon": material_data["weapon"],
|
||||
"weapon_types": material_data["weapon_types"]
|
||||
}
|
||||
|
||||
# Writing refactored data to json files
|
||||
for (name, data) in refactored_data.items():
|
||||
|
Reference in New Issue
Block a user