mirror of
https://github.com/cainan-c/TaikoPythonTools.git
synced 2024-11-30 18:24:33 +01:00
Add a few fixes
This commit is contained in:
parent
cf5f974157
commit
dbee0bc540
@ -6,5 +6,6 @@ Only supports Japanese text for now.
|
|||||||
Usage: python generate.py song_id genreNo
|
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
|
Usage: generate_nut.py input_folder output_file
|
@ -25,9 +25,29 @@ rotated_chars = {
|
|||||||
'〈': '︿', '〉': '﹀',
|
'〈': '︿', '〉': '﹀',
|
||||||
'《': '︽', '》': '︾',
|
'《': '︽', '》': '︾',
|
||||||
'【': '︻', '】': '︼',
|
'【': '︻', '】': '︼',
|
||||||
'〔': '︹', '〕': '︺'
|
'〔': '︹', '〕': '︺',
|
||||||
|
'~': '|', '~': '|'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rotated_letters = {
|
||||||
|
'ー': '|'
|
||||||
|
}
|
||||||
|
|
||||||
|
full_width_chars = {
|
||||||
|
'A': 'A', 'B': 'B', 'C': 'C', 'D': 'D', 'E': 'E', 'F': 'F', 'G': 'G', 'H': 'H', 'I': 'I',
|
||||||
|
'J': 'J', 'K': 'K', 'L': 'L', 'M': 'M', 'N': 'N', 'O': 'O', 'P': 'P', 'Q': 'Q', 'R': 'R',
|
||||||
|
'S': 'S', 'T': 'T', 'U': 'U', 'V': 'V', 'W': 'W', 'X': 'X', 'Y': 'Y', 'Z': 'Z',
|
||||||
|
'a': 'a', 'b': 'b', 'c': 'c', 'd': 'd', 'e': 'e', 'f': 'f', 'g': 'g', 'h': 'h', 'i': 'i',
|
||||||
|
'j': 'j', 'k': 'k', 'l': 'l', 'm': 'm', 'n': 'n', 'o': 'o', 'p': 'p', 'q': 'q', 'r': 'r',
|
||||||
|
's': 's', 't': 't', 'u': 'u', 'v': 'v', 'w': 'w', 'x': 'x', 'y': 'y', 'z': '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):
|
def get_text_bbox(draw, text, font):
|
||||||
return draw.textbbox((0, 0), text, font=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:
|
for char in text:
|
||||||
char_font = rotated_font if char in rotated_chars else font
|
char_font = rotated_font if char in rotated_chars else font
|
||||||
char = rotated_chars.get(char, char)
|
char = rotated_chars.get(char, char)
|
||||||
|
char = rotated_letters.get(char, char)
|
||||||
text_bbox = get_text_bbox(draw, char, char_font)
|
text_bbox = get_text_bbox(draw, char, char_font)
|
||||||
text_height += text_bbox[3] - text_bbox[1]
|
text_height += text_bbox[3] - text_bbox[1]
|
||||||
char_width = text_bbox[2] - text_bbox[0]
|
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:
|
for char in text:
|
||||||
char_font = rotated_font if char in rotated_chars else font
|
char_font = rotated_font if char in rotated_chars else font
|
||||||
char = rotated_chars.get(char, char)
|
char = rotated_chars.get(char, char)
|
||||||
|
char = rotated_letters.get(char, char)
|
||||||
text_bbox = get_text_bbox(draw, char, char_font)
|
text_bbox = get_text_bbox(draw, char, char_font)
|
||||||
char_height = 40
|
char_height = 40
|
||||||
char_width = text_bbox[2] - text_bbox[0]
|
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
|
y_offset = 5
|
||||||
for char in text:
|
for char in text:
|
||||||
char_font = rotated_font if char in rotated_chars else font
|
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_chars.get(char, char)
|
||||||
|
char = rotated_letters.get(char, char)
|
||||||
text_bbox = get_text_bbox(draw, char, char_font)
|
text_bbox = get_text_bbox(draw, char, char_font)
|
||||||
char_height = 27
|
char_height = 27
|
||||||
char_width = text_bbox[2] - text_bbox[0]
|
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_text = ""
|
||||||
japanese_sub_text = ""
|
japanese_sub_text = ""
|
||||||
|
|
||||||
|
|
||||||
# Find the relevant texts
|
# Find the relevant texts
|
||||||
for item in data['items']:
|
for item in data['items']:
|
||||||
if item['key'] == f'song_{id}':
|
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}':
|
if item['key'] == f'song_sub_{id}':
|
||||||
japanese_sub_text = item['japaneseText']
|
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
|
# Check if texts were found
|
||||||
if not japanese_text:
|
if not japanese_text:
|
||||||
print(f"Error: No Japanese text found for song_{id}")
|
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:
|
for char in japanese_text:
|
||||||
char_font = rotated_font if char in rotated_chars else font_large
|
char_font = rotated_font if char in rotated_chars else font_large
|
||||||
char = rotated_chars.get(char, char)
|
char = rotated_chars.get(char, char)
|
||||||
|
char = rotated_letters.get(char, char)
|
||||||
text_bbox = get_text_bbox(temp_draw3, char, char_font)
|
text_bbox = get_text_bbox(temp_draw3, char, char_font)
|
||||||
char_height = 42
|
char_height = 42
|
||||||
y_offset += char_height
|
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:
|
for char in japanese_sub_text:
|
||||||
char_font = rotated_font if char in rotated_chars else font_large
|
char_font = rotated_font if char in rotated_chars else font_large
|
||||||
char = rotated_chars.get(char, char)
|
char = rotated_chars.get(char, char)
|
||||||
|
char = rotated_letters.get(char, char)
|
||||||
text_bbox = get_text_bbox(temp_sub_draw3, char, char_font)
|
text_bbox = get_text_bbox(temp_sub_draw3, char, char_font)
|
||||||
char_height = 28
|
char_height = 28
|
||||||
y_offset += char_height
|
y_offset += char_height
|
||||||
@ -232,6 +263,7 @@ def create_images(data, id, genreNo, font_path, rotated_font_path):
|
|||||||
for char in japanese_text:
|
for char in japanese_text:
|
||||||
char_font = rotated_font if char in rotated_chars else font_large
|
char_font = rotated_font if char in rotated_chars else font_large
|
||||||
char = rotated_chars.get(char, char)
|
char = rotated_chars.get(char, char)
|
||||||
|
char = rotated_letters.get(char, char)
|
||||||
text_bbox = get_text_bbox(temp_draw4, char, char_font)
|
text_bbox = get_text_bbox(temp_draw4, char, char_font)
|
||||||
char_height = 42
|
char_height = 42
|
||||||
y_offset += char_height
|
y_offset += char_height
|
||||||
@ -263,6 +295,7 @@ def create_images(data, id, genreNo, font_path, rotated_font_path):
|
|||||||
for char in japanese_text:
|
for char in japanese_text:
|
||||||
char_font = rotated_font if char in rotated_chars else font_large
|
char_font = rotated_font if char in rotated_chars else font_large
|
||||||
char = rotated_chars.get(char, char)
|
char = rotated_chars.get(char, char)
|
||||||
|
char = rotated_letters.get(char, char)
|
||||||
text_bbox = get_text_bbox(temp_draw5, char, char_font)
|
text_bbox = get_text_bbox(temp_draw5, char, char_font)
|
||||||
char_height = 42
|
char_height = 42
|
||||||
y_offset += char_height
|
y_offset += char_height
|
||||||
|
@ -85,9 +85,6 @@ class NUT:
|
|||||||
|
|
||||||
def modify_nut_file(self, file_path, output_path):
|
def modify_nut_file(self, file_path, output_path):
|
||||||
# Set replacement bytes to 00
|
# Set replacement bytes to 00
|
||||||
replacement_bytes = bytes.fromhex(
|
|
||||||
"4E5450330200000600000000000000000002D050000000000002D00000500000001000E02D0004000000000000000000001E00000000000000000000655874000000002000000010000000004749445800000010000000000000000004925000000000000049200005000000001000E02D0006800000000000000000002D190000000000000000000000006558740000000020000000100000000047494458000000100000000100000000002D0500000000000002D00000500000001000E02D00040000000000000000076340000000000000000000000006558740000000002000000010000000004749445800000010000000020000000000258500000000000000025800005000000001000E00600190000000000000000A32F000000000000000000000065587400000000200000001000000000474944580000001000000003000000000015E50000000000000015E00005000000001000E003801900000000000000C8AA000000000000000000000065587400000000200000001000000000474944580000001000000004000000000015E50000000000000015E00005000000001000E0038019000000000000000D8500000000000000000000000655874000000002000000010000000004749445800000010000000050000000000"
|
|
||||||
)
|
|
||||||
|
|
||||||
with open(file_path, 'rb') as f:
|
with open(file_path, 'rb') as f:
|
||||||
data = bytearray(f.read())
|
data = bytearray(f.read())
|
||||||
|
Loading…
Reference in New Issue
Block a user