diff --git a/museca1_5/scorecard.py b/museca1_5/scorecard.py index acde5ad..4b840f3 100644 --- a/museca1_5/scorecard.py +++ b/museca1_5/scorecard.py @@ -11,10 +11,17 @@ package_dir = Path(os.path.relpath(__file__)).parent -# I'm not going to include these two xml files, but they're easy enough to get. -# lxml doesn't like to parse these characters ( 隯, 霻, Ⅱ, 隯) , so you'll have to remove them manually. -mdb = etree.parse(str(package_dir / 'assets/music-info-b.xml')).getroot() -grafica_xml = etree.parse(str(package_dir / 'assets/grafica-info-b.xml')).getroot() + +# Seek past the xml declaration since we're specifying encoding, cause lxml doesn't like it when we do that. +def seekXml(path): + with open(path, 'r', encoding='shift_jisx0213') as f: + if ' 226: + log.error("Jacket(s) don't exist, using default jacket.") with Image.open(package_dir / 'assets/misc/mplus.png') as mplus: base.paste(mplus, (425, 127), mask=mplus) - log.error("Jacket(s) don't exist, using default jacket.") except FileNotFoundError: log.error("Jacket(s) don't exist, did you fuck something up?") - # ----- Title/Artist text ----- + # ----- Title text ----- title = self.fixBrokenChars(info['title']) + titleW, titleH = draw.textsize(title, font=title_font) + if titleW > 247: + titleW, titleH = draw.textsize(title, font=title_font_s) + titlecanvas = Image.new('RGBA', (titleW, titleH), color=(255, 255, 255, 0)) + titledraw = ImageDraw.Draw(titlecanvas) + titledraw.text((0, 0), title, (30, 30, 30), font=title_font_s) + if titlecanvas.size[0] > 247: # If the smaller font size still doesn't fit, resize the text image to fit. + titlecanvas = titlecanvas.resize((247, titleH), resample=Image.LANCZOS) + base.paste(titlecanvas, (694 - titlecanvas.size[0], 359), mask=titlecanvas) + else: + draw.text((694 - draw.textsize(title, font=title_font)[0], 359), title, (30, 30, 30), + font=title_font) + + # ------ Artist text ------ artist = self.fixBrokenChars(info['artist']) - draw.text((694 - draw.textsize(artist, font=artist_font)[0], 382), artist, (120, 120, 120), font=artist_font) - if draw.textsize(title, font=title_font)[0] > 248: - draw.text((694 - draw.textsize(title, font=title_font_s)[0], 359), title, (30, 30, 30), font=title_font_s) + artistW, artistH = draw.textsize(artist, font=artist_font) + if artistW > 247: + artistcanvas = Image.new('RGBA', (artistW, artistH), color=(255, 255, 255, 0)) + artistdraw = ImageDraw.Draw(artistcanvas) + artistdraw.text((0, 0), artist, (120, 120, 120), font=artist_font) + artistcanvas = artistcanvas.resize((247, artistH), resample=Image.LANCZOS) + base.paste(artistcanvas, (694 - artistcanvas.size[0], 382), mask=artistcanvas) else: - draw.text((694 - draw.textsize(title, font=title_font)[0], 359), title, (30, 30, 30), font=title_font) + draw.text((694 - draw.textsize(artist, font=artist_font)[0], 382), artist, (120, 120, 120), font=artist_font) + # ----- Score text ----- draw.text((694 - draw.textsize(info['new_score'], font=scorefont)[0], 431), info['new_score'], (0, 0, 0), font=scorefont) @@ -161,11 +192,13 @@ def create_image(self, info): font=subscorefont) draw.text((694 - draw.textsize(info['max_combo'], font=subscorefont)[0], 583), info['max_combo'], (0, 0, 0), font=subscorefont) + # ----- Level ----- with Image.open(package_dir / 'assets/numbers/lv_{}.png'.format(info['difficulty'])) as levelimg: base.paste(levelimg, (609, 41), mask=levelimg) with Image.open(package_dir / 'assets/misc/difficulty_{}.png'.format(int(info['music_type']))) as levelicon: base.paste(levelicon, (542, 89), mask=levelicon) + # ----- Grade ----- with Image.open(package_dir / 'assets/grade/grade_{}.png'.format(info['score_grade'])) as grade: base.paste(grade, (467, 682), mask=grade) @@ -176,9 +209,11 @@ def create_image(self, info): else: with Image.open(package_dir / 'assets/misc/grade_index_0.png') as pointer: base.paste(pointer, (pointer_x_map.get(info['score_grade']), 650), mask=pointer) + # ----- Track number ----- with Image.open(package_dir / 'assets/misc/track_{}.png'.format(info['track_no'])) as layer: base.paste(layer, (0, 221), mask=layer) + # ----- GRAFICA ----- if info['grafica_1'] != '0': base.paste(Image.open(package_dir / 'assets/grafica/{}.png'.format(info['grafica_1'])), (126, 134)) @@ -198,9 +233,11 @@ def create_image(self, info): base.paste(medel, (186, 854), mask=medel) with Image.open(package_dir / 'assets/misc/frame_3.png') as frame: base.paste(frame, (126, 668), mask=frame) + # ----- Connect All ----- if info['clear_type'] == '4': base.paste(Image.open(package_dir / 'assets/misc/ca_icon_big.png'), (475, 501)) + # ----- Score difference ----- if 'old_score' in info.keys(): old_score, new_score = int(info['old_score']), int(info['new_score']) @@ -225,6 +262,7 @@ def create_image(self, info): with Image.open(package_dir / 'assets/misc/minus_record_bg.png') as minus_record: base.paste(minus_record, (493, 470), mask=minus_record) draw.text((692 - draw.textsize(diff, font=record_font_2)[0], 471), diff, (0, 0, 0), font=record_font_2) + # ----- Object Placement ----- if info['object_placement'] == '1': with Image.open(package_dir / 'assets/misc/option_mirror.png') as mirror: @@ -267,6 +305,8 @@ def saveImage(self, base): saveName = img_save_dir / f'{newNum}.png' log.info("Saving imgscore %s", saveName) base.save(saveName) + if __name__ == '__main__': + base.show() return saveName def fixBrokenChars(self, name): # thanks mon @@ -308,7 +348,7 @@ def fixBrokenChars(self, name): # thanks mon if __name__ == '__main__': - tree = etree.parse('req-game_3-save_m.xml') # File not included + tree = etree.parse('assets/req-game_3-save_m.xml') # File not included data = etree.tostring(tree) scorecard = ScoreCard(data) scorecard.generate()