DChat/resource pack/generators/combine.py

71 lines
4.9 KiB
Python

import json
import sys
import os
import pathlib
import shutil
# A list of folders to check for icon_info.json files and sheets/ folders.
FOLDERS = ["mc_items"]
def to_symbol_string(number):
return "\\ue" + str(hex(number))[2:].zfill(3)
# The emotedb to store later.
emotedb = []
current_index = 0
# A map containing information about all texture sheets and where they belong.
# Format: {folder_name: [{icons: [[],[],[]]}]}
sheets = {}
for folder in FOLDERS:
with open(f"{folder}/icon_info.json", "r") as icon_info_file:
icon_info = json.load(icon_info_file)
sheet_array = []
for sheet in os.listdir(f"{folder}/sheets/"):
sheet_array.append({"icons": [['\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000'], ['\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000'], ['\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000'], ['\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000'], ['\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000'], ['\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000'], ['\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000'], ['\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000'], ['\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000'], ['\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000'], ['\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000'], ['\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000'], ['\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000'], ['\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000'], ['\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000'], ['\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000', '\\u0000']]})
sheets[folder] = sheet_array
for icon in icon_info:
symbol = to_symbol_string(current_index)
sheets[folder][icon["sheet"]]["icons"][icon["pos"] // 16][icon["pos"] % 16] = symbol
emotedb.append({
"name": icon["name"],
"symbol": symbol,
"description": icon["description"]
})
current_index += 1
with open("emotedb.json", "w") as emotedb_file:
data = json.dumps(emotedb).encode().decode("unicode-escape")
emotedb_file.write(data)
providers = []
os.mkdir
pathlib.Path("pack/assets/dchat/textures/font/").mkdir(parents=True, exist_ok=True)
pathlib.Path("pack/assets/minecraft/font/").mkdir(parents=True, exist_ok=True)
for sheet_group in sheets:
sheet_array = sheets[sheet_group]
for index in range(len(sheet_array)):
sheet = sheet_array[index]
shutil.copy(f"{sheet_group}/sheets/sheet_{index}.png", f"pack/assets/dchat/textures/font/{sheet_group}_{index}.png")
chars = []
for row in sheet["icons"]:
chars.append("".join(row))
providers.append({
"type": "bitmap",
"file": f"dchat:font/{sheet_group}_{index}.png",
"ascent": 7,
"chars": chars
})
with open("pack/assets/minecraft/font/default.json", "w") as font_file:
data = json.dumps({"providers": providers}).encode().decode("unicode-escape")
font_file.write(data)