Add a few fixes

This commit is contained in:
Cainan 2024-06-27 10:29:03 +01:00
parent cf5f974157
commit dbee0bc540
3 changed files with 36 additions and 5 deletions

View File

@ -5,6 +5,7 @@ Only supports Japanese text for now.
Usage: python generate.py song_id genreNo
There is also an additional script in here to convert the folder of textures to a .nut texture.
There is also an additional script in here to convert the folder of textures to a .nut texture.
The code in this was partially based on the NUT code found in [Smash Forge](https://github.com/jam1garner/Smash-Forge)
Usage: generate_nut.py input_folder output_file

View File

@ -25,9 +25,29 @@ rotated_chars = {
'': '︿', '': '',
'': '', '': '',
'': '', '': '',
'': '', '': ''
'': '', '': '',
'': '', '': ''
}
rotated_letters = {
'': ''
}
full_width_chars = {
'': 'A', '': 'B', '': 'C', '': 'D', '': 'E', '': 'F', '': 'G', '': 'H', '': 'I',
'': 'J', '': 'K', '': 'L', '': 'M', '': 'N', '': 'O', '': 'P', '': 'Q', '': 'R',
'': 'S', '': 'T', '': 'U', '': 'V', '': 'W', '': 'X', '': 'Y', '': 'Z',
'': 'a', '': 'b', '': 'c', '': 'd', '': 'e', '': 'f', '': 'g', '': 'h', '': 'i',
'': 'j', '': 'k', '': 'l', '': 'm', '': 'n', '': 'o', '': 'p', '': 'q', '': 'r',
'': 's', '': 't', '': 'u', '': 'v', '': 'w', '': 'x', '': 'y', '': 'z'
}
def convert_full_width(text):
converted_text = ''
for char in text:
converted_text += full_width_chars.get(char, char)
return converted_text
def get_text_bbox(draw, text, font):
return draw.textbbox((0, 0), text, font=font)
@ -46,6 +66,7 @@ def generate_image(draw, text, font, rotated_font, size, position, alignment, st
for char in text:
char_font = rotated_font if char in rotated_chars else font
char = rotated_chars.get(char, char)
char = rotated_letters.get(char, char)
text_bbox = get_text_bbox(draw, char, char_font)
text_height += text_bbox[3] - text_bbox[1]
char_width = text_bbox[2] - text_bbox[0]
@ -71,6 +92,7 @@ def generate_image(draw, text, font, rotated_font, size, position, alignment, st
for char in text:
char_font = rotated_font if char in rotated_chars else font
char = rotated_chars.get(char, char)
char = rotated_letters.get(char, char)
text_bbox = get_text_bbox(draw, char, char_font)
char_height = 40
char_width = text_bbox[2] - text_bbox[0]
@ -80,7 +102,9 @@ def generate_image(draw, text, font, rotated_font, size, position, alignment, st
y_offset = 5
for char in text:
char_font = rotated_font if char in rotated_chars else font
char = rotated_letters.get(char, char)
char = rotated_chars.get(char, char)
char = rotated_letters.get(char, char)
text_bbox = get_text_bbox(draw, char, char_font)
char_height = 27
char_width = text_bbox[2] - text_bbox[0]
@ -118,6 +142,7 @@ def create_images(data, id, genreNo, font_path, rotated_font_path):
japanese_text = ""
japanese_sub_text = ""
# Find the relevant texts
for item in data['items']:
if item['key'] == f'song_{id}':
@ -125,6 +150,10 @@ def create_images(data, id, genreNo, font_path, rotated_font_path):
if item['key'] == f'song_sub_{id}':
japanese_sub_text = item['japaneseText']
# Convert full-width English characters to normal ASCII characters
japanese_text = convert_full_width(japanese_text)
japanese_sub_text = convert_full_width(japanese_sub_text) if japanese_sub_text else ''
# Check if texts were found
if not japanese_text:
print(f"Error: No Japanese text found for song_{id}")
@ -179,6 +208,7 @@ def create_images(data, id, genreNo, font_path, rotated_font_path):
for char in japanese_text:
char_font = rotated_font if char in rotated_chars else font_large
char = rotated_chars.get(char, char)
char = rotated_letters.get(char, char)
text_bbox = get_text_bbox(temp_draw3, char, char_font)
char_height = 42
y_offset += char_height
@ -199,6 +229,7 @@ def create_images(data, id, genreNo, font_path, rotated_font_path):
for char in japanese_sub_text:
char_font = rotated_font if char in rotated_chars else font_large
char = rotated_chars.get(char, char)
char = rotated_letters.get(char, char)
text_bbox = get_text_bbox(temp_sub_draw3, char, char_font)
char_height = 28
y_offset += char_height
@ -232,6 +263,7 @@ def create_images(data, id, genreNo, font_path, rotated_font_path):
for char in japanese_text:
char_font = rotated_font if char in rotated_chars else font_large
char = rotated_chars.get(char, char)
char = rotated_letters.get(char, char)
text_bbox = get_text_bbox(temp_draw4, char, char_font)
char_height = 42
y_offset += char_height
@ -263,6 +295,7 @@ def create_images(data, id, genreNo, font_path, rotated_font_path):
for char in japanese_text:
char_font = rotated_font if char in rotated_chars else font_large
char = rotated_chars.get(char, char)
char = rotated_letters.get(char, char)
text_bbox = get_text_bbox(temp_draw5, char, char_font)
char_height = 42
y_offset += char_height

View File

@ -85,9 +85,6 @@ class NUT:
def modify_nut_file(self, file_path, output_path):
# Set replacement bytes to 00
replacement_bytes = bytes.fromhex(
"4E5450330200000600000000000000000002D050000000000002D00000500000001000E02D0004000000000000000000001E00000000000000000000655874000000002000000010000000004749445800000010000000000000000004925000000000000049200005000000001000E02D0006800000000000000000002D190000000000000000000000006558740000000020000000100000000047494458000000100000000100000000002D0500000000000002D00000500000001000E02D00040000000000000000076340000000000000000000000006558740000000002000000010000000004749445800000010000000020000000000258500000000000000025800005000000001000E00600190000000000000000A32F000000000000000000000065587400000000200000001000000000474944580000001000000003000000000015E50000000000000015E00005000000001000E003801900000000000000C8AA000000000000000000000065587400000000200000001000000000474944580000001000000004000000000015E50000000000000015E00005000000001000E0038019000000000000000D8500000000000000000000000655874000000002000000010000000004749445800000010000000050000000000"
)
with open(file_path, 'rb') as f:
data = bytearray(f.read())