2023-03-13 18:36:30 +01:00
|
|
|
import json
|
|
|
|
|
2023-03-16 01:56:44 +01:00
|
|
|
todo_types = ["roomitemtypes", "wallitemtypes"]
|
|
|
|
|
2023-03-17 22:12:23 +01:00
|
|
|
# Furnidata id = items_base.sprite_id
|
|
|
|
# Productdata classname = catalog_items.catalog_name
|
|
|
|
# Furnidata classname = items_base.item_name/public_name
|
|
|
|
# items_base.id = catalog_items.items_id which is different from sprite id and furnidata id
|
|
|
|
|
2023-03-19 16:05:48 +01:00
|
|
|
def normalize_classnames(classname):
|
|
|
|
return str(classname).replace("_", "").replace(" ", "")
|
2023-03-17 22:12:23 +01:00
|
|
|
|
2023-03-13 18:36:30 +01:00
|
|
|
# Create a dictionary mapping classname to name and description
|
|
|
|
furniture_dict = {}
|
|
|
|
with open('gamedata/furnidata.json', 'r', encoding='utf-8') as f:
|
|
|
|
furniture_data = json.load(f)
|
2023-03-16 01:56:44 +01:00
|
|
|
for todo_type in todo_types:
|
|
|
|
for furnitype in furniture_data[todo_type]["furnitype"]:
|
2023-03-19 16:05:48 +01:00
|
|
|
classname = normalize_classnames(furnitype['classname'])
|
2023-03-16 01:56:44 +01:00
|
|
|
furniture_dict[classname] = {
|
|
|
|
"name": furnitype['name'],
|
|
|
|
"description": furnitype['description'],
|
2023-03-17 22:12:23 +01:00
|
|
|
"specialtype": furnitype['specialtype'],
|
2023-03-16 01:56:44 +01:00
|
|
|
}
|
2023-03-13 18:36:30 +01:00
|
|
|
|
2023-03-19 16:05:48 +01:00
|
|
|
with open('gamedata/productdata.json', 'r', encoding='utf-8') as f:
|
|
|
|
product_data = json.load(f)
|
|
|
|
for product in product_data["productdata"]["product"]:
|
|
|
|
classname = normalize_classnames(product['code'])
|
|
|
|
furniture_dict[classname] = {
|
|
|
|
"name": product['name'],
|
|
|
|
"description": product['description'],
|
|
|
|
}
|
|
|
|
|
2023-03-16 01:56:44 +01:00
|
|
|
orig_furniture_data = {}
|
2023-03-13 18:36:30 +01:00
|
|
|
# Load the JSON file
|
|
|
|
with open('../assets/gamedata/FurnitureData.json', 'r', encoding='utf-8') as f:
|
2023-03-16 01:56:44 +01:00
|
|
|
orig_furniture_data = json.load(f)
|
2023-03-13 18:36:30 +01:00
|
|
|
|
|
|
|
# Replace the name and description values with values from the XML file
|
2023-03-16 01:56:44 +01:00
|
|
|
for todo_type in todo_types:
|
|
|
|
for furnitype in orig_furniture_data[todo_type]["furnitype"]:
|
2023-03-19 16:05:48 +01:00
|
|
|
classname = normalize_classnames(furnitype['classname'])
|
2023-03-16 01:56:44 +01:00
|
|
|
if classname in furniture_dict:
|
|
|
|
furnitype['name'] = furniture_dict[classname]['name']
|
|
|
|
furnitype['description'] = furniture_dict[classname]['description']
|
2023-03-19 16:05:48 +01:00
|
|
|
if "specialtype" in furniture_dict[classname]:
|
|
|
|
furnitype['specialtype'] = furniture_dict[classname]['specialtype']
|
2023-03-17 22:12:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
orig_product_dict = {}
|
|
|
|
# Load the JSON file
|
|
|
|
with open('../assets/gamedata/ProductData.json', 'r', encoding='utf-8') as f:
|
|
|
|
orig_product_dict = json.load(f)
|
|
|
|
|
|
|
|
for product in orig_product_dict["productdata"]["product"]:
|
2023-03-19 16:05:48 +01:00
|
|
|
classname = normalize_classnames(product['code'])
|
|
|
|
if classname in furniture_dict:
|
|
|
|
product['name'] = furniture_dict[classname]['name']
|
|
|
|
product['description'] = furniture_dict[classname]['description']
|
2023-03-17 22:12:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Save the updated JSON file
|
2023-03-19 16:05:48 +01:00
|
|
|
with open('../assets/gamedata/FurnitureData.json', 'w') as f:
|
|
|
|
json.dump(orig_furniture_data, f, separators=(',', ':'))
|
|
|
|
|
2023-03-17 22:12:23 +01:00
|
|
|
with open('../assets/gamedata/ProductData.json', 'w') as f:
|
|
|
|
json.dump(orig_product_dict, f, separators=(',', ':'))
|